瀏覽代碼

profiler: fix a crash on exit.

legacy
Sam Hocevar 5 年之前
父節點
當前提交
baa6f0186c
共有 1 個檔案被更改,包括 17 行新增22 行删除
  1. +17
    -22
      src/profiler.cpp

+ 17
- 22
src/profiler.cpp 查看文件

@@ -20,24 +20,31 @@ namespace lol
* Profiler implementation class * Profiler implementation class
*/ */


static class ProfilerData
static class profiler_data
{ {
friend class Profiler; friend class Profiler;


static int const HISTORY = 32;

public:
ProfilerData()
void update()
{ {
for (int i = 0; i < HISTORY; i++)
history[i] = 0.0f;
history[frame++ % HISTORY] = m_timer.get();
avg = max = 0.0f; avg = max = 0.0f;

for (int i = 0; i < HISTORY; i++)
{
avg += history[i];
if (history[i] > max)
max = history[i];
}
avg /= HISTORY;
} }


static int const HISTORY = 32;

private: private:
float history[HISTORY];
float history[HISTORY] = { 0.0f };
int frame = 0;
timer m_timer; timer m_timer;
float avg, max;
float avg = 0.0f, max = 0.0f;
} }
data[Profiler::STAT_COUNT]; data[Profiler::STAT_COUNT];


@@ -52,19 +59,7 @@ void Profiler::Start(int id)


void Profiler::Stop(int id) void Profiler::Stop(int id)
{ {
float seconds = data[id].m_timer.get();

data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds;
data[id].avg = 0.0f;
data[id].max = 0.0f;

for (int i = 0; i < ProfilerData::HISTORY; i++)
{
data[id].avg += data[id].history[i];
if (data[id].history[i] > data[id].max)
data[id].max = data[id].history[i];
}
data[id].avg /= ProfilerData::HISTORY;
data[id].update();
} }


float Profiler::GetAvg(int id) float Profiler::GetAvg(int id)


Loading…
取消
儲存