|
From: Lasse Kärkkäi. <tr...@us...> - 2009-07-18 12:05:21
|
Module: performous
Branch: master
Commit: 0eaa864cb73e57b2b9f5e3887c8b7524f7170b28
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Jul 18 15:02:45 2009 +0300
Add profiling class that can be used for performance measurements.
Usage:
Profiler prof("render"); // Description of what is profiled
foo();
prof("foo");
glStuff();
glFlush(); prof("gl"); // Remember to flush before measuring GL stuff
// When prof goes out of scope, it prints the results to std::cout
---
game/profiler.hh | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/game/profiler.hh b/game/profiler.hh
new file mode 100644
index 0000000..256a2fc
--- /dev/null
+++ b/game/profiler.hh
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "xtime.hh"
+#include <iostream>
+#include <sstream>
+#include <string>
+
+class Profiler {
+ std::ostringstream m_oss;
+ boost::xtime m_time;
+ public:
+ Profiler(std::string const& name): m_time(now()) { m_oss << name << ": "; }
+ ~Profiler() { std::clog << m_oss.str() << std::endl; }
+ void operator()(std::string const& tag) {
+ boost::xtime n = now();
+ std::swap(n, m_time);
+ m_oss << unsigned((m_time - n) * 1000.0 + 0.5) << " ms (" << tag << ") ";
+ }
+};
+
+
|