Browse Source

started perf counter

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
f4727d76e7
3 changed files with 53 additions and 0 deletions
  1. 47
    0
      libswan/include/swan/PerfCounter.h
  2. 1
    0
      libswan/src/PerfCounter.cc
  3. 5
    0
      libswan/test/PerfCounter.t.cc

+ 47
- 0
libswan/include/swan/PerfCounter.h View File

@@ -0,0 +1,47 @@
namespace Swan {



class PerfCounter {
public:
class Counter {
public:
void count(double secs) {
latest_ = secs;
if (count_ >= 60) {
sum_ -= avg();
sum_ += secs;
} else {
sum_ += secs;
count_ += 1;
}
}

double avg() { return sum_ / count_; }
double latest() { return latest_; }

private:
double latest_ = 0;
double sum_ = 0;
int count_ = 0;
};

void countFrameTime(double secs) { frame_time_.count(secs); }
void countGameUpdate(double secs) { game_update_.count(secs); }
void countGameTick(double secs) { game_tick_.count(secs); }
void countGameDraw(double secs) { game_draw_.count(secs); }
void countGameUpdatesPerFrame(double count) { game_updates_per_frame_.count(count); }
void countRenderPresent(double secs) { render_present_.count(secs); }
void countMemoryUsage(double bytes) { memory_usage_.count(bytes); }

private:
Counter frame_time_;
Counter game_update_;
Counter game_tick_;
Counter game_draw_;
Counter game_updates_per_frame_;
Counter render_present_;
Counter memory_usage_;
};

}

+ 1
- 0
libswan/src/PerfCounter.cc View File

@@ -0,0 +1 @@
#include "PerfCounter.h"

+ 5
- 0
libswan/test/PerfCounter.t.cc View File

@@ -0,0 +1,5 @@
#include "PerfCounter.h"

#include "lib/test.h"

test("")

Loading…
Cancel
Save