Improve profiling code

This commit is contained in:
Cameron Gutman 2016-05-09 14:25:58 -04:00
parent 2c2c90ef94
commit dd3cf77bee
2 changed files with 32 additions and 6 deletions

View File

@ -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 File

@ -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));
}