1#include "performance_monitor.h"
2#include <cgv/utils/file.h>
9performance_monitor::frame_data& performance_monitor::current_frame()
14void performance_monitor::add_measurement(
const performance_measurement& pm)
16 current_frame().push_back(pm);
25 frame_finished =
true;
28 nr_display_cycles = 2;
32 bar_config.push_back(PMB_MAX);
33 bar_config.push_back(PMB_CUR);
34 bar_config.push_back(PMB_MIN);
49void performance_monitor::set_file_name(
const std::string& _file_name)
51 file_name = _file_name;
65 add_task(
"transparent_surfaces",
rgb(0.9f, 0.7f, 0.5f));
78 bar_config.push_back(item);
84 placement = rectangle;
90 nr_display_cycles = _nr_cycles;
98 return (
int)tasks.size() - 1;
110 data.push_back(frame_data());
114 frame_finished =
false;
139 const char* start_or_finish[] = {
"start",
"finish" };
142 double new_fps = 1.0 / (data.back().back().time - data.back().front().time);
146 fps = fps_alpha * new_fps + (1.0 - fps_alpha)*fps;
147 frame_finished =
true;
148 if (file_name.empty())
150 bool need_header = cgv::utils::file::exists(file_name);
151 FILE* fp = fopen(file_name.c_str(),
"wa");
156 const frame_data& cf = current_frame();
157 for (i=0; i<(int)cf.size(); ++i) {
159 fprintf(fp, i==0?
"%s %s":
",%s %s", start_or_finish[pm.start ? 0 : 1], tasks[pm.task_id].name.c_str());
163 fprintf(fp,
"%d", frame_id);
164 for (i=0; i<(int)current_frame().size(); ++i)
165 fprintf(fp,
", %f", current_frame()[i].time);
170void performance_monitor::compute_colors(
const frame_data& fdata)
172 colors.resize(2*fdata.size()-2);
173 std::stack<int> task_stack;
175 for (
unsigned t=0; t<fdata.size()-1; ++t) {
176 int task_id = fdata[t].task_id;
177 if (fdata[t].start) {
178 colors[2*t+1] = colors[2*t] = tasks[task_id].col;
179 task_stack.push(task_id);
183 colors[2*t+1] = colors[2*t] = tasks[task_stack.top()].col;
188void performance_monitor::compute_positions(
int x0,
int y0,
int dx,
int dy,
const frame_data& fdata)
190 positions.resize(2*fdata.size()-2);
191 double scale_x = time_scale*dx;
192 double scale_y = time_scale*dy;
194 for (
unsigned t=0; t < fdata.size()-1; ++t) {
195 positions[2*t].set(x,y);
196 x = x0 + (int)(fdata[t+1].time*scale_x+0.5);
197 y = y0 + (int)(fdata[t+1].time*scale_y+0.5);
198 positions[2*t+1].set(x,y);
void set(const T &x, const T &y)
set the first two components
double get_elapsed_time() const
return time elpased thus far
double restart()
restart timer and return time elapsed until restart
PerformanceMonitoringBar
different items that can be shown in the long bar
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components