dolphin-emulator/Source/Core/Common/Profiler.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.6 KiB
C
Raw Normal View History

2014-11-19 19:57:12 +01:00
// Copyright 2014 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2014-11-19 19:57:12 +01:00
#pragma once
#include <list>
2015-08-20 11:41:49 +02:00
#include <mutex>
2014-11-19 19:57:12 +01:00
#include <string>
#include "CommonTypes.h"
2015-08-20 11:41:49 +02:00
namespace Common
{
2014-11-19 19:57:12 +01:00
class Profiler
{
public:
Profiler(const std::string& name);
~Profiler();
static std::string ToString();
2025-03-29 15:00:33 +01:00
void Start(u64* time, int* depth);
void Stop(u64* time, int* depth);
2014-11-19 19:57:12 +01:00
std::string Read();
2015-08-20 11:41:49 +02:00
bool operator<(const Profiler& b) const;
2014-11-19 19:57:12 +01:00
private:
static std::list<Profiler*> s_all_profilers;
2015-08-20 11:41:49 +02:00
static std::mutex s_mutex;
2014-11-19 19:57:12 +01:00
static u32 s_max_length;
static u64 s_frame_time;
static u64 s_usecs_frame;
2014-11-19 19:57:12 +01:00
static std::string s_lazy_result;
static int s_lazy_delay;
2025-03-29 15:00:33 +01:00
std::mutex m_mutex;
2014-11-19 19:57:12 +01:00
std::string m_name;
u64 m_usecs;
u64 m_usecs_min;
u64 m_usecs_max;
u64 m_usecs_quad;
u64 m_calls;
};
class ProfilerExecuter
{
public:
2025-03-29 15:00:33 +01:00
ProfilerExecuter(Profiler* profiler, u64* time, int* depth)
: m_profiler(profiler), m_time(time), m_depth(depth)
{
m_profiler->Start(m_time, m_depth);
}
~ProfilerExecuter() { m_profiler->Stop(m_time, m_depth); }
2018-04-12 14:18:04 +02:00
2014-11-19 19:57:12 +01:00
private:
2025-03-29 15:00:33 +01:00
Profiler* m_profiler;
u64* m_time;
int* m_depth;
2014-11-19 19:57:12 +01:00
};
2024-08-18 15:08:44 +02:00
} // namespace Common
2015-08-20 11:41:49 +02:00
#define PROFILE(name) \
static Common::Profiler prof_gen(name); \
2025-03-29 15:00:33 +01:00
static thread_local u64 prof_time; \
static thread_local int prof_depth; \
Common::ProfilerExecuter prof_e(&prof_gen, &prof_time, &prof_depth);