From ddc359f006c47e2a503b616d27e22f5d29c13e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 25 Apr 2014 17:04:22 +0200 Subject: [PATCH] add more timers to headless test --- include/llmr/util/timer.hpp | 26 +++++++++++++++----------- src/renderer/painter.cpp | 3 +++ src/shader/shader.cpp | 3 +++ test/headless.cpp | 29 ++++++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/include/llmr/util/timer.hpp b/include/llmr/util/timer.hpp index 95a58e500..a1e8e05a9 100644 --- a/include/llmr/util/timer.hpp +++ b/include/llmr/util/timer.hpp @@ -1,28 +1,32 @@ #ifndef LLMR_UTIL_TIMER #define LLMR_UTIL_TIMER -#include #include -#include namespace llmr { namespace util { +#ifndef DISABLE_TIMER class timer { - using hr = std::chrono::high_resolution_clock; public: - explicit timer(const std::string &name) : name(name), start(hr::now()) {} - ~timer() { - using namespace std::chrono; - std::cerr << name << ": " - << (double)duration_cast(hr::now() - start).count() / 1000 - << "ms" << std::endl; - } + timer(); + timer(const std::string &name); + void report(const std::string &name); + ~timer(); private: const std::string name; - const hr::time_point start; + uint64_t start; }; +#else +class timer { + inline timer() {} + inline timer(const std::string &name) {} + inline void report (const std::string &name) {} + inline ~timer() {} +}; +#endif + } } diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index fc1cc481b..944a5083b 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace llmr; @@ -35,6 +36,8 @@ bool Painter::needsAnimation() const { } void Painter::setup() { + util::timer timer("painter setup"); + setupShaders(); assert(pointShader); diff --git a/src/shader/shader.cpp b/src/shader/shader.cpp index 5fe91e62f..97e494f65 100644 --- a/src/shader/shader.cpp +++ b/src/shader/shader.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -10,6 +11,8 @@ using namespace llmr; Shader::Shader(const GLchar *vertSource, const GLchar *fragSource) : valid(false), program(0) { + util::timer timer("shader compilation"); + GLuint vertShader; if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { diff --git a/test/headless.cpp b/test/headless.cpp index 86f112c2a..0da898245 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -23,6 +24,7 @@ TEST(Headless, initialize) { llmr::Map map(settings); + llmr::util::timer timer; // Setup OpenGL CGLContextObj gl_context; @@ -57,6 +59,8 @@ TEST(Headless, initialize) { return; } + timer.report("gl setup"); + int width = 1024; int height = 768; @@ -84,7 +88,6 @@ TEST(Headless, initialize) { GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "Couldn't create framebuffer: "); switch (status) { @@ -97,26 +100,48 @@ TEST(Headless, initialize) { return; } + timer.report("gl framebuffer"); map.setup(); + + timer.report("map setup"); + map.resize(width, height); + + timer.report("map resize"); + map.loadSettings(); + timer.report("map settings"); + map.update(); + timer.report("map update"); + // Run the loop. It will terminate when we don't have any further listeners. map.run(); + timer.report("map loop"); + map.render(); + timer.report("map render"); uint32_t *pixels = new uint32_t[width * height]; glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + timer.report("gl readpixels"); + std::string result = llmr::util::compress_png(width, height, pixels, true); + + timer.report("compress png"); + llmr::util::write_file("out.png", result); + timer.report("save file"); + + delete[] pixels; glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -125,4 +150,6 @@ TEST(Headless, initialize) { glDeleteRenderbuffersEXT(1, &fbo_depth_stencil); CGLDestroyContext(gl_context); + + timer.report("destruct"); }