From: José Fonseca Date: Thu, 10 Nov 2011 06:37:13 +0000 (+0000) Subject: Add an "--api" option to "apitrace trace" allowing to choose egl. X-Git-Tag: 2.0_alpha^2~501 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f28cd84c31bfe031a0f9ae119f0bcc55d59286e;p=tools%2Fapitrace.git Add an "--api" option to "apitrace trace" allowing to choose egl. --- diff --git a/cli/cli_trace.cpp b/cli/cli_trace.cpp index b96dca8..92251b4 100644 --- a/cli/cli_trace.cpp +++ b/cli/cli_trace.cpp @@ -50,6 +50,8 @@ usage(void) " with other apitrace utilities for replay or analysis.\n" "\n" " -v, --verbose verbose output\n" + " -a, --api API specify API to trace (gl or egl);\n" + " default is `gl`\n" " -o, --output TRACE specify output trace file;\n" " default is `PROGRAM.trace`\n"; } @@ -58,6 +60,7 @@ static int command(int argc, char *argv[]) { bool verbose = false; + trace::API api = trace::API_GL; const char *output = NULL; int i; @@ -78,6 +81,18 @@ command(int argc, char *argv[]) } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0) { verbose = true; + } else if (strcmp(arg, "-a") == 0 || + strcmp(arg, "--api") == 0) { + arg = argv[i++]; + if (strcmp(arg, "gl") == 0) { + api = trace::API_GL; + } else if (strcmp(arg, "egl") == 0) { + api = trace::API_EGL; + } else { + std::cerr << "error: unknown API `" << arg << "`\n"; + usage(); + return 1; + } } else if (strcmp(arg, "-o") == 0 || strcmp(arg, "--output") == 0) { output = argv[i++]; @@ -95,7 +110,7 @@ command(int argc, char *argv[]) } assert(argv[argc] == 0); - return trace::traceProgram(argv + i, output, verbose); + return trace::traceProgram(api, argv + i, output, verbose); } const Command trace_command = { diff --git a/common/trace_tools.hpp b/common/trace_tools.hpp index f141d2c..ed786e9 100644 --- a/common/trace_tools.hpp +++ b/common/trace_tools.hpp @@ -38,13 +38,20 @@ namespace os { namespace trace { +enum API { + API_GL, // GL + GLX/WGL/CGL + API_EGL, // GL/GLES1/GLES2/VG + EGL +}; + + os::Path findFile(const char *relPath, // path relative to the current program const char *absPath, // absolute path bool verbose); int -traceProgram(char * const *argv, +traceProgram(API api, + char * const *argv, const char *output = NULL, bool verbose = false); diff --git a/common/trace_tools_trace.cpp b/common/trace_tools_trace.cpp index 9a69928..d1d6483 100644 --- a/common/trace_tools_trace.cpp +++ b/common/trace_tools_trace.cpp @@ -39,14 +39,15 @@ namespace trace { #if defined(__APPLE__) -#define CLI_TRACE_VARIABLE "DYLD_LIBRARY_PATH" -#define CLI_TRACE_WRAPPER "OpenGL" +#define TRACE_VARIABLE "DYLD_LIBRARY_PATH" +#define GL_TRACE_WRAPPER "OpenGL" #elif defined(_WIN32) -#define CLI_TRACE_VARIABLE "" -#define CLI_TRACE_WRAPPER "opengl32.dll" +#define TRACE_VARIABLE "" +#define GL_TRACE_WRAPPER "opengl32.dll" #else -#define CLI_TRACE_VARIABLE "LD_PRELOAD" -#define CLI_TRACE_WRAPPER "glxtrace.so" +#define TRACE_VARIABLE "LD_PRELOAD" +#define GL_TRACE_WRAPPER "glxtrace.so" +#define EGL_TRACE_WRAPPER "egltrace.so" #endif @@ -84,13 +85,35 @@ findFile(const char *relPath, int -traceProgram(char * const *argv, +traceProgram(API api, + char * const *argv, const char *output, bool verbose) { - os::Path wrapper; + const char *relPath; + const char *absPath; + + switch (api) { + case API_GL: + relPath = "wrappers/" GL_TRACE_WRAPPER; + absPath = APITRACE_WRAPPER_INSTALL_DIR "/" GL_TRACE_WRAPPER; + break; + case API_EGL: +#ifndef EGL_TRACE_WRAPPER + std::cerr << "error: unsupported API\n"; + return 1; +#else + relPath = "wrappers/" EGL_TRACE_WRAPPER; + absPath = APITRACE_WRAPPER_INSTALL_DIR "/" EGL_TRACE_WRAPPER; + break; +#endif + default: + std::cerr << "error: invalid API\n"; + return 1; + } - wrapper = findFile("wrappers/" CLI_TRACE_WRAPPER, APITRACE_WRAPPER_INSTALL_DIR "/" CLI_TRACE_WRAPPER, verbose); + os::Path wrapper; + wrapper = findFile(relPath, absPath, verbose); if (!wrapper.length()) { return 1; @@ -113,11 +136,11 @@ traceProgram(char * const *argv, #endif if (verbose) { - std::cerr << CLI_TRACE_VARIABLE << "=" << wrapper.str() << "\n"; + std::cerr << TRACE_VARIABLE << "=" << wrapper.str() << "\n"; } /* FIXME: Don't modify the current environment */ - setenv(CLI_TRACE_VARIABLE, wrapper.str(), 1); + setenv(TRACE_VARIABLE, wrapper.str(), 1); if (output) { setenv("TRACE_FILE", output, 1); @@ -134,7 +157,7 @@ traceProgram(char * const *argv, execvp(argv[0], argv); - unsetenv(CLI_TRACE_VARIABLE); + unsetenv(TRACE_VARIABLE); if (output) { unsetenv("TRACE_FILE"); }