]> git.cworth.org Git - apitrace/blobdiff - log.cpp
Prepend process name to the log's filename.
[apitrace] / log.cpp
diff --git a/log.cpp b/log.cpp
index ac1787b19184eb016112897c5a5178c4aa1895e2..7e219700988acad8e12ba6f0324885aa49a193f1 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -63,13 +63,25 @@ static void _Open(const char *szName, const char *szExtension) {
     
     static unsigned dwCounter = 0;
 
+    char szProcessPath[PATH_MAX];
+    char *lpProcessName;
+    char *lpProcessExt;
+
+    GetModuleFileNameA(NULL, szProcessPath, sizeof(szProcessPath)/sizeof(szProcessPath[0]));
+
+    lpProcessName = strrchr(szProcessPath, '\\');
+    lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
+    lpProcessExt = strrchr(lpProcessName, '.');
+    if(lpProcessExt)
+       *lpProcessExt = '\0';
+
     for(;;) {
         FILE *file;
         
         if(dwCounter)
-            snprintf(g_szFileName, PATH_MAX, "%s.%u.%s.gz", szName, dwCounter, szExtension);
+            snprintf(g_szFileName, PATH_MAX, "%s.%s.%u.%s.gz", lpProcessName, szName, dwCounter, szExtension);
         else
-            snprintf(g_szFileName, PATH_MAX, "%s.%s.gz", szName, szExtension);
+            snprintf(g_szFileName, PATH_MAX, "%s.%s.%s.gz", lpProcessName, szName, szExtension);
         
         file = fopen(g_szFileName, "rb");
         if(file == NULL)
@@ -228,14 +240,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();
@@ -301,7 +333,7 @@ void DumpString(const char *str) {
         else if(c == '\r')
             Text("\\r");
         else if(c == '\n')
-            Text("\\n");
+            Text("
");
         else {
             unsigned char octal0 = c & 0x7;
             unsigned char octal1 = (c >> 3) & 0x7;
@@ -333,7 +365,7 @@ void DumpWString(const wchar_t *str) {
         else if(c == '\r')
             Text("\\r");
         else if(c == '\n')
-            Text("\\n");
+            Text("
");
         else {
             unsigned octal0 = c & 0x7;
             unsigned octal1 = (c >> 3) & 0x7;