]> git.cworth.org Git - apitrace/commitdiff
log - > trace
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 26 Nov 2010 11:35:54 +0000 (11:35 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 26 Nov 2010 11:35:54 +0000 (11:35 +0000)
17 files changed:
CMakeLists.txt
d3d10_1.py
d3d10misc.py
d3d8.py
d3d9.py
d3dshader.py
ddraw.py
glxtrace.py
log.cpp [deleted file]
log.hpp [deleted file]
os_posix.cpp
os_win32.cpp
trace.py
trace_write.cpp [new file with mode: 0644]
trace_write.hpp [new file with mode: 0644]
wgltrace.py
winapi.py

index 2fc59ee3d9970f4b932b06c07eda3fa1add9959c..04c7a44d38c7c6c7d4e5ddb50d35e8aac4d49f96 100644 (file)
@@ -102,7 +102,7 @@ if (WIN32)
        #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
        #               DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
        #       )
-       #       add_library (d3d8 SHARED d3d8.def d3d8.cpp log.cpp os_win32.cpp)
+       #       add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
        #       set_target_properties (d3d8 PROPERTIES PREFIX "")
        #endif (DirectX_D3D8_FOUND)
 
@@ -114,7 +114,7 @@ if (WIN32)
        #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
        #               DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
        #       )
-       #       add_library (d3d9 SHARED d3d9.def d3d9.cpp log.cpp os_win32.cpp)
+       #       add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
        #       set_target_properties (d3d9 PROPERTIES PREFIX "")
        #endif (DirectX_D3DX9_FOUND)
 
@@ -126,7 +126,7 @@ if (WIN32)
        #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
        #               DEPENDS d3d10misc.py winapi.py stdapi.py
        #       )
-       #       add_library (d3d10 SHARED d3d10.def d3d10.cpp log.cpp os_win32.cpp)
+       #       add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
        #       set_target_properties (d3d10 PROPERTIES PREFIX "")
        #endif (DirectX_D3D10_FOUND)
 
@@ -136,7 +136,7 @@ if (WIN32)
                COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
                DEPENDS wgltrace.py trace.py wglapi.py glapi.py glenum.py winapi.py stdapi.py
        )
-       add_library (opengl SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
+       add_library (opengl SHARED opengl32.def opengl32.cpp trace_write.cpp os_win32.cpp)
        set_target_properties (opengl PROPERTIES
                PREFIX ""
                OUTPUT_NAME opengl32)
@@ -153,7 +153,7 @@ else ()
                DEPENDS glxtrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
        )
 
-       add_library (glxtrace SHARED glxtrace.cpp log.cpp os_posix.cpp)
+       add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp)
        set_target_properties (glxtrace PROPERTIES PREFIX "")
        target_link_libraries (glxtrace dl)
 endif ()
index 14420da67ecbbed4be7b1c9bf8dc9d5ed00563d5..c71e880bd1687ef72851e2405e1f4535daae0221 100644 (file)
@@ -72,6 +72,6 @@ if __name__ == '__main__':
     print
     print '#include <d3d10_1.h>'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print
     wrap()
index 9396a56f99b54f84bb1ce1a7fdcd05f4bc21afec..00bd0e9f28a1353fa92c7851c1c0da32a7bd4a93 100644 (file)
@@ -64,6 +64,6 @@ if __name__ == '__main__':
     print
     print '#include <d3d10.h>'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print
     wrap()
diff --git a/d3d8.py b/d3d8.py
index 720455480d67fe267ff3f917144e5d1f4c335438..fdf788f9ab19f8f9146fc14aa5c267a9eeb1edd7 100644 (file)
--- a/d3d8.py
+++ b/d3d8.py
@@ -283,7 +283,7 @@ if __name__ == '__main__':
     print '#include <tchar.h>'
     print '#include <d3d8.h>'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print
     wrap()
 
diff --git a/d3d9.py b/d3d9.py
index 4e1da90c1f974340441844874b11388da3b93ab0..572d328d464f238edffd269e9fb0238908821dde 100644 (file)
--- a/d3d9.py
+++ b/d3d9.py
@@ -411,7 +411,7 @@ if __name__ == '__main__':
     print
     print '#include <d3d9.h>'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print
     wrap()
 
index bb37678721ae3879b4e4c7d58bbab8a1e9c2e24c..6093336c23219380ea9ca897ecd3a72a377ffb0e 100644 (file)
@@ -85,7 +85,7 @@ found:
         LPD3DXBUFFER pDisassembly = NULL;
    
         if (pfnD3DXDisassembleShader( (DWORD *)tokens, FALSE, NULL, &pDisassembly) == D3D_OK)
