source: trunk/src/profiler.cpp @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

  • 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://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdlib>
16#include <stdint.h>
17
18#include "core.h"
19
20namespace lol
21{
22
23/*
24 * Profiler implementation class
25 */
26
27static class ProfilerData
28{
29    friend class Profiler;
30
31    static int const HISTORY = 32;
32
33public:
34    ProfilerData()
35    {
36        for (int i = 0; i < HISTORY; i++)
37            history[i] = 0.0f;
38        avg = max = 0.0f;
39    }
40
41private:
42    float history[HISTORY];
43    Timer timer;
44    float avg, max;
45}
46data[Profiler::STAT_COUNT];
47
48/*
49 * Profiler public class
50 */
51
52void Profiler::Start(int id)
53{
54    data[id].timer.Get();
55}
56
57void Profiler::Stop(int id)
58{
59    float seconds = data[id].timer.Get();
60
61    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds;
62    data[id].avg = 0.0f;
63    data[id].max = 0.0f;
64
65    for (int i = 0; i < ProfilerData::HISTORY; i++)
66    {
67        data[id].avg += data[id].history[i];
68        if (data[id].history[i] > data[id].max)
69            data[id].max = data[id].history[i];
70    }
71    data[id].avg /= ProfilerData::HISTORY;
72}
73
74float Profiler::GetAvg(int id)
75{
76    return data[id].avg;
77}
78
79float Profiler::GetMax(int id)
80{
81    return data[id].max;
82}
83
84} /* namespace lol */
85
Note: See TracBrowser for help on using the repository browser.