From: Ryan C. Gordon Date: Sun, 8 Jan 2012 06:32:41 +0000 (-0500) Subject: Add simple CPU profiling support to glretrace. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=2dad4b44fc34f6bd31584b1e2b25aaa9ea861110;p=apitrace Add simple CPU profiling support to glretrace. This will note the time that each traced call required, and will dump this information during the replay, giving a basic idea of where CPU time was spent in the GL. Signed-off-by: José Fonseca --- diff --git a/common/trace_dump.cpp b/common/trace_dump.cpp index fd1d16a..c55bbb1 100644 --- a/common/trace_dump.cpp +++ b/common/trace_dump.cpp @@ -200,6 +200,10 @@ public: void visit(Call *call) { CallFlags callFlags = call->flags; + + if (!(dumpFlags & DUMP_FLAG_NO_CALL_NO)) { + os << call->no << " "; + } if (callFlags & CALL_FLAG_NON_REPRODUCIBLE) { os << strike; @@ -252,7 +256,6 @@ void dump(Value *value, std::ostream &os, DumpFlags flags) { void dump(Call &call, std::ostream &os, DumpFlags flags) { Dumper d(os, flags); - os << call.no << " "; d.visit(&call); } diff --git a/common/trace_dump.hpp b/common/trace_dump.hpp index 4ffe65a..d4612e5 100644 --- a/common/trace_dump.hpp +++ b/common/trace_dump.hpp @@ -44,6 +44,7 @@ typedef unsigned DumpFlags; enum { DUMP_FLAG_NO_COLOR = (1 << 0), DUMP_FLAG_NO_ARG_NAMES = (1 << 1), + DUMP_FLAG_NO_CALL_NO = (1 << 2), }; diff --git a/glretrace.py b/glretrace.py index 7570ebd..e862e25 100644 --- a/glretrace.py +++ b/glretrace.py @@ -240,7 +240,7 @@ class GlRetracer(Retracer): print ' glretrace::insideGlBeginEnd = true;' elif function.name.startswith('gl'): # glGetError is not allowed inside glBegin/glEnd - print ' if (!glretrace::benchmark && !glretrace::insideGlBeginEnd) {' + print ' if (!glretrace::benchmark && !retrace::profiling && !glretrace::insideGlBeginEnd) {' print ' glretrace::checkGlError(call);' if function.name in ('glProgramStringARB', 'glProgramStringNV'): print r' GLint error_position = -1;' diff --git a/glretrace_main.cpp b/glretrace_main.cpp index f9d7741..785d6fe 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -256,7 +256,7 @@ static void display(void) { long long endTime = os::getTime(); float timeInterval = (endTime - startTime) * (1.0 / os::timeFrequency); - if (retrace::verbosity >= -1) { + if ((retrace::verbosity >= -1) || (retrace::profiling)) { std::cout << "Rendered " << frame << " frames" " in " << timeInterval << " secs," @@ -277,6 +277,7 @@ static void usage(void) { "Replay TRACE.\n" "\n" " -b benchmark mode (no error checking or warning messages)\n" + " -p profiling mode (run whole trace, dump profiling info)\n" " -c PREFIX compare against snapshots\n" " -C CALLSET calls to compare (default is every frame)\n" " -core use core profile\n" @@ -309,6 +310,10 @@ int main(int argc, char **argv) benchmark = true; retrace::verbosity = -1; glws::debug = false; + } else if (!strcmp(arg, "-p")) { + retrace::profiling = true; + retrace::verbosity = -1; + glws::debug = false; } else if (!strcmp(arg, "-c")) { compare_prefix = argv[++i]; if (compare_frequency.empty()) { diff --git a/retrace.cpp b/retrace.cpp index 849c597..d2e6d37 100644 --- a/retrace.cpp +++ b/retrace.cpp @@ -27,6 +27,7 @@ #include #include +#include "os_time.hpp" #include "trace_dump.hpp" #include "retrace.hpp" @@ -35,6 +36,7 @@ namespace retrace { int verbosity = 0; +bool profiling = false; static bool call_dumped = false; @@ -114,7 +116,20 @@ void Retracer::retrace(trace::Call &call) { assert(callback); assert(callbacks[id] == callback); - callback(call); + if (retrace::profiling) { + long long startTime = os::getTime(); + callback(call); + long long stopTime = os::getTime(); + float timeInterval = (stopTime - startTime) * (1.0E6 / os::timeFrequency); + + std::cout + << call.no << " " + << "[" << timeInterval << " usec] " + ; + trace::dump(call, std::cout, trace::DUMP_FLAG_NO_CALL_NO | trace::DUMP_FLAG_NO_COLOR); + } else { + callback(call); + } } diff --git a/retrace.hpp b/retrace.hpp index a59a6eb..57b8b05 100644 --- a/retrace.hpp +++ b/retrace.hpp @@ -95,6 +95,11 @@ toPointer(trace::Value &value, bool bind = false); */ extern int verbosity; +/** + * Add profiling data to the dump when retracing. + */ +extern bool profiling; + std::ostream &warning(trace::Call &call);