source: trunk/src/profiler.cpp @ 221

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

Complete Lol Engine / Deus Hax / Monsterz split.

  • 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
21/*
22 * Profiler implementation class
23 */
24
25static class ProfilerData
26{
27    friend class Profiler;
28
29    static int const HISTORY = 32;
30
31public:
32    ProfilerData()
33    {
34        for (int i = 0; i < HISTORY; i++)
35            history[i] = 0.0f;
36        avg = max = 0.0f;
37    }
38
39private:
40    float history[HISTORY];
41    Timer timer;
42    float avg, max;
43}
44data[Profiler::STAT_COUNT];
45
46/*
47 * Profiler public class
48 */
49
50void Profiler::Start(int id)
51{
52    data[id].timer.GetMs();
53}
54
55void Profiler::Stop(int id)
56{
57    float deltams = data[id].timer.GetMs();
58
59    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
60    data[id].avg = 0.0f;
61    data[id].max = 0.0f;
62
63    for (int i = 0; i < ProfilerData::HISTORY; i++)
64    {
65        data[id].avg += data[id].history[i];
66        if (data[id].history[i] > data[id].max)
67            data[id].max = data[id].history[i];
68    }
69    data[id].avg /= ProfilerData::HISTORY;
70}
71
72float Profiler::GetAvg(int id)
73{
74    return data[id].avg;
75}
76
77float Profiler::GetMax(int id)
78{
79    return data[id].max;
80}
81
Note: See TracBrowser for help on using the repository browser.