Skip to content

Commit

Permalink
Merge pull request #18200 from hrydgard/assert-time
Browse files Browse the repository at this point in the history
Add time-elapsed to assert messages
  • Loading branch information
hrydgard committed Sep 23, 2023
2 parents a9b6421 + 949f746 commit c1529b2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Common/Log.cpp
Expand Up @@ -25,6 +25,7 @@
#include "StringUtils.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/TimeUtil.h"

#if PPSSPP_PLATFORM(ANDROID)
#include <android/log.h>
Expand All @@ -38,10 +39,12 @@ static bool hitAnyAsserts = false;

std::mutex g_extraAssertInfoMutex;
std::string g_extraAssertInfo = "menu";
double g_assertInfoTime = 0.0;

void SetExtraAssertInfo(const char *info) {
std::lock_guard<std::mutex> guard(g_extraAssertInfoMutex);
g_extraAssertInfo = info ? info : "menu";
g_assertInfoTime = time_now_d();
}

bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
Expand All @@ -57,7 +60,8 @@ bool HandleAssert(const char *function, const char *file, int line, const char *
char formatted[LOG_BUF_SIZE + 128];
{
std::lock_guard<std::mutex> guard(g_extraAssertInfoMutex);
snprintf(formatted, sizeof(formatted), "(%s:%s:%d): [%s] (%s) %s", file, function, line, expression, g_extraAssertInfo.c_str(), text);
double delta = time_now_d() - g_assertInfoTime;
snprintf(formatted, sizeof(formatted), "(%s:%s:%d): [%s] (%s, %0.1fs) %s", file, function, line, expression, g_extraAssertInfo.c_str(), delta, text);
}

// Normal logging (will also log to Android log)
Expand Down

0 comments on commit c1529b2

Please sign in to comment.