Permalink
Browse files

Relocate tracing (dis/en)enablement.

Out of common -- as it is tracing specific
  • Loading branch information...
1 parent b4c584d commit 537c507874cdde0b507d306ac058767f506da8e2 @jrfonseca jrfonseca committed Jul 7, 2012
Showing with 196 additions and 78 deletions.
  1. +0 −9 common/os.hpp
  2. +0 −66 common/os_posix.cpp
  3. +0 −1 wrappers/.gitignore
  4. +18 −0 wrappers/CMakeLists.txt
  5. +115 −0 wrappers/trace.cpp
  6. +56 −0 wrappers/trace.hpp
  7. +7 −2 wrappers/trace.py
View
@@ -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));
View
@@ -46,10 +46,6 @@
#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)
{
View
@@ -9,5 +9,4 @@ dlltrace.cpp
egltrace.cpp
gltrace.cpp
glxtrace.cpp
-trace.cpp
wgltrace.cpp
@@ -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}
View
@@ -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 */
+
View
@@ -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_ */
View
@@ -396,6 +396,9 @@ def header(self, api):
print '#else'
print '# include <alloca.h> // alloca'
print '#endif'
+ print
+ print '#include "trace.hpp"'
+ print
def footer(self, api):
pass
@@ -422,14 +425,16 @@ def traceFunctionImpl(self, function):
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;'

0 comments on commit 537c507

Please sign in to comment.