From dd3cf77beef187e05abfbfd33262bc488810f855 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 9 May 2016 14:25:58 -0400 Subject: [PATCH] Improve profiling code --- moonlight.hpp | 7 +++++++ profiling.cpp | 31 +++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/moonlight.hpp b/moonlight.hpp index d29b7ca..ae38338 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -31,6 +31,10 @@ // Uncomment this line to enable the profiling infrastructure //#define ENABLE_PROFILING 1 +// Use this define to choose the time threshold in milliseconds above +// which a profiling message is printed +#define PROFILING_MESSAGE_THRESHOLD 1 + struct Shader { Shader() : program(0), texcoord_scale_location(0) {} ~Shader() {} @@ -92,6 +96,9 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { static uint64_t ProfilerUnpackTime(uint32_t packedTime); static void ProfilerPrintPackedDelta(const char* message, uint32_t packedTimeA, uint32_t packedTimeB); static void ProfilerPrintDelta(const char* message, uint64_t timeA, uint64_t timeB); + static void ProfilerPrintPackedDeltaFromNow(const char* message, uint32_t packedTime); + static void ProfilerPrintDeltaFromNow(const char* message, uint64_t time); + static void ProfilerPrintWarning(const char* message); static void* ConnectionThreadFunc(void* context); static void* GamepadThreadFunc(void* context); diff --git a/profiling.cpp b/profiling.cpp index a60a91b..b4d0309 100644 --- a/profiling.cpp +++ b/profiling.cpp @@ -51,19 +51,38 @@ uint64_t MoonlightInstance::ProfilerUnpackTime(uint32_t packedTime) { #endif } +static void printDeltaAboveThreshold(const char* message, uint32_t delta) { +#if defined(ENABLE_PROFILING) + if (PROFILING_MESSAGE_THRESHOLD < 0 || delta > PROFILING_MESSAGE_THRESHOLD) { + printf("%s: %d ms\n", message, delta); + } +#endif +} + +void MoonlightInstance::ProfilerPrintPackedDeltaFromNow(const char* message, uint32_t packedTime) { + ProfilerPrintPackedDelta(message, packedTime, ProfilerGetPackedMillis()); +} + void MoonlightInstance::ProfilerPrintPackedDelta(const char* message, uint32_t packedTimeA, uint32_t packedTimeB) { + printDeltaAboveThreshold(message, + (uint32_t)(ProfilerUnpackTime(packedTimeB) - + ProfilerUnpackTime(packedTimeA))); +} + +void MoonlightInstance::ProfilerPrintWarning(const char* message) { #if defined(ENABLE_PROFILING) - printf("%s: %d ms\n", message, - (uint32_t)(ProfilerUnpackTime(packedTimeB) - ProfilerUnpackTime(packedTimeA))); + printf("PROFILING WARNING: %s\n", message); #endif } +void MoonlightInstance::ProfilerPrintDeltaFromNow(const char* message, uint64_t time) { + ProfilerPrintDelta(message, time, ProfilerGetMillis()); +} + void MoonlightInstance::ProfilerPrintDelta(const char* message, uint64_t timeA, uint64_t timeB) { -#if defined(ENABLE_PROFILING) - printf("%s: %d ms\n", message, (uint32_t)(timeA - timeB)); -#endif -} \ No newline at end of file + printDeltaAboveThreshold(message, (uint32_t)(timeB - timeA)); +}