source: trunk/src/profiler.cpp @ 686

Last change on this file since 686 was 686, checked in by sam, 9 years ago

Put everything in the "lol" namespace. Better late than never.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdlib>
16#include <cstdio>
17#include <stdint.h>
18
19#include "core.h"
20
21namespace lol
22{
23
24/*
25 * Profiler implementation class
26 */
27
28static class ProfilerData
29{
30    friend class Profiler;
31
32    static int const HISTORY = 32;
33
34public:
35    ProfilerData()
36    {
37        for (int i = 0; i < HISTORY; i++)
38            history[i] = 0.0f;
39        avg = max = 0.0f;
40    }
41
42private:
43    float history[HISTORY];
44    Timer timer;
45    float avg, max;
46}
47data[Profiler::STAT_COUNT];
48
49/*
50 * Profiler public class
51 */
52
53void Profiler::Start(int id)
54{
55    data[id].timer.GetMs();
56}
57
58void Profiler::Stop(int id)
59{
60    float deltams = data[id].timer.GetMs();
61
62    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
63    data[id].avg = 0.0f;
64    data[id].max = 0.0f;
65
66    for (int i = 0; i < ProfilerData::HISTORY; i++)
67    {
68        data[id].avg += data[id].history[i];
69        if (data[id].history[i] > data[id].max)
70            data[id].max = data[id].history[i];
71    }
72    data[id].avg /= ProfilerData::HISTORY;
73}
74
75float Profiler::GetAvg(int id)
76{
77    return data[id].avg;
78}
79
80float Profiler::GetMax(int id)
81{
82    return data[id].max;
83}
84
85} /* namespace lol */
86
Note: See TracBrowser for help on using the repository browser.