source: trunk/src/profiler.cpp @ 150

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

Replace mouse scrolling with a joystick simulated by the e/s/d/f keys.

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