]> git.cworth.org Git - apitrace/commitdiff
Relocate tracing (dis/en)enablement.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 7 Jul 2012 11:54:09 +0000 (12:54 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 7 Jul 2012 11:54:09 +0000 (12:54 +0100)
Out of common -- as it is tracing specific

common/os.hpp
common/os_posix.cpp
wrappers/.gitignore
wrappers/CMakeLists.txt
wrappers/trace.cpp [new file with mode: 0644]
wrappers/trace.hpp [new file with mode: 0644]
wrappers/trace.py

index 7f624517432838f1a8fd38515cbf0c871b15af6d..cc72a0ea5b288184ffeb1759894344d2f5f5de3a 100644 (file)
@@ -70,15 +70,6 @@ void log(const char *format, ...)
   #endif
 #endif
 
-#ifdef ANDROID
-bool apitrace_enabled(void);
-#else
-static inline bool apitrace_enabled(void)
-{
-    return true;
-}
-#endif
-
 void abort(void);
 
 void setExceptionCallback(void (*callback)(void));
index e4de967b045fd67c3ff5837127a5ddc18ccf055a..7d39d8ada5e0ffafc0f730bcdd3e913744f734d2 100644 (file)
 
 #ifdef ANDROID
 #include <android/log.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/system_properties.h>
 #endif
 
 #ifndef PATH_MAX
@@ -101,68 +97,6 @@ getProcessName(void)
     return path;
 }
 
