Time call durations.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 29 Jul 2009 11:39:55 +0000 (12:39 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 29 Jul 2009 11:39:55 +0000 (12:39 +0100)
log.cpp

diff --git a/log.cpp b/log.cpp
index 97f2271..433368f 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -228,14 +228,34 @@ void TextF(const char *format, ...) {
     Text(szBuffer);
 }
 
+static LARGE_INTEGER frequency = {0};
+static LARGE_INTEGER startcounter;
+
 void BeginCall(const char *function) {
     EnterCriticalSection(&CriticalSection); 
     Indent(1);
     BeginTag("call", "name", function);
     NewLine();
+
+    if(!frequency.QuadPart)
+       QueryPerformanceFrequency(&frequency);
+    
+    QueryPerformanceCounter(&startcounter);
 }
 
 void EndCall(void) {
+    LARGE_INTEGER endcounter;
+    LONGLONG usecs;
+
+    QueryPerformanceCounter(&endcounter);
+    usecs = (endcounter.QuadPart - startcounter.QuadPart)*1000000/frequency.QuadPart;
+
+    Indent(2);
+    BeginTag("duration");
+    TextF("%llu", usecs);
+    EndTag("duration");
+    NewLine();
+
     Indent(1);
     EndTag("call");
     NewLine();