source: trunk/src/profiler.cpp @ 149

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

Get the timer to talk milliseconds instead of seconds.

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