]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/profiler.cpp
Remove dependencies to MSP libraries to make compiling on embedded platforms easier
[gldbg.git] / flavors / gl / source / profiler.cpp
index 37caa68636745f85c0f6290e006fef426618370c..4b95208c4b0425424a2ca89d5973d096a4cce049 100644 (file)
@@ -1,18 +1,17 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2010-2011  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)),
@@ -44,12 +43,12 @@ void Profiler::cmd_profile(const string &args)
                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)
@@ -93,18 +92,25 @@ void Profiler::glXSwapBuffers(void *user_data, Display *, GLXDrawable)
 {
        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;
+}