Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
performance_profiler.h
1 #pragma once
2 
3 #include "core/debug/debug_window.h"
4 #include "util/string.h"
5 #include "util/map.h"
6 #include "util/ring_buffer.h"
7 #include "util/utility.h"
8 #include "util/vector.h"
9 #include "renderer/imgui/imgui.h"
10 
11 #define BLOWBOX_PROFILER_HISTORY_MAX_SAMPLE_COUNT 2000
12 #define BLOWBOX_PROFILER_HISTORY_MIN_SAMPLE_COUNT 2
13 
14 namespace blowbox
15 {
16  class GpuResource;
17 
20  {
21  ProfilerBlockType_GAME,
22  ProfilerBlockType_CORE,
23  ProfilerBlockType_RENDERER,
24  ProfilerBlockType_CONTENT,
25  ProfilerBlockType_MISC,
26  ProfilerBlockType_COUNT
27  };
28 
38  {
39  public:
53  {
54  friend class PerformanceProfiler;
56  public:
57  ProfilerBlock();
58 
64  ProfilerBlock(const String& block_name, const ProfilerBlockType& block_type = ProfilerBlockType_MISC);
65 
68 
70  void Restart();
71 
73  void Finish();
74  private:
77  double start_time_;
78  double end_time_;
79  bool finished_;
80  };
81 
91  {
92  double total_time;
95  };
96 
99 
101  void RenderMenu() override;
102 
104  void RenderWindow() override;
105 
107  void NewFrame();
108 
110  void CatchNextFrame();
111 
112  protected:
115  {
116  double start_time;
117  double end_time;
118  };
119 
124  {
132  };
133 
138  void AddProfilerBlock(ProfilerBlock& profiler_block);
139 
145 
146  private:
150 
151  private:
153 
159 
161  float contiguous_block_times[BLOWBOX_PROFILER_HISTORY_MAX_SAMPLE_COUNT];
162 
163  ImGuiTextFilter profiler_block_filters_[ProfilerBlockType_COUNT];
164 
165  protected:
166 
169  {
176  {
177  return (a.total_time > b.total_time);
178  }
179  };
180  };
181 }
Allows you to profile a block of code.
Definition: performance_profiler.h:52
Map< String, ProfilerBlockData > profiler_blocks_[ProfilerBlockType_COUNT]
This is an array of maps that&#39;s used to categorize all the different PerformanceProfiler::ProfilerBlo...
Definition: performance_profiler.h:160
double worst_block_time
The worst block time (i.e. the one block time that was slowest at getting executed) that is currently...
Definition: performance_profiler.h:130
Vector< ProfilerBlock > collected_profiler_blocks_single_frame_
All PerformanceProfiler::ProfilerBlocks that are collected when catch_frame_ is on, are stored in this array.
Definition: performance_profiler.h:156
eastl::vector< T > Vector
Typedef for wrapping the EASTL vector.
Definition: vector.h:14
Base class for DebugWindows.
Definition: debug_window.h:8
DO NOT USE! This struct is meant for internal use by the Profiler.
Definition: performance_profiler.h:90
The main profiler in Blowbox.
Definition: performance_profiler.h:37
String block_name_
The name of this ProfilerBlock.
Definition: performance_profiler.h:75
double last_recalculation
The last time when the values in this block data got recalculated (average & bounds).
Definition: performance_profiler.h:127
void RenderMenu() override
Renders the menu for the Profiler.
Definition: performance_profiler.cc:38
String ConvertBlockTypeToString(ProfilerBlockType type)
Converts a ProfilerBlockType to a String.
Definition: performance_profiler.cc:314
bool show_window_
Whether the profiler window should be shown.
Definition: performance_profiler.h:152
int history_sample_count_
The number of samples that should be kept as history for all history buffers.
Definition: performance_profiler.h:149
double start_time
The time at which the ProfilerBlock spawned.
Definition: performance_profiler.h:116
eastl::map< Key, T > Map
Typedef for wrapping the EASTL map.
Definition: map.h:14
bool catch_frame_
Whether all ProfilerBlocks in the current frames are being caught for frame analysis.
Definition: performance_profiler.h:154
double total_time
The total amount of time that has been spent for this ProfilerBlock in this frame.
Definition: performance_profiler.h:92
RingBuffer< ProfilerBlockTime > block_times
A ring buffer containing all block times for this type of PerformanceProfiler::ProfilerBlockData.
Definition: performance_profiler.h:125
void Finish()
Finishes the ProfilerBlock. This means that the block will expire and report itself to the main Profi...
Definition: performance_profiler.cc:371
double best_block_time_overall
The best block time (i.e. the one block time that was quickest at getting executed) over the entire l...
Definition: performance_profiler.h:129
Compares single frame ProfilerBlocks.
Definition: performance_profiler.h:168
float contiguous_block_times[BLOWBOX_PROFILER_HISTORY_MAX_SAMPLE_COUNT]
An array that gets re-used for every type of block time that needs to be stored contiguously (require...
Definition: performance_profiler.h:161
eastl::ring_buffer< T > RingBuffer
Typedef for wrapping the EASTL ring_buffer.
Definition: ring_buffer.h:14
float last_bounds_reset_time_
The last time that bounds got reset in the profiler.
Definition: performance_profiler.h:147
eastl::string String
Typedef for wrapping the EASTL string.
Definition: string.h:13
ImGuiTextFilter profiler_block_filters_[ProfilerBlockType_COUNT]
An array of text filters for filtering out profiler blocks from the individual ProfilerBlock views...
Definition: performance_profiler.h:163
float bounds_reset_interval_
The interval at which bounds should be reset.
Definition: performance_profiler.h:148
Stores expanded data for PerformanceProfiler::ProfilerBlocks, over the lifetime of the entire applica...
Definition: performance_profiler.h:123
String block_name
The name of the block.
Definition: performance_profiler.h:93
double worst_block_time_overall
The worst block time (i.e. the one block time that was slowest at getting executed) over the entire l...
Definition: performance_profiler.h:131
The main Blowbox namespace.
Definition: image.cc:8
ProfilerBlockType block_type_
The type of this ProfilerBlock.
Definition: performance_profiler.h:76
~ProfilerBlock()
Destructs the ProfilerBlock. It automatically calls ProfilerBlock::Finish() for you.
Definition: performance_profiler.cc:357
double best_block_time
The best block time (i.e. the one block time that was quickest at getting executed) that is currently...
Definition: performance_profiler.h:128
void CatchNextFrame()
Makes the profiler collect the next frame&#39;s data.
Definition: performance_profiler.cc:279
Vector< ProfilerBlockFrameData > profiler_blocks_single_frame_
An array of ProfilerBlockFrameData&#39;s that spans an entire frame.
Definition: performance_profiler.h:158
void AddProfilerBlock(ProfilerBlock &profiler_block)
Adds a PerformanceProfiler::ProfilerBlock to the profiler. The profiler will automatically figure out...
Definition: performance_profiler.cc:288
double start_time_
The time at which this ProfilerBlock spawned.
Definition: performance_profiler.h:77
bool catch_next_frame_
Whether the next frame should be made ready for data collection.
Definition: performance_profiler.h:155
This is a lightweight version of the PerformanceProfiler::ProfilerBlock. It only stores the block tim...
Definition: performance_profiler.h:114
void RenderWindow() override
Renders the actual window for the Profiler.
Definition: performance_profiler.cc:69
double average_block_time
The average block time for this block data.
Definition: performance_profiler.h:126
bool finished_
Whether the block has been finished already.
Definition: performance_profiler.h:79
ProfilerBlockType block_type
The type of the block.
Definition: performance_profiler.h:94
void NewFrame()
Starts a new profiling frame.
Definition: performance_profiler.cc:230
double end_time_
The time at which this ProfilerBlock finished.
Definition: performance_profiler.h:78
Map< String, ProfilerBlockFrameData > condensed_profiler_block_times_
This map helps in removing duplicates from the collected_profiler_blocks_single_frame_ array...
Definition: performance_profiler.h:157
ProfilerBlockType
Identifies a type of profiling block.
Definition: performance_profiler.h:19
double end_time
The time at which the ProfilerBlock finished.
Definition: performance_profiler.h:117
void Restart()
This invalidates the ProfilerBlock.
Definition: performance_profiler.cc:363