#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));
#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
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)
{
egltrace.cpp
gltrace.cpp
glxtrace.cpp
-trace.cpp
wgltrace.cpp
${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)
)
add_library (ddrawtrace MODULE ddraw.def ddrawtrace.cpp)
target_link_libraries (ddrawtrace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
)
add_library (d3d8trace MODULE d3d8.def d3d8trace.cpp d3d9shader.cpp)
target_link_libraries (d3d8trace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
)
add_library (d3d9trace MODULE d3d9.def d3d9trace.cpp d3d9shader.cpp)
target_link_libraries (d3d9trace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
)
add_library (d3d10trace MODULE d3d10.def d3d10trace.cpp d3d10shader.cpp)
target_link_libraries (d3d10trace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
)
add_library (d3d10_1trace MODULE d3d10_1.def d3d10_1trace.cpp)
target_link_libraries (d3d10_1trace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
)
add_library (d3d11trace MODULE d3d11.def d3d11trace.cpp)
target_link_libraries (d3d11trace
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
add_dependencies (wgltrace glproc)
target_link_libraries (wgltrace
glproc_gl
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
target_link_libraries (cgltrace
glproc_gl
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
target_link_libraries (glxtrace
glproc_gl
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
target_link_libraries (egltrace
glproc_egl
+ common_trace
common
${ZLIB_LIBRARIES}
${SNAPPY_LIBRARIES}
--- /dev/null
+/**************************************************************************
+ *
+ * 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 */
+
--- /dev/null
+/**************************************************************************
+ *
+ * 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_ */
print '#else'
print '# include <alloca.h> // alloca'
print '#endif'
+ print
+ print '#include "trace.hpp"'
+ print
def footer(self, api):
pass
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;'