I am mostly working with C# and I often use TracePoints (Breakpoints with "When hit..." set) printing the current time using {DateTime.Now.ToString(HH:mm:ss.fff")}
. I know this is not very accurate (and I am aware of the Stopwatch
class), but it is often helpful for a quick overview of what happens when. Furthermore, it is pretty easy to produce that output and it does not require any compiling.
Now I am more and more often working with (native) C++ code and I would like to produce the same output. However, it does not seem to be possible to use C# code in TracePoints in C++ code files. Therefore, I am looking for an equivalent one-liner in C++ that could be used in TracePoints. Or is there any other way to output the current time using TracePoints?
BTW: The time output should at least have milliseconds precision!
A visual studio feature called Tracepoint can be very helpful in these scenarios. Breakpoint allows to stop at a point where you can see the variable value but you may loose the track of it loops for more than 4-5 times. Tracepoint is an awesome feature of Visual Studio and it is available since Visual Studio 2005.
The Output window displays status messages for various features in the integrated development environment (IDE). To open the Output window, on the menu bar, choose View > Output, or press Ctrl+Alt+O.
Tracepoints are a new debugger feature in Visual Studio. A tracepoint is a breakpoint with a custom action associated with it. When a tracepoint is hit, the debugger performs the specified tracepoint action instead of, or in addition to, breaking program execution.
I just found out myself that you can also use the $TICK
keyword in the "When hit" dialog box. You should put it within curly braces: {$TICK}
otherwise the output will be hexadecimal.
According to MSDN:
$TICK inserts the current CPU tick count
This does not give you the current time, but it can certainly be converted. Furthermore, the ticks might already be enough for quick comparisons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With