Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print current time in output window using TracePoint

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!

like image 413
gehho Avatar asked Nov 25 '13 14:11

gehho


People also ask

What is difference between breakpoint and Tracepoint in Visual Studio?

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.

How do I display the output window in Visual Studio?

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.

What is a trace point?

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.


1 Answers

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.

like image 62
gehho Avatar answered Sep 17 '22 12:09

gehho