Permalink
Browse files

Improve profiling code

  • Loading branch information...
1 parent 2c2c90e commit dd3cf77beef187e05abfbfd33262bc488810f855 @cgutman cgutman committed May 9, 2016
Showing with 32 additions and 6 deletions.
  1. +7 −0 moonlight.hpp
  2. +25 −6 profiling.cpp
View
@@ -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);
View
@@ -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
-}
+ printDeltaAboveThreshold(message, (uint32_t)(timeB - timeA));
+}

0 comments on commit dd3cf77

Please sign in to comment.