-            Log::LiteralString((char *)pDisassembly->GetBufferPointer());
+            Trace::LiteralString((char *)pDisassembly->GetBufferPointer());
 
         if(pDisassembly)
             pDisassembly->Release();
index bc1f8f2a6de5897b2f459ce20c1200341a55c22f..0841a8a13c914152262d0ddbb01c295b646b38db 100644 (file)
--- a/ddraw.py
+++ b/ddraw.py
@@ -1619,6 +1619,6 @@ if __name__ == '__main__':
     print '#include <tchar.h>'
     print '#include <ddraw.h>'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print
     wrap()
index b8cd151a6f43141c1782db2c76e8e7107678aa33..14aca2a969c707384c7d5dca467ddd54d83d5ad5 100644 (file)
@@ -37,7 +37,7 @@ class GlxTracer(Tracer):
             print '    if (!pglXGetProcAddress) {'
             print '        pglXGetProcAddress = (PglXGetProcAddress)dlsym(RTLD_NEXT, "glXGetProcAddress");'
             print '        if (!pglXGetProcAddress)'
-            print '            Log::Abort();'
+            print '            Trace::Abort();'
             print '    }'
             return 'pglXGetProcAddress((const GLubyte *)"%s")' % (function.name,)
 
@@ -65,7 +65,7 @@ if __name__ == '__main__':
     print '#include <GL/glx.h>'
     print '#include "glxext.h"'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print '#include "glsize.hpp"'
     print
     print 'extern "C" {'
