COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
DEPENDS opengl32.py gl.py windows.py base.py
)
- add_library (opengl32 SHARED opengl32.def opengl32.cpp log.cpp)
+ add_library (opengl32 SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
set_target_properties (opengl32 PROPERTIES PREFIX "")
else ()
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glx.py > ${CMAKE_CURRENT_BINARY_DIR}/glx.cpp
DEPENDS glx.py gl.py dl.py base.py
)
- add_library (glxtrace SHARED glx.cpp log.cpp)
+ add_library (glxtrace SHARED glx.cpp log.cpp os_posix.cpp)
set_target_properties (glxtrace PROPERTIES PREFIX "")
target_link_libraries (glxtrace dl)
endif ()
'ddraw.def',
'ddraw.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
'd3d8.def',
'd3d8.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
'd3d9.def',
'd3d9.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
'd3d10.def',
'd3d10.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
'd3d10_1.def',
'd3d10_1.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
'opengl32.def',
'opengl32.cpp',
'log.cpp',
+ 'os_win32.cpp',
]
)
from gl import *
from dl import *
-libgl = Dll("libGL.so")
+libgl = Dll("GL")
libgl.functions += [
DllFunction(Void, "glNewList", [(GLuint, "list"), (GLenum, "mode")]),
DllFunction(Void, "glEndList", []),
#include <stdlib.h>
#include <string.h>
-#ifdef WIN32
-#include <windows.h>
-#endif
-
#include <zlib.h>
+#include "os.hpp"
#include "log.hpp"
-#ifdef WIN32
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#ifndef vsnprintf
-#define vsnprintf _vsnprintf
-#endif
-#endif /* WIN32 */
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024
-#endif
-
namespace Log {
static gzFile g_gzFile = NULL;
-static char g_szFileName[PATH_MAX];
-
-#if WIN32
-static CRITICAL_SECTION CriticalSection;
-#endif /* WIN32 */
-
static void _Close(void) {
if(g_gzFile != NULL) {
gzclose(g_gzFile);
g_gzFile = NULL;
-#if WIN32
- DeleteCriticalSection(&CriticalSection);
-#endif
}
}
static unsigned dwCounter = 0;
- char szProcessPath[PATH_MAX];
- char *lpProcessName;
- char *lpProcessExt;
-
-#ifdef WIN32
- GetModuleFileNameA(NULL, szProcessPath, sizeof(szProcessPath)/sizeof(szProcessPath[0]));
+ char szProcessName[PATH_MAX];
+ char szFileName[PATH_MAX];
- lpProcessName = strrchr(szProcessPath, '\\');
- lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
- lpProcessExt = strrchr(lpProcessName, '.');
- if(lpProcessExt)
- *lpProcessExt = '\0';
-#else
- // http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
- lpProcessName = "";
-#endif
+ OS::GetProcessName(szProcessName, PATH_MAX);
for(;;) {
FILE *file;
if(dwCounter)
- snprintf(g_szFileName, PATH_MAX, "%s.%s.%u.%s.gz", lpProcessName, szName, dwCounter, szExtension);
+ snprintf(szFileName, PATH_MAX, "%s.%s.%u.%s.gz", szProcessName, szName, dwCounter, szExtension);
else
- snprintf(g_szFileName, PATH_MAX, "%s.%s.%s.gz", lpProcessName, szName, szExtension);
+ snprintf(szFileName, PATH_MAX, "%s.%s.%s.gz", szProcessName, szName, szExtension);
- file = fopen(g_szFileName, "rb");
+ file = fopen(szFileName, "rb");
if(file == NULL)
break;
++dwCounter;
}
- g_gzFile = gzopen(g_szFileName, "wb");
-#ifdef WIN32
- InitializeCriticalSection(&CriticalSection);
-#endif
+ fprintf(stderr, "Logging to %s\n", szFileName);
+ g_gzFile = gzopen(szFileName, "wb");
}
static inline void _ReOpen(void) {
}
void BeginCall(const char *function) {
-#ifdef WIN32
- EnterCriticalSection(&CriticalSection);
-#endif
+ OS::AcquireMutex();
Indent(1);
BeginTag("call", "name", function);
NewLine();
EndTag("call");
NewLine();
gzflush(g_gzFile, Z_SYNC_FLUSH);
-#ifdef WIN32
- LeaveCriticalSection(&CriticalSection);
-#endif
+ OS::ReleaseMutex();
}
void BeginArg(const char *type, const char *name) {
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 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 _OS_HPP_
+#define _OS_HPP_
+
+#ifdef WIN32
+#ifndef snprintf
+#define snprintf _snprintf
+#endif
+#ifndef vsnprintf
+#define vsnprintf _vsnprintf
+#endif
+#endif /* WIN32 */
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+namespace OS {
+
+void AcquireMutex(void);
+
+void ReleaseMutex(void);
+
+bool GetProcessName(char *str, size_t size);
+
+} /* namespace OS */
+
+#endif /* _OS_HPP_ */
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 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.
+ *
+ **************************************************************************/
+
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#include "os.hpp"
+
+namespace OS {
+
+
+static pthread_mutex_t
+mutex = PTHREAD_MUTEX_INITIALIZER;
+
+
+void
+AcquireMutex(void)
+{
+ pthread_mutex_lock(&mutex);
+}
+
+
+void
+ReleaseMutex(void)
+{
+ pthread_mutex_unlock(&mutex);
+}
+
+
+bool
+GetProcessName(char *str, size_t size)
+{
+ char szProcessPath[PATH_MAX + 1];
+ char *lpProcessName;
+
+ // http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
+ if (readlink("/proc/self/exe", szProcessPath, sizeof(szProcessPath) - 1) == -1) {
+ *str = 0;
+ return false;
+ }
+
+ lpProcessName = strrchr(szProcessPath, '/');
+ lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
+
+ strncpy(str, lpProcessName, size);
+
+ return true;
+}
+
+
+} /* namespace OS */
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 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.
+ *
+ **************************************************************************/
+
+#include <windows.h>
+#include <string.h>
+
+#include "os.hpp"
+
+
+namespace OS {
+
+
+/*
+ * Trick from http://locklessinc.com/articles/pthreads_on_windows/
+ */
+static CRITICAL_SECTION
+CriticalSection = {
+ (_CRITICAL_SECTION_DEBUG *)-1, -1, 0, 0, 0, 0
+};
+
+
+void
+AcquireMutex(void)
+{
+ EnterCriticalSection(&CriticalSection);
+}
+
+
+void
+ReleaseMutex(void)
+{
+ LeaveCriticalSection(&CriticalSection);
+}
+
+
+bool
+GetProcessName(char *str, size_t size)
+{
+ 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';
+ }
+
+ strncpy(str, lpProcessName, size);
+
+ return true;
+}
+
+
+} /* namespace OS */