-#ifdef ANDROID
-static String
-getZygoteProcessName(void)
-{
-    String path;
-    size_t size = PATH_MAX;
-    char *buf = path.buf(size);
-    ssize_t len;
-
-    int fd = open("/proc/self/cmdline", O_RDONLY);
-
-    assert(fd >= 0);
-    len = read(fd, buf, size - 1);
-    close(fd);
-    path.truncate(len);
-
-    return path;
-}
-
-static bool isZygoteProcess(void)
-{
-    os::String proc_name;
-
-    proc_name = getProcessName();
-    proc_name.trimDirectory();
-
-    return strcmp(proc_name, "app_process") == 0;
-}
-
-bool apitrace_enabled(void)
-{
-    static pid_t cached_pid;
-    static bool enabled;
-    pid_t pid;
-
-    pid = getpid();
-    if (cached_pid == pid)
-        return enabled;
-    cached_pid = pid;
-
-    if (!isZygoteProcess()) {
-        os::log("apitrace[%d]: enabled for standalone %s", pid,
-                (const char *)getProcessName());
-        enabled = true;
-        return true;
-    }
-
-    char target_proc_name[PROP_VALUE_MAX] = "";
-    os::String proc_name;
-
-    proc_name = getZygoteProcessName();
-    proc_name.trimDirectory();
-
-    __system_property_get("debug.apitrace.procname", target_proc_name);
-    enabled = !strcmp(target_proc_name, proc_name);
-    os::log("apitrace[%d]: %s for %s",
-            pid, enabled ? "enabled" : "disabled", (const char *)proc_name);
-
-    return enabled;
-}
-#endif
-
 String
 getCurrentDir(void)
 {
index 8ba6fb819598527c06c5bdd261c6f5c5a909fac2..2f8172099842b4d27e3ee14feb8ebbd0886b438d 100644 (file)
@@ -9,5 +9,4 @@ dlltrace.cpp
 egltrace.cpp
 gltrace.cpp
 glxtrace.cpp
-trace.cpp
 wgltrace.cpp
index a33350470730fe5d4245a5a66dc81180448e194f..259c7fb4759d03887ab23457d3f3227ead5d23f1 100644 (file)
@@ -9,6 +9,14 @@ include_directories (
     ${CMAKE_SOURCE_DIR}/dispatch
 )
 
+add_library (common_trace STATIC
+    trace.cpp
+)
+
+set_target_properties (common_trace PROPERTIES
+    # Ensure it can be statically linked in shared libraries
+    COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
+)
 
 if (WIN32)
     if (MINGW)
@@ -36,6 +44,7 @@ if (WIN32)
         )
         add_library (ddrawtrace MODULE ddraw.def ddrawtrace.cpp)
         target_link_libraries (ddrawtrace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -66,6 +75,7 @@ if (WIN32)
         )
         add_library (d3d8trace MODULE d3d8.def d3d8trace.cpp d3d9shader.cpp)
         target_link_libraries (d3d8trace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -96,6 +106,7 @@ if (WIN32)
         )
         add_library (d3d9trace MODULE d3d9.def d3d9trace.cpp d3d9shader.cpp)
         target_link_libraries (d3d9trace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -132,6 +143,7 @@ if (WIN32)
         )
         add_library (d3d10trace MODULE d3d10.def d3d10trace.cpp d3d10shader.cpp)
         target_link_libraries (d3d10trace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -166,6 +178,7 @@ if (WIN32)
         )
         add_library (d3d10_1trace MODULE d3d10_1.def d3d10_1trace.cpp)
         target_link_libraries (d3d10_1trace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -205,6 +218,7 @@ if (WIN32)
         )
         add_library (d3d11trace MODULE d3d11.def d3d11trace.cpp)
         target_link_libraries (d3d11trace
+            common_trace
             common
             ${ZLIB_LIBRARIES}
             ${SNAPPY_LIBRARIES}
@@ -240,6 +254,7 @@ if (WIN32)
     add_dependencies (wgltrace glproc)
     target_link_libraries (wgltrace
         glproc_gl
+        common_trace
         common
         ${ZLIB_LIBRARIES}
         ${SNAPPY_LIBRARIES}
@@ -282,6 +297,7 @@ elseif (APPLE)
 
     target_link_libraries (cgltrace
         glproc_gl
+        common_trace
         common
         ${ZLIB_LIBRARIES}
         ${SNAPPY_LIBRARIES}
@@ -323,6 +339,7 @@ elseif (X11_FOUND)
 
     target_link_libraries (glxtrace
         glproc_gl
+        common_trace
         common
         ${ZLIB_LIBRARIES}
         ${SNAPPY_LIBRARIES}
@@ -369,6 +386,7 @@ if (ENABLE_EGL AND NOT WIN32 AND NOT APPLE)
 
     target_link_libraries (egltrace
         glproc_egl
+        common_trace
         common
         ${ZLIB_LIBRARIES}
         ${SNAPPY_LIBRARIES}
diff --git a/wrappers/trace.cpp b/wrappers/trace.cpp
new file mode 100644 (file)
index 0000000..eb68934
--- /dev/null
@@ -0,0 +1,115 @@
+/**************************************************************************
+ *
+ * Copyright 2010-2011 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef ANDROID
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/system_properties.h>
+#endif
+
+#include "os.hpp"
+#include "os_string.hpp"
+#include "trace.hpp"
+
+
+namespace trace {
+
+
+#ifdef ANDROID
+
+static bool
+isZygoteProcess(void)
+{
+    os::String proc_name;
+
+    proc_name = os::getProcessName();
+    proc_name.trimDirectory();
+
+    return strcmp(proc_name, "app_process") == 0;
+}
+
+static os::String
+getZygoteProcessName(void)
+{
+    os::String path;
+    size_t size = PATH_MAX;
+    char *buf = path.buf(size);
+    ssize_t len;
+
+    int fd = open("/proc/self/cmdline", O_RDONLY);
+
+    assert(fd >= 0);
+    len = read(fd, buf, size - 1);
+    close(fd);
+    path.truncate(len);
+
+    return path;
+}
+
+bool
+isTracingEnabled(void)
+{
+    static pid_t cached_pid;
+    static bool enabled;
+    pid_t pid;
+
+    pid = getpid();
+    if (cached_pid == pid)
+        return enabled;
+    cached_pid = pid;
+
+    if (!isZygoteProcess()) {
+        os::log("apitrace[%d]: enabled for standalone %s",
+                pid, (const char *)os::getProcessName());
+        enabled = true;
+        return true;
+    }
+
+    char target_proc_name[PROP_VALUE_MAX] = "";
+    os::String proc_name;
+
+    proc_name = getZygoteProcessName();
+    proc_name.trimDirectory();
+
+    __system_property_get("debug.apitrace.procname", target_proc_name);
+    enabled = !strcmp(target_proc_name, proc_name);
+    os::log("apitrace[%d]: %s for %s",
+            pid, enabled ? "enabled" : "disabled", (const char *)proc_name);
+
+    return enabled;
+}
+
+#endif /* ANDROID */
+
+
+} /* namespace trace */
+
diff --git a/wrappers/trace.hpp b/wrappers/trace.hpp
new file mode 100644 (file)
index 0000000..997617e
--- /dev/null
@@ -0,0 +1,56 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * 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.
+ *
+ **************************************************************************/
+
+
+/*
+ * Comon definitions for all tracers.
+ */
+
+
+#ifndef _TRACE_HPP_
+#define _TRACE_HPP_
+
+
+namespace trace {
+
+
+#ifdef ANDROID
+
+bool isTracingEnabled(void);
+
+#else /* !ANDROID */
+
+static inline bool
+isTracingEnabled(void) {
+    return true;
+}
+
+#endif /* !ANDROID */
+
+
+} /* namespace trace */
+
+
+#endif /* _TRACE_HPP_ */
index aab99d793c1ce433bf6ad19d97d7afd89bfbac15..958c07279a1bf55eab84d44d349ef6a3fded764f 100644 (file)
@@ -396,6 +396,9 @@ class Tracer:
         print '#else'
         print '#  include <alloca.h> // alloca'
         print '#endif'
+        print
+        print '#include "trace.hpp"'
+        print
 
     def footer(self, api):
         pass
@@ -422,14 +425,16 @@ class Tracer:
         print function.prototype() + ' {'
         if function.type is not stdapi.Void:
             print '    %s _result;' % function.type
-        print '    if (!os::apitrace_enabled()) {'
+
+        # No-op if tracing is disabled
+        print '    if (!trace::isTracingEnabled()) {'
         Tracer.invokeFunction(self, function)
         if function.type is not stdapi.Void:
             print '        return _result;'
         else:
             print '        return;'
         print '    }'
-        print
+
         self.traceFunctionImplBody(function)
         if function.type is not stdapi.Void:
             print '    return _result;'