source: trunk/src/profiler.cpp @ 167

Last change on this file since 167 was 167, checked in by sam, 10 years ago

Store the frame number in the Ticker instead of duplicating the information
in each class that uses it.

  • Property svn:keywords set to Id
File size: 1.2 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdlib>
11#include <cstdio>
12#include <stdint.h>
13
14#include "core.h"
15
16/*
17 * Profiler implementation class
18 */
19
20static class ProfilerData
21{
22    friend class Profiler;
23
24    static int const HISTORY = 32;
25
26public:
27    ProfilerData()
28    {
29        for (int i = 0; i < HISTORY; i++)
30            history[i] = 0.0f;
31        avg = max = 0.0f;
32    }
33
34private:
35    float history[HISTORY];
36    Timer timer;
37    float avg, max;
38}
39data[Profiler::STAT_COUNT];
40
41/*
42 * Profiler public class
43 */
44
45void Profiler::Start(int id)
46{
47    data[id].timer.GetMs();
48}
49
50void Profiler::Stop(int id)
51{
52    float deltams = data[id].timer.GetMs();
53
54    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
55    data[id].avg = 0.0f;
56    data[id].max = 0.0f;
57
58    for (int i = 0; i < ProfilerData::HISTORY; i++)
59    {
60        data[id].avg += data[id].history[i];
61        if (data[id].history[i] > data[id].max)
62            data[id].max = data[id].history[i];
63    }
64    data[id].avg /= ProfilerData::HISTORY;
65}
66
67float Profiler::GetAvg(int id)
68{
69    return data[id].avg;
70}
71
72float Profiler::GetMax(int id)
73{
74    return data[id].max;
75}
76
Note: See TracBrowser for help on using the repository browser.