cgv
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 
11 namespace cgv {
12  namespace render {
13 
16  PMB_MIN,
17  PMB_MAX,
18  PMB_CUR,
19  PMB_AVG
20 };
21 
22 struct CGV_API performance_measurement
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 
30 struct 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 
42 class CGV_API performance_monitor
43 {
44 public:
48  typedef std::vector<performance_measurement> frame_data;
49 private:
50  bool frame_finished;
51  unsigned frame_id;
52 protected:
53  bool enabled;
54  double fps_alpha;
55  double fps;
56  Rec placement;
57  int nr_display_cycles;
58  int bar_line_width;
59  Col plot_color;
60  std::string file_name;
61  std::vector<performance_task> tasks;
62  std::deque<frame_data> data;
63  std::vector<PerformanceMonitoringBar> bar_config;
64 
66  float time_scale;
67  std::vector<Pos> positions;
68  std::vector<Col> colors;
69 
70  void compute_colors(const frame_data& fdata);
71  void compute_positions(int x, int y, int dx, int dy, const frame_data& fdata);
72  frame_data& current_frame();
73  void add_measurement(const performance_measurement& pm);
74 
75 public:
80  void set_file_name(const std::string& _file_name);
83  const std::string& get_file_name() const { return file_name; }
85  void enable();
87  void disable();
89  bool is_enabled() const { return enabled; }
91 
94  void init_tasks();
97  int add_task(const std::string& name, const Col& col);
99  unsigned get_buffer_size() const { return placement.get_extent()(0); }
101  void start_frame();
103  unsigned get_frame_id() const { return frame_id; }
105  void start_task(int task_id);
107  void finish_task(int task_id);
109  void finish_frame();
111 
114  void clear_bar();
117  void add_bar_item(PerformanceMonitoringBar item);
119  void set_placement(const Rec& rectangle);
121  Rec get_placement() const { return placement; }
123  void set_nr_display_cycles(unsigned _nr_cycles);
125  unsigned get_nr_display_cycles() const { return nr_display_cycles; }
127 };
128 
129  }
130 }
131 
132 #include <cgv/config/lib_end.h>
cgv::render::performance_monitor::get_frame_id
unsigned get_frame_id() const
return the current frame id
Definition: performance_monitor.h:103
cgv::render::performance_monitor::get_nr_display_cycles
unsigned get_nr_display_cycles() const
return the number of display cycles to by drawn for the performance monitor
Definition: performance_monitor.h:125
cgv::math::fvec
Definition: fvec.h:18
cgv::utils::stopwatch
Definition: stopwatch.h:37
cgv::render::performance_monitor::is_enabled
bool is_enabled() const
return whether performance monitoring is enabled
Definition: performance_monitor.h:89
cgv::render::PerformanceMonitoringBar
PerformanceMonitoringBar
different items that can be shown in the long bar
Definition: performance_monitor.h:15
cgv::media::axis_aligned_box::get_extent
fvec_type get_extent() const
return a vector with the extents in the different dimensions
Definition: axis_aligned_box.h:80
cgv::render::performance_monitor::get_placement
Rec get_placement() const
return placement of performance monitor
Definition: performance_monitor.h:121
cgv::media::color< float >
cgv::media::axis_aligned_box< int, 2 >
cgv::render::performance_monitor
Definition: performance_monitor.h:43
cgv::render::performance_monitor::get_buffer_size
unsigned get_buffer_size() const
return the size of the buffer to store frame data
Definition: performance_monitor.h:99
cgv
the cgv namespace
Definition: vr_calib.cxx:9