diff --git a/log.cpp b/log.cpp
deleted file mode 100644 (file)
index 719666f..0000000
--- a/log.cpp
+++ /dev/null
@@ -1,324 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007-2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <map>
-
-#include <zlib.h>
-
-#include "os.hpp"
-#include "log.hpp"
-#include "trace_format.hpp"
-
-
-namespace Log {
-
-
-static gzFile g_gzFile = NULL;
-static void _Close(void) {
-   if(g_gzFile != NULL) {
-      gzclose(g_gzFile);
-      g_gzFile = NULL;
-   }
-}
-
-static void _Open(const char *szExtension) {
-   _Close();
-   
-   static unsigned dwCounter = 0;
-
-   char szFileName[PATH_MAX];
-   const char *lpFileName;
-
-   lpFileName = getenv("TRACE_PATH");
-   if (lpFileName) {
-       strncpy(szFileName, lpFileName, PATH_MAX);
-   }
-   else {
-       char szProcessName[PATH_MAX];
-       char szCurrentDir[PATH_MAX];
-       OS::GetProcessName(szProcessName, PATH_MAX);
-       OS::GetCurrentDir(szCurrentDir, PATH_MAX);
-
-       for(;;) {
-          FILE *file;
-          
-          if (dwCounter)
-             snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
-          else
-             snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
-          
-          file = fopen(szFileName, "rb");
-          if(file == NULL)
-             break;
-          
-          fclose(file);
-          
-          ++dwCounter;
-       }
-   }
-
-   OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
-
-   g_gzFile = gzopen(szFileName, "wb");
-}
-
-static inline void Write(const void *sBuffer, size_t dwBytesToWrite) {
-   if (g_gzFile == NULL)
-      return;
-   
-   gzwrite(g_gzFile, sBuffer, dwBytesToWrite);
-}
-
-static inline void 
-WriteByte(char c) {
-   Write(&c, 1);
-}
-
-void inline 
-WriteUInt(unsigned long long value) {
-   char buf[2 * sizeof value];
-   unsigned len;
-
-   len = 0;
-   do {
-      assert(len < sizeof buf);
-      buf[len] = 0x80 | (value & 0x7f);
-      value >>= 7;
-      ++len;
-   } while (value);
-
-   assert(len);
-   buf[len - 1] &= 0x7f;
-
-   Write(buf, len);
-}
-
-static inline void 
-WriteFloat(float value) {
-   assert(sizeof value == 4);
-   Write((const char *)&value, sizeof value);
-}
-
-static inline void 
-WriteDouble(double value) {
-   assert(sizeof value == 8);
-   Write((const char *)&value, sizeof value);
-}
-
-static inline void 
-WriteString(const char *str) {
-   size_t len = strlen(str);
-   WriteUInt(len);
-   Write(str, len);
-}
-
-typedef std::map<const char *, size_t> namemap;
-static namemap names;
-
-static inline void 
-WriteName(const char *name) {
-   namemap::iterator it = names.find(name);
-   if (it == names.end()) {
-       size_t name_id = names.size();
-       WriteUInt(name_id);
-       WriteString(name);
-       names[name] = name_id;
-   } else {
-       WriteUInt(it->second);
-   }
-}
-
-void Open(void) {
-    if (!g_gzFile) {
-        _Open("trace");
-        WriteUInt(TRACE_VERSION);
-    }
-}
-
-void Close(void) {
-   _Close();
-}
-
-static unsigned call_no = 0;
-
-unsigned BeginEnter(const char *function) {
-   OS::AcquireMutex();
-   Open();
-   WriteByte(Trace::EVENT_ENTER);
-   WriteName(function);
-   return call_no++;
-}
-
-void EndEnter(void) {
-   WriteByte(Trace::CALL_END);
-   gzflush(g_gzFile, Z_SYNC_FLUSH);
-   OS::ReleaseMutex();
-}
-
-void BeginLeave(unsigned call) {
-   OS::AcquireMutex();
-   WriteByte(Trace::EVENT_LEAVE);
-   WriteUInt(call);
-}
-
-void EndLeave(void) {
-   WriteByte(Trace::CALL_END);
-   gzflush(g_gzFile, Z_SYNC_FLUSH);
-   OS::ReleaseMutex();
-}
-
-void BeginArg(unsigned index, const char *name) {
-   WriteByte(Trace::CALL_ARG);
-   WriteUInt(index);
-   WriteName(name);
-}
-
-void BeginReturn(void) {
-   WriteByte(Trace::CALL_RET);
-}
-
-void BeginArray(size_t length) {
-   WriteByte(Trace::TYPE_ARRAY);
-   WriteUInt(length);
-}
-
-void BeginStruct(size_t length) {
-   WriteByte(Trace::TYPE_STRUCT);
-   WriteUInt(length);
-}
-
-void BeginMember(const char *name) {
-   WriteName(name);
-}
-
-void BeginBitmask(void) {
-   WriteByte(Trace::TYPE_BITMASK);
-}
-
-void EndBitmask(void) {
-   WriteByte(Trace::TYPE_NULL);
-}
-
-void LiteralBool(bool value) {
-   WriteByte(value ? Trace::TYPE_TRUE : Trace::TYPE_FALSE);
-}
-
-void LiteralSInt(signed long long value) {
-   if (value < 0) {
-      WriteByte(Trace::TYPE_SINT);
-      WriteUInt(-value);
-   } else {
-      WriteByte(Trace::TYPE_UINT);
-      WriteUInt(value);
-   }
-}
-
-void LiteralUInt(unsigned long long value) {
-   WriteByte(Trace::TYPE_UINT);
-   WriteUInt(value);
-}
-
-void LiteralFloat(float value) {
-   WriteByte(Trace::TYPE_FLOAT);
-   WriteFloat(value);
-}
-
-void LiteralFloat(double value) {
-   WriteByte(Trace::TYPE_DOUBLE);
-   WriteDouble(value);
-}
-
-void LiteralString(const char *str) {
-   if (!str) {
-      LiteralNull();
-      return;
-   }
-   WriteByte(Trace::TYPE_STRING);
-   WriteString(str);
-}
-
-void LiteralString(const char *str, size_t len) {
-   if (!str) {
-      LiteralNull();
-      return;
-   }
-   WriteByte(Trace::TYPE_STRING);
-   WriteUInt(len);
-   Write(str, len);
-}
-
-void LiteralWString(const wchar_t *str) {
-   if (!str) {
-      LiteralNull();
-      return;
-   }
-   WriteByte(Trace::TYPE_STRING);
-   WriteString("<wide-string>");
-}
-   
-void LiteralBlob(const void *data, size_t size) {
-   if (!data) {
-      LiteralNull();
-      return;
-   }
-   WriteByte(Trace::TYPE_BLOB);
-   WriteUInt(size);
-   if (size) {
-      Write(data, size);
-   }
-}
-
-void LiteralNamedConstant(const char *name, long long value) {
-   WriteByte(Trace::TYPE_CONST);
-   WriteName(name);
-   LiteralSInt(value);
-}
-
-void LiteralNull(void) {
-   WriteByte(Trace::TYPE_NULL);
-}
-
-void LiteralOpaque(const void *addr) {
-   if (!addr) {
-      LiteralNull();
-      return;
-   }
-   WriteByte(Trace::TYPE_OPAQUE);
-   WriteUInt((size_t)addr);
-}
-
-void Abort(void) {
-    Close();
-    OS::Abort();
-}
-
-} /* namespace Log */
diff --git a/log.hpp b/log.hpp
deleted file mode 100644 (file)
index edbf002..0000000
--- a/log.hpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef _LOG_HPP_
-#define _LOG_HPP_
-
-namespace Log {
-
-    void Open(void);
-    void Close(void);
-    
-    unsigned BeginEnter(const char *function);
-    void EndEnter(void);
-    
-    void BeginLeave(unsigned call);
-    void EndLeave(void);
-    
-    void BeginArg(unsigned index, const char *name);
-    inline void EndArg(void) {}
-
-    void BeginReturn(void);
-    inline void EndReturn(void) {}
-
-    void BeginArray(size_t length);
-    inline void EndArray(void) {}
-
-    inline void BeginElement(void) {}
-    inline void EndElement(void) {}
-
-    void BeginStruct(size_t length);
-    inline void EndStruct(void) {}
-
-    void BeginMember(const char *name);
-    inline void EndMember(void) {}
-
-    void BeginBitmask(void);
-    void EndBitmask(void);
-
-    void LiteralBool(bool value);
-    void LiteralSInt(signed long long value);
-    void LiteralUInt(unsigned long long value);
-    void LiteralFloat(float value);
-    void LiteralFloat(double value);
-    void LiteralString(const char *str);
-    void LiteralString(const char *str, size_t size);
-    void LiteralWString(const wchar_t *str);
-    void LiteralBlob(const void *data, size_t size);
-    void LiteralNamedConstant(const char *name, long long value);
-    void LiteralNull(void);
-    void LiteralOpaque(const void *ptr);
-
-    void Abort(void);
-}
-
-#endif /* _LOG_HPP_ */
index 590738f36f51b97e411acc0226ce9f94d19e6316..f4dbaab5c3119f572923ce5a7496f2bfbb0fc36a 100644 (file)
@@ -30,7 +30,7 @@
 #include <pthread.h>
 
 #include "os.hpp"
