source: trunk/src/profiler.cpp @ 2370

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