<br><br><div class="gmail_quote">On Wed, Aug 24, 2011 at 12:00 PM, Zack Rusin <span dir="ltr">&lt;<a href="mailto:zack@kde.org">zack@kde.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Long term is would probably make sense to just use:<br>
<br>
<a href="http://www.fftw.org/cycle.h" target="_blank">http://www.fftw.org/cycle.h</a><br></blockquote><div>Yup, sounds good.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

but my main concern for CPU timings is that compression and disk io will skew<br>
them a bit. </blockquote><div>Yes, that is possible.  I was thinking of reading the timestamp immediately before the call, and then immediately after.  Something like:<br><br>diff --git a/trace_writer.cpp b/trace_writer.cpp<br>
index af8d62f..56aa4fb 100644<br>--- a/trace_writer.cpp<br>+++ b/trace_writer.cpp<br>@@ -33,6 +33,7 @@<br> #include &lt;zlib.h&gt;<br> <br> #include &quot;os.hpp&quot;<br>+#include &quot;tsc.h&quot;<br> #include &quot;trace_writer.hpp&quot;<br>
 #include &quot;trace_format.hpp&quot;<br> <br>@@ -206,12 +207,19 @@ void Writer::endEnter(void) {<br>     _writeByte(Trace::CALL_END);<br>     gzflush(g_gzFile, Z_SYNC_FLUSH);<br>     OS::ReleaseMutex();<br>+    //collect call begin timing here (TLS protects us, don&#39;t need mutex)<br>
+    startTimestamp = getTSC();<br> }<br> <br> void Writer::beginLeave(unsigned call) {<br>+    //collect call end timing here <br>+    uint64_t endTimestamp = getTSC();<br>     OS::AcquireMutex();<br>     _writeByte(Trace::EVENT_LEAVE);<br>
     _writeUInt(call);<br>+    _writeByte(Trace::CALL_TIMING);<br>+    _writeUInt(startTimestamp);<br>+    _writeUInt(endTimestamp);<br> }<br> <br> void Writer::endLeave(void) {<br><br>I was hoping to use thread local storage for startTimestamp.  Unfortunately the application I&#39;m tracing was not compiled with -std=gnu++0x, and the runtime linker complains that it can&#39;t find the startTimestamp symbol.  So I may have to move the timestamp reads into the python generator code and create a Writer::WriteTiming(a,b), or something close to that, so that the startTimestamp variable is on the stack.  That&#39;s probably more multi-platform friendly anyway.<br>
<br>By doing the collection like above, you&#39;re effectively only timing the call, not the compression.  Granted, the scheduler may still penalize you because you&#39;re eating up CPU cycles for the compression and IO.  And your overall frame time will be larger (as you mention below).<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">So I think we need to figure out the use case for this stuff. For<br>
example what I&#39;d love to know:<br>
<br>
- what exactly it is that we&#39;re trying to measure,<br></blockquote><div><br>In my case, trying to measure call times to see if there&#39;s gross differences between driver versions.  I&#39;ll admit it&#39;s kinda specialized, and most folks may not find it useful.  I&#39;ll take the opportunity to thank you guys for getting me this far tho.  :)<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">- what&#39;s the performance of tracing while fetching both cpu and gpu time for<br>

every call,<br></blockquote><div> </div><div>The RDTSC instruction itself takes a clock cycle or two of cpu time.  In
 total, after transferring the registers to memory, the latency is on 
the order of nanoseconds.  &#39;Course, there&#39;s still definite drawbacks to RDTSC, especially WRT dynamic frequency scaling and sleep states.<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
- how should the data be stored so that the tools can do the most out of them,<br>
for example as the TODO.markdown mentioned we&#39;d really love to have a<br>
&quot;Timeline view&quot;<br>
( <a href="http://msdn.microsoft.com/en-us/library/ee417180%28v=vs.85%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ee417180(v=vs.85).aspx</a> )<br>
I haven&#39;t yet looked at how the data would need to be stored for this to<br>
happen.<br>
<div class="im"><br>
&gt; My admittedly lofty goal was to trace an application, capturing the TSC<br>
&gt; data.  Then run the retrace, also capturing TSC data.  One could then diff<br>
&gt; frames/calls between the trace and retrace to see CPU utliization<br>
&gt; differences.<br>
<br>
</div>That sounds like a great idea. The issue is that between the app actually<br>
generating the data and tracing compressing the data (compression is slower<br>
than decompression), the tracing timings will always be slower than the<br>
retracing. Also the disk io read/write speed will heavily influence both.<br></blockquote><div><br>Has there been discussion on pushing the writer out to a dedicated thread?  Or is there too much of a risk that a tracing thread would outrun the writer? <br>
</div><div><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
So I think there&#39;s a lot of open questions. Most likely initially we need to<br>
push some implementation of this stuff to a branch and start experimenting with<br>
it.<br>
<font color="#888888"><br>
z<br>
</font></blockquote></div><br>Experiments are fun.  :)<br>Chris<br><br clear="all"><br>-- <br>Oh, meltdown... It&#39;s one of these annoying buzzwords. We prefer to call it an unrequested fission surplus.<br>-- Mr. Burns, The Simpsons<br>