diff options
| author | JosJuice <josjuice@gmail.com> | 2025-04-21 20:19:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-21 20:19:47 +0200 |
| commit | c0c180bdc21cd9fe7374df3f83db57cdf8f5c492 (patch) | |
| tree | b66b17f4906e3f305ca5f84139ce62766cc0701d /Source/Core/Common/Profiler.cpp | |
| parent | 258fc1b2093f7734c9ac6269d36c2c57ec0ec75f (diff) | |
| parent | 957265ba5271aef0b14c3bc39fb015c9d1ae7805 (diff) | |
Merge pull request #13467 from JosJuice/profiler-thread-safety
Common: Make Profiler thread safe
Diffstat (limited to 'Source/Core/Common/Profiler.cpp')
| -rw-r--r-- | Source/Core/Common/Profiler.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Source/Core/Common/Profiler.cpp b/Source/Core/Common/Profiler.cpp index f3903629e6..34aafd38fd 100644 --- a/Source/Core/Common/Profiler.cpp +++ b/Source/Core/Common/Profiler.cpp @@ -29,10 +29,8 @@ std::string Profiler::s_lazy_result; int Profiler::s_lazy_delay = 0; Profiler::Profiler(const std::string& name) - : m_name(name), m_usecs(0), m_usecs_min(UINT64_MAX), m_usecs_max(0), m_usecs_quad(0), - m_calls(0), m_depth(0) + : m_name(name), m_usecs(0), m_usecs_min(UINT64_MAX), m_usecs_max(0), m_usecs_quad(0), m_calls(0) { - m_time = Common::Timer::NowUs(); s_max_length = std::max<u32>(s_max_length, u32(m_name.length())); std::lock_guard<std::mutex> lk(s_mutex); @@ -97,22 +95,23 @@ std::string Profiler::ToString() return s_lazy_result; } -void Profiler::Start() +void Profiler::Start(u64* time, int* depth) { - if (!m_depth++) + if ((*depth)++ == 0) { - m_time = Common::Timer::NowUs(); + *time = Common::Timer::NowUs(); } } -void Profiler::Stop() +void Profiler::Stop(u64* time, int* depth) { - if (!--m_depth) + if (--(*depth) == 0) { u64 end = Common::Timer::NowUs(); - u64 diff = end - m_time; + u64 diff = end - *time; + std::lock_guard lk(m_mutex); m_usecs += diff; m_usecs_min = std::min(m_usecs_min, diff); m_usecs_max = std::max(m_usecs_max, diff); @@ -123,6 +122,8 @@ void Profiler::Stop() std::string Profiler::Read() { + std::lock_guard lk(m_mutex); + double avg = 0; double stdev = 0; double time_rel = 0; |