-#include "log.hpp"
+#include "trace_write.hpp"
 
 namespace OS {
 
@@ -108,6 +108,6 @@ Abort(void)
 
 static void _uninit(void) __attribute__((destructor));
 static void _uninit(void) {
-    Log::Close();
+    Trace::Close();
 }
 
index 5f8dddfc1204f7805d720d4a7ae3c98c8df052b5..f9fb56a1f639be8b273915ddc513270238cb9edb 100644 (file)
@@ -28,7 +28,7 @@
 #include <stdio.h>
 
 #include "os.hpp"
-#include "log.hpp"
+#include "trace_write.hpp"
 
 
 namespace OS {
@@ -131,7 +131,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
     case DLL_THREAD_DETACH:
         return TRUE;
     case DLL_PROCESS_DETACH:
-        Log::Close();
+        Trace::Close();
         return TRUE;
     }
     (void)hinstDLL;
index 677faf33d4d3823287ad24f296394af15fc0bfcf..388729a95d9d1d676134b673ee71a1cc084d4d63 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -51,12 +51,12 @@ class DumpDeclarator(stdapi.OnceVisitor):
         for type, name in struct.members:
             self.visit(type)
         print 'static void __traceStruct%s(const %s &value) {' % (struct.id, struct.expr)
-        print '    Log::BeginStruct(%u);' % len(struct.members)
+        print '    Trace::BeginStruct(%u);' % len(struct.members)
         for type, name in struct.members:
-            print '    Log::BeginMember("%s");' % (name,)
+            print '    Trace::BeginMember("%s");' % (name,)
             dump_instance(type, 'value.%s' % (name,))
-            print '    Log::EndMember();'
-        print '    Log::EndStruct();'
+            print '    Trace::EndMember();'
+        print '    Trace::EndStruct();'
         print '}'
         print
 
@@ -71,10 +71,10 @@ class DumpDeclarator(stdapi.OnceVisitor):
         print '    switch(value) {'
         for value in enum.values:
             print '    case %s:' % value
-            print '        Log::LiteralNamedConstant("%s", %s);' % (value, value)
+            print '        Trace::LiteralNamedConstant("%s", %s);' % (value, value)
             print '        break;'
         print '    default:'
-        print '        Log::LiteralSInt(value);'
+        print '        Trace::LiteralSInt(value);'
         print '        break;'
         print '    }'
         print '}'
@@ -82,16 +82,16 @@ class DumpDeclarator(stdapi.OnceVisitor):
 
     def visit_bitmask(self, bitmask):
         print 'static void __traceBitmask%s(%s value) {' % (bitmask.id, bitmask.type)
-        print '    Log::BeginBitmask();'
+        print '    Trace::BeginBitmask();'
         for value in bitmask.values:
             print '    if((value & %s) == %s) {' % (value, value)
-            print '        Log::LiteralNamedConstant("%s", %s);' % (value, value)
+            print '        Trace::LiteralNamedConstant("%s", %s);' % (value, value)
             print '        value &= ~%s;' % value
             print '    }'
         print '    if(value) {'
         dump_instance(bitmask.type, "value");
         print '    }'
-        print '    Log::EndBitmask();'
+        print '    Trace::EndBitmask();'
         print '}'
         print
 
@@ -115,13 +115,13 @@ class DumpImplementer(stdapi.Visitor):
     '''Dump an instance.'''
 
     def visit_literal(self, literal, instance):
-        print '    Log::Literal%s(%s);' % (literal.format, instance)
+        print '    Trace::Literal%s(%s);' % (literal.format, instance)
 
     def visit_string(self, string, instance):
         if string.length is not None:
-            print '    Log::LiteralString((const char *)%s, %s);' % (instance, string.length)
+            print '    Trace::LiteralString((const char *)%s, %s);' % (instance, string.length)
         else:
-            print '    Log::LiteralString((const char *)%s);' % instance
+            print '    Trace::LiteralString((const char *)%s);' % instance
 
     def visit_const(self, const, instance):
         self.visit(const.type, instance)
@@ -132,19 +132,19 @@ class DumpImplementer(stdapi.Visitor):
     def visit_array(self, array, instance):
         print '    if(%s) {' % instance
         index = '__i' + array.type.id
-        print '        Log::BeginArray(%s);' % (array.length,)
+        print '        Trace::BeginArray(%s);' % (array.length,)
         print '        for (int %s = 0; %s < %s; ++%s) {' % (index, index, array.length, index)
-        print '            Log::BeginElement();'
+        print '            Trace::BeginElement();'
         self.visit(array.type, '(%s)[%s]' % (instance, index))
-        print '            Log::EndElement();'
+        print '            Trace::EndElement();'
         print '        }'
-        print '        Log::EndArray();'
+        print '        Trace::EndArray();'
         print '    }'
         print '    else'
-        print '        Log::LiteralNull();'
+        print '        Trace::LiteralNull();'
 
     def visit_blob(self, blob, instance):
-        print '    Log::LiteralBlob(%s, %s);' % (instance, blob.size)
+        print '    Trace::LiteralBlob(%s, %s);' % (instance, blob.size)
 
     def visit_enum(self, enum, instance):
         print '    __traceEnum%s(%s);' % (enum.id, instance)
@@ -154,14 +154,14 @@ class DumpImplementer(stdapi.Visitor):
 
     def visit_pointer(self, pointer, instance):
         print '    if(%s) {' % instance
-        print '        Log::BeginArray(1);'
-        print '        Log::BeginElement();'
+        print '        Trace::BeginArray(1);'
+        print '        Trace::BeginElement();'
         dump_instance(pointer.type, "*" + instance)
-        print '        Log::EndElement();'
-        print '        Log::EndArray();'
+        print '        Trace::EndElement();'
+        print '        Trace::EndArray();'
         print '    }'
         print '    else'
-        print '        Log::LiteralNull();'
+        print '        Trace::LiteralNull();'
 
     def visit_handle(self, handle, instance):
         self.visit(handle.type, instance)
@@ -170,10 +170,10 @@ class DumpImplementer(stdapi.Visitor):
         self.visit(alias.type, instance)
 
     def visit_opaque(self, opaque, instance):
-        print '    Log::LiteralOpaque((const void *)%s);' % instance
+        print '    Trace::LiteralOpaque((const void *)%s);' % instance
 
     def visit_interface(self, interface, instance):
-        print '    Log::LiteralOpaque((const void *)%s);' % instance
+        print '    Trace::LiteralOpaque((const void *)%s);' % instance
 
 
 dump_instance = DumpImplementer().visit
@@ -297,7 +297,7 @@ class Tracer:
                 assert function.fail != ''
                 print '            return %s;' % function.fail
         else:
-            print '            Log::Abort();'
+            print '            Trace::Abort();'
 
     def get_function_address(self, function):
         raise NotImplementedError
@@ -320,21 +320,21 @@ class Tracer:
             print '    %s __result;' % function.type
             result = '__result = '
         self._get_true_pointer(function)
-        print '    unsigned __call = Log::BeginEnter("%s");' % (function.name)
+        print '    unsigned __call = Trace::BeginEnter("%s");' % (function.name)
         for arg in function.args:
             if not arg.output:
                 self.unwrap_arg(function, arg)
                 self.dump_arg(function, arg)
-        print '    Log::EndEnter();'
+        print '    Trace::EndEnter();'
         print '    %s%s(%s);' % (result, pvalue, ', '.join([str(arg.name) for arg in function.args]))
-        print '    Log::BeginLeave(__call);'
+        print '    Trace::BeginLeave(__call);'
         for arg in function.args:
             if arg.output:
                 self.dump_arg(function, arg)
                 self.wrap_arg(function, arg)
         if function.type is not stdapi.Void:
             self.dump_ret(function, "__result")
-        print '    Log::EndLeave();'
+        print '    Trace::EndLeave();'
         if function.type is not stdapi.Void:
             self.wrap_ret(function, "__result")
             print '    return __result;'
@@ -342,9 +342,9 @@ class Tracer:
         print
 
     def dump_arg(self, function, arg):
-        print '    Log::BeginArg(%u, "%s");' % (arg.index, arg.name,)
+        print '    Trace::BeginArg(%u, "%s");' % (arg.index, arg.name,)
         dump_instance(arg.type, arg.name)
-        print '    Log::EndArg();'
+        print '    Trace::EndArg();'
 
     def wrap_arg(self, function, arg):
         wrap_instance(arg.type, arg.name)
@@ -353,9 +353,9 @@ class Tracer:
         unwrap_instance(arg.type, arg.name)
 
     def dump_ret(self, function, instance):
-        print '    Log::BeginReturn();'
+        print '    Trace::BeginReturn();'
         dump_instance(function.type, instance)
-        print '    Log::EndReturn();'
+        print '    Trace::EndReturn();'
 
     def wrap_ret(self, function, instance):
         wrap_instance(function.type, instance)
@@ -403,10 +403,10 @@ class Tracer:
         else:
             print '    %s __result;' % method.type
             result = '__result = '
-        print '    Log::BeginCall("%s");' % (interface.name + '::' + method.name)
-        print '    Log::BeginArg(0, "this");'
-        print '    Log::LiteralOpaque((const void *)m_pInstance);'
-        print '    Log::EndArg();'
+        print '    Trace::BeginCall("%s");' % (interface.name + '::' + method.name)
+        print '    Trace::BeginArg(0, "this");'
+        print '    Trace::LiteralOpaque((const void *)m_pInstance);'
+        print '    Trace::EndArg();'
         for arg in method.args:
             if not arg.output:
                 self.unwrap_arg(method, arg)
@@ -417,11 +417,11 @@ class Tracer:
                 self.dump_arg(method, arg)
                 self.wrap_arg(method, arg)
         if method.type is not Void:
-            print '    Log::BeginReturn("%s");' % method.type
+            print '    Trace::BeginReturn("%s");' % method.type
             dump_instance(method.type, "__result")
-            print '    Log::EndReturn();'
+            print '    Trace::EndReturn();'
             wrap_instance(method.type, '__result')
-        print '    Log::EndCall();'
+        print '    Trace::EndCall();'
         if method.name == 'QueryInterface':
             print '    if (*ppvObj == m_pInstance)'
             print '        *ppvObj = this;'
diff --git a/trace_write.cpp b/trace_write.cpp
new file mode 100644 (file)
index 0000000..054303b
--- /dev/null
@@ -0,0 +1,324 @@
+/**************************************************************************
+ *
+ * Copyright 2007-2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <map>
+
+#include <zlib.h>
+
+#include "os.hpp"
+#include "trace_write.hpp"
+#include "trace_format.hpp"
+
+
+namespace Trace {
+
+
+static gzFile g_gzFile = NULL;
+static void _Close(void) {
+   if(g_gzFile != NULL) {
+      gzclose(g_gzFile);
+      g_gzFile = NULL;
+   }
+}
+
+static void _Open(const char *szExtension) {
+   _Close();
+   
+   static unsigned dwCounter = 0;
+
+   char szFileName[PATH_MAX];
+   const char *lpFileName;
+
+   lpFileName = getenv("TRACE_PATH");
+   if (lpFileName) {
+       strncpy(szFileName, lpFileName, PATH_MAX);
+   }
+   else {
+       char szProcessName[PATH_MAX];
+       char szCurrentDir[PATH_MAX];
+       OS::GetProcessName(szProcessName, PATH_MAX);
+       OS::GetCurrentDir(szCurrentDir, PATH_MAX);
+
+       for(;;) {
+          FILE *file;
+          
+          if (dwCounter)
+             snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
+          else
+             snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
+          
+          file = fopen(szFileName, "rb");
+          if(file == NULL)
+             break;
+          
+          fclose(file);
+          
+          ++dwCounter;
+       }
+   }
+
+   OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
+
+   g_gzFile = gzopen(szFileName, "wb");
+}
+
+static inline void Write(const void *sBuffer, size_t dwBytesToWrite) {
+   if (g_gzFile == NULL)
+      return;
+   
+   gzwrite(g_gzFile, sBuffer, dwBytesToWrite);
+}
+
+static inline void 
+WriteByte(char c) {
+   Write(&c, 1);
+}
+
+void inline 
+WriteUInt(unsigned long long value) {
+   char buf[2 * sizeof value];
+   unsigned len;
+
+   len = 0;
+   do {
+      assert(len < sizeof buf);
+      buf[len] = 0x80 | (value & 0x7f);
+      value >>= 7;
+      ++len;
+   } while (value);
+
+   assert(len);
+   buf[len - 1] &= 0x7f;
+
+   Write(buf, len);
+}
+
+static inline void 
+WriteFloat(float value) {
+   assert(sizeof value == 4);
+   Write((const char *)&value, sizeof value);
+}
+
+static inline void 
+WriteDouble(double value) {
+   assert(sizeof value == 8);
+   Write((const char *)&value, sizeof value);
+}
+
+static inline void 
+WriteString(const char *str) {
+   size_t len = strlen(str);
+   WriteUInt(len);
+   Write(str, len);
+}
+
+typedef std::map<const char *, size_t> namemap;
+static namemap names;
+
+static inline void 
+WriteName(const char *name) {
+   namemap::iterator it = names.find(name);
+   if (it == names.end()) {
+       size_t name_id = names.size();
+       WriteUInt(name_id);
+       WriteString(name);
+       names[name] = name_id;
+   } else {
+       WriteUInt(it->second);
+   }
+}
+
+void Open(void) {
+    if (!g_gzFile) {
+        _Open("trace");
+        WriteUInt(TRACE_VERSION);
+    }
+}
+
+void Close(void) {
+   _Close();
+}
+
+static unsigned call_no = 0;
+
+unsigned BeginEnter(const char *function) {
+   OS::AcquireMutex();
+   Open();
+   WriteByte(Trace::EVENT_ENTER);
+   WriteName(function);
+   return call_no++;
+}
+
+void EndEnter(void) {
+   WriteByte(Trace::CALL_END);
+   gzflush(g_gzFile, Z_SYNC_FLUSH);
+   OS::ReleaseMutex();
+}
+
+void BeginLeave(unsigned call) {
+   OS::AcquireMutex();
+   WriteByte(Trace::EVENT_LEAVE);
+   WriteUInt(call);
+}
+
+void EndLeave(void) {
+   WriteByte(Trace::CALL_END);
+   gzflush(g_gzFile, Z_SYNC_FLUSH);
+   OS::ReleaseMutex();
+}
+
+void BeginArg(unsigned index, const char *name) {
+   WriteByte(Trace::CALL_ARG);
+   WriteUInt(index);
+   WriteName(name);
+}
+
+void BeginReturn(void) {
+   WriteByte(Trace::CALL_RET);
+}
+
+void BeginArray(size_t length) {
+   WriteByte(Trace::TYPE_ARRAY);
+   WriteUInt(length);
+}
+
+void BeginStruct(size_t length) {
+   WriteByte(Trace::TYPE_STRUCT);
+   WriteUInt(length);
+}
+
+void BeginMember(const char *name) {
+   WriteName(name);
+}
+
+void BeginBitmask(void) {
+   WriteByte(Trace::TYPE_BITMASK);
+}
+
+void EndBitmask(void) {
+   WriteByte(Trace::TYPE_NULL);
+}
+
+void LiteralBool(bool value) {
+   WriteByte(value ? Trace::TYPE_TRUE : Trace::TYPE_FALSE);
+}
+
+void LiteralSInt(signed long long value) {
+   if (value < 0) {
+      WriteByte(Trace::TYPE_SINT);
+      WriteUInt(-value);
+   } else {
+      WriteByte(Trace::TYPE_UINT);
+      WriteUInt(value);
+   }
+}
+
+void LiteralUInt(unsigned long long value) {
+   WriteByte(Trace::TYPE_UINT);
+   WriteUInt(value);
+}
+
+void LiteralFloat(float value) {
+   WriteByte(Trace::TYPE_FLOAT);
+   WriteFloat(value);
+}
+
+void LiteralFloat(double value) {
+   WriteByte(Trace::TYPE_DOUBLE);
+   WriteDouble(value);
+}
+
+void LiteralString(const char *str) {
+   if (!str) {
+      LiteralNull();
+      return;
+   }
+   WriteByte(Trace::TYPE_STRING);
+   WriteString(str);
+}
+
+void LiteralString(const char *str, size_t len) {
+   if (!str) {
+      LiteralNull();
+      return;
+   }
+   WriteByte(Trace::TYPE_STRING);
+   WriteUInt(len);
+   Write(str, len);
+}
+
+void LiteralWString(const wchar_t *str) {
+   if (!str) {
+      LiteralNull();
+      return;
+   }
+   WriteByte(Trace::TYPE_STRING);
+   WriteString("<wide-string>");
+}
+   
+void LiteralBlob(const void *data, size_t size) {
+   if (!data) {
+      LiteralNull();
+      return;
+   }
+   WriteByte(Trace::TYPE_BLOB);
+   WriteUInt(size);
+   if (size) {
+      Write(data, size);
+   }
+}
+
+void LiteralNamedConstant(const char *name, long long value) {
+   WriteByte(Trace::TYPE_CONST);
+   WriteName(name);
+   LiteralSInt(value);
+}
+
+void LiteralNull(void) {
+   WriteByte(Trace::TYPE_NULL);
+}
+
+void LiteralOpaque(const void *addr) {
+   if (!addr) {
+      LiteralNull();
+      return;
+   }
+   WriteByte(Trace::TYPE_OPAQUE);
+   WriteUInt((size_t)addr);
+}
+
+void Abort(void) {
+    Close();
+    OS::Abort();
+}
+
+} /* namespace Trace */
diff --git a/trace_write.hpp b/trace_write.hpp
new file mode 100644 (file)
index 0000000..7b494e4
--- /dev/null
@@ -0,0 +1,77 @@
+/**************************************************************************
+ *
+ * Copyright 2007-2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _TRACE_HPP_
+#define _TRACE_HPP_
+
+namespace Trace {
+
+    void Open(void);
+    void Close(void);
+    
+    unsigned BeginEnter(const char *function);
+    void EndEnter(void);
+    
+    void BeginLeave(unsigned call);
+    void EndLeave(void);
+    
+    void BeginArg(unsigned index, const char *name);
+    inline void EndArg(void) {}
+
+    void BeginReturn(void);
+    inline void EndReturn(void) {}
+
+    void BeginArray(size_t length);
+    inline void EndArray(void) {}
+
+    inline void BeginElement(void) {}
+    inline void EndElement(void) {}
+
+    void BeginStruct(size_t length);
+    inline void EndStruct(void) {}
+
+    void BeginMember(const char *name);
+    inline void EndMember(void) {}
+
+    void BeginBitmask(void);
+    void EndBitmask(void);
+
+    void LiteralBool(bool value);
+    void LiteralSInt(signed long long value);
+    void LiteralUInt(unsigned long long value);
+    void LiteralFloat(float value);
+    void LiteralFloat(double value);
+    void LiteralString(const char *str);
+    void LiteralString(const char *str, size_t size);
+    void LiteralWString(const wchar_t *str);
+    void LiteralBlob(const void *data, size_t size);
+    void LiteralNamedConstant(const char *name, long long value);
+    void LiteralNull(void);
+    void LiteralOpaque(const void *ptr);
+
+    void Abort(void);
+}
+
+#endif /* _TRACE_HPP_ */
index b5f94f3b73345db91cd029e9ebef2fbffe612ed7..f75ae80f972802ac27fd0d96572156665dfc949c 100644 (file)
@@ -403,7 +403,7 @@ class WglTracer(Tracer):
             print '        if (!pwglGetProcAddress) {'
             print '            pwglGetProcAddress = (PwglGetProcAddress)__GetProcAddress("wglGetProcAddress");'
             print '            if (!pwglGetProcAddress)'
-            print '                Log::Abort();'
+            print '                Trace::Abort();'
             print '        }'
             return 'pwglGetProcAddress("%s")' % (function.name,)
 
@@ -431,7 +431,7 @@ if __name__ == '__main__':
     print
     print '#include "glimports.hpp"'
     print
-    print '#include "log.hpp"'
+    print '#include "trace_write.hpp"'
     print '#include "os.hpp"'
     print '#include "glsize.hpp"'
     print
index 30826e3fed9a957323b370d2fed3aa67c9d28e67..5345a0dc5bd62ec527298d7cdf371051a06d1fa5 100644 (file)
--- a/winapi.py
+++ b/winapi.py
@@ -199,13 +199,13 @@ class Dll:
         print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
         print r'            return FALSE;'
         print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
-        print r'        Log::Open("%s");' % self.name
+        print r'        Trace::Open("%s");' % self.name
         print r'    case DLL_THREAD_ATTACH:'
         print r'        return TRUE;'
         print r'    case DLL_THREAD_DETACH:'
         print r'        return TRUE;'
         print r'    case DLL_PROCESS_DETACH:'
-        print r'        Log::Close();'
+        print r'        Trace::Close();'
         print r'        if(g_hDll) {'
         print r'            FreeLibrary(g_hDll);'
         print r'            g_hDll = NULL;'