gehho
gehho

Reputation: 9238

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!

Upvotes: 12

Views: 4383

Answers (1)

gehho
gehho

Reputation: 9238

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.

Upvotes: 14

Related Questions