add more timers to headless test
This commit is contained in:
@@ -1,28 +1,32 @@
|
||||
#ifndef LLMR_UTIL_TIMER
|
||||
#define LLMR_UTIL_TIMER
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
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<microseconds>(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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <llmr/style/sprite.hpp>
|
||||
#include <llmr/util/raster.hpp>
|
||||
#include <llmr/util/string.hpp>
|
||||
#include <llmr/util/timer.hpp>
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
@@ -35,6 +36,8 @@ bool Painter::needsAnimation() const {
|
||||
}
|
||||
|
||||
void Painter::setup() {
|
||||
util::timer timer("painter setup");
|
||||
|
||||
setupShaders();
|
||||
|
||||
assert(pointShader);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <llmr/shader/shader.hpp>
|
||||
#include <llmr/platform/gl.hpp>
|
||||
#include <llmr/util/timer.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
@@ -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)) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <llmr/llmr.hpp>
|
||||
#include <llmr/util/image.hpp>
|
||||
#include <llmr/util/io.hpp>
|
||||
#include <llmr/util/timer.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user