X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=flavors%2Fgl%2Fsource%2Fprofiler.cpp;h=94496023ecf1f52178fa655f92a7b9a45774cf8e;hb=a34325fadec5b2be003bf9af1f081bfc4c83e8b6;hp=37caa68636745f85c0f6290e006fef426618370c;hpb=f53057ce9b5eb3c7256a4aca95b4944733e14503;p=gldbg.git diff --git a/flavors/gl/source/profiler.cpp b/flavors/gl/source/profiler.cpp index 37caa68..9449602 100644 --- a/flavors/gl/source/profiler.cpp +++ b/flavors/gl/source/profiler.cpp @@ -1,18 +1,10 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - -#include -#include -#include +#include +#include +#include #include "gldbg.h" #include "profiler.h" using namespace std; -using namespace Msp; Profiler::Profiler(GlDbg &dbg): decoder(gldecoder_new(this, 0)), @@ -29,6 +21,11 @@ Profiler::Profiler(GlDbg &dbg): decoder->glXSwapBuffers = glXSwapBuffers; } +Profiler::~Profiler() +{ + gldecoder_delete(decoder); +} + void Profiler::decode(const char *data, unsigned len) { if(enabled) @@ -44,12 +41,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 +90,25 @@ void Profiler::glXSwapBuffers(void *user_data, Display *, GLXDrawable) { Profiler *self = reinterpret_cast(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; +}