cgv
Loading...
Searching...
No Matches
performance_monitor.h
1#pragma once
2
3#include <deque>
4#include <vector>
5#include <cgv/utils/stopwatch.h>
6#include <cgv/media/axis_aligned_box.h>
7#include <cgv/media/color.h>
8
9#include "lib_begin.h"
10
11namespace cgv {
12 namespace render {
13
16 PMB_MIN,
17 PMB_MAX,
18 PMB_CUR,
19 PMB_AVG
20};
21
23{
24 double time;
25 int task_id;
26 bool start;
27 performance_measurement(double _time, int _task_id, bool _start) : time(_time), task_id(_task_id), start(_start) {}
28};
29
30struct CGV_API performance_task
31{
32 std::string name;
34 performance_task(std::string _name, cgv::media::color<float> _col) : name(_name), col(_col) {}
35};
36
43{
44public:
45 typedef std::vector<performance_measurement> frame_data;
46private:
47 bool frame_finished;
48 unsigned frame_id;
49protected:
50 bool enabled;
51 double fps_alpha;
52 double fps;
53 ibox2 placement;
54 int nr_display_cycles;
55 int bar_line_width;
56 rgb plot_color;
57 std::string file_name;
58 std::vector<performance_task> tasks;
59 std::deque<frame_data> data;
60 std::vector<PerformanceMonitoringBar> bar_config;
61
63 float time_scale;
64 std::vector<ivec2> positions;
65 std::vector<rgb> colors;
66
67 void compute_colors(const frame_data& fdata);
68 void compute_positions(int x, int y, int dx, int dy, const frame_data& fdata);
69 frame_data& current_frame();
70 void add_measurement(const performance_measurement& pm);
71
72public:
78 void set_file_name(const std::string& _file_name);
80 const std::string& get_file_name() const { return file_name; }
82 void enable();
84 void disable();
86 bool is_enabled() const { return enabled; }
88
92 void init_tasks();
94 int add_task(const std::string& name, const rgb& col);
96 unsigned get_buffer_size() const { return placement.get_extent()(0); }
98 void start_frame();
100 unsigned get_frame_id() const { return frame_id; }
102 void start_task(int task_id);
104 void finish_task(int task_id);
106 void finish_frame();
108
112 void clear_bar();
114 void add_bar_item(PerformanceMonitoringBar item);
116 void set_placement(const ibox2& rectangle);
118 ibox2 get_placement() const { return placement; }
120 void set_nr_display_cycles(unsigned _nr_cycles);
122 unsigned get_nr_display_cycles() const { return nr_display_cycles; }
124};
125
126 }
127}
128
129#include <cgv/config/lib_end.h>
fvec_type get_extent() const
return a vector with the extents in the different dimensions
represent a color with components of given type and color and alpha model as specified.
Definition color.h:574
This class allows to monitor the performance of a set of tasks that are repeatedly executed over time...
unsigned get_nr_display_cycles() const
return the number of display cycles to by drawn for the performance monitor
ibox2 get_placement() const
return placement of performance monitor
bool is_enabled() const
return whether performance monitoring is enabled
unsigned get_buffer_size() const
return the size of the buffer to store frame data
unsigned get_frame_id() const
return the current frame id
A trivial stop watch class for time measurement.
Definition stopwatch.h:35
PerformanceMonitoringBar
different items that can be shown in the long bar
the cgv namespace
Definition print.h:11