-/* $Id$
-
-This file is part of gldbg
-Copyright © 2010 Mikko Rasa, Mikkosoft Productions
-Distributed under the GPL
-*/
-
-#include <msp/io/print.h>
-#include <msp/time/units.h>
-#include <msp/time/utils.h>
+#include <stdexcept>
+#include <cstdio>
+#include <ctime>
#include "gldbg.h"
#include "profiler.h"
using namespace std;
-using namespace Msp;
Profiler::Profiler(GlDbg &dbg):
decoder(gldecoder_new(this, 0)),
decoder->glXSwapBuffers = glXSwapBuffers;
}
+Profiler::~Profiler()
+{
+ gldecoder_delete(decoder);
+}
+
void Profiler::decode(const char *data, unsigned len)
{
if(enabled)
draw_calls = 0;
vertices = 0;
triangles = 0;
- start = Msp::Time::now();
+ start = get_time();
}
else if(args=="off")
enabled = false;
else
- throw InvalidParameterValue("Invalid argument");
+ throw runtime_error("Invalid argument");
}
void Profiler::glDrawArrays(void *user_data, GLenum mode, int, int count)
{
Profiler *self = reinterpret_cast<Profiler *>(user_data);
- IO::print("%d draw calls, %d vertices, %d triangles\n", self->draw_calls, self->vertices, self->triangles);
+ printf("%d draw calls, %d vertices, %d triangles\n", self->draw_calls, self->vertices, self->triangles);
self->draw_calls = 0;
self->vertices = 0;
self->triangles = 0;
++self->frames;
- Msp::Time::TimeStamp t = Msp::Time::now();
- Msp::Time::TimeDelta dt = t-self->start;
- if(dt>Msp::Time::sec)
+ Time t = get_time();
+ float dt = (t-self->start)/1e6;
+ if(dt>1)
{
- Msp::IO::print("%d frames in %s seconds\n", self->frames, dt);
+ printf("%d frames in %.2f seconds\n", self->frames, dt);
self->start = t;
self->frames = 0;
}
}
+
+Profiler::Time Profiler::get_time()
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ return ts.tv_sec*1000000+ts.tv_nsec/1000;
+}