Skip to content

Commit 2b63244

Browse files
committed
[profiler] export frame data using time interval
1 parent 6886353 commit 2b63244

4 files changed

Lines changed: 23 additions & 36 deletions

File tree

source/editor/Widgets/Profiler.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,11 @@ void Profiler::OnTickVisible()
146146
if (ImGui::Selectable("GPU", mode_hardware == 0))
147147
{
148148
mode_hardware = 0;
149-
spartan::CsvExporter::StopRecording(true);
150149
}
151150

152151
if (ImGui::Selectable("CPU", mode_hardware == 1))
153152
{
154153
mode_hardware = 1;
155-
spartan::CsvExporter::StopRecording(true);
156154
}
157155

158156
ImGui::EndCombo();
@@ -166,13 +164,11 @@ void Profiler::OnTickVisible()
166164
if (ImGui::Selectable("Alphabetically", mode_sort == 0))
167165
{
168166
mode_sort = 0;
169-
spartan::CsvExporter::StopRecording(true);
170167
}
171168

172169
if (ImGui::Selectable("By Duration", mode_sort == 1))
173170
{
174171
mode_sort = 1;
175-
spartan::CsvExporter::StopRecording(true);
176172
}
177173

178174
ImGui::EndCombo();
@@ -187,7 +183,7 @@ void Profiler::OnTickVisible()
187183
ImGui::SameLine();
188184
if (ImGui::Button("Start Recording"))
189185
{
190-
spartan::CsvExporter::StartRecording(mode_hardware);
186+
spartan::CsvExporter::StartRecording();
191187
}
192188
ImGui::SameLine();
193189
if (ImGui::Button("Stop Recording"))
@@ -228,11 +224,7 @@ void Profiler::OnTickVisible()
228224
continue;
229225

230226
show_time_block(time_blocks[i]);
231-
232-
// Csv recording
233-
spartan::CsvExporter::WriteFrameData(time_blocks[i], spartan::Renderer::GetFrameNumber());
234227
}
235-
spartan::CsvExporter::NextFrame();
236228

237229
// plot
238230
ImGui::Separator();

source/runtime/Profiling/CsvExporter.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2828

2929
//= NAMESPACES ===============
3030
using namespace std;
31+
using namespace filesystem;
3132
//============================
3233

3334
namespace spartan
@@ -36,14 +37,13 @@ namespace spartan
3637
{
3738
constexpr const char* file_path_name = "data/profiling/ProfilingReport.csv";
3839

39-
std::ofstream csv_export_file;
40-
filesystem::path file_path(file_path_name);
41-
int current_mode_hardware = 0;
42-
int current_csv_col = 0; // frames by columns
43-
int current_csv_row = 0; // frame data by row
40+
ofstream csv_export_file;
41+
path file_path(file_path_name);
42+
int current_csv_col = 0; // frames by columns
43+
int current_csv_row = 0; // frame data by row
4444
}
4545

46-
void CsvExporter::StartRecording(int mode_hardware)
46+
void CsvExporter::StartRecording()
4747
{
4848
if (csv_export_file.is_open())
4949
{
@@ -55,11 +55,10 @@ namespace spartan
5555
{
5656
if (file_path.has_parent_path())
5757
{
58-
filesystem::create_directories(file_path.parent_path());
58+
create_directories(file_path.parent_path());
5959
}
6060

61-
csv_export_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
62-
61+
csv_export_file.exceptions(ofstream::failbit | ofstream::badbit);
6362
csv_export_file.open(file_path, ios::out | ios::trunc);
6463

6564
if (current_csv_col == 0)
@@ -68,11 +67,10 @@ namespace spartan
6867
csv_export_file.flush();
6968
current_csv_col++;
7069
}
71-
current_mode_hardware = mode_hardware;
7270

73-
SP_LOG_INFO("Started recording %s data for CSV report: %s", current_mode_hardware == 0 ? "GPU" : "CPU", file_path.generic_string().c_str());
71+
SP_LOG_INFO("Started recording profiling data for CSV report: %s", file_path.generic_string().c_str());
7472
}
75-
catch (const filesystem::filesystem_error& e) // directory creation failures
73+
catch (const filesystem_error& e) // directory creation failures
7674
{
7775
SP_LOG_ERROR("Filesystem Error: %s", e.what());
7876
}
@@ -88,7 +86,8 @@ namespace spartan
8886
{
8987
if (current_csv_row == 0)
9088
{
91-
csv_export_file << current_time_block.GetName() << ",";
89+
const char* hardware_type = current_time_block.GetType() == TimeBlockType::Gpu ? "GPU" : "CPU";
90+
csv_export_file << hardware_type << "/" << current_time_block.GetName() << ",";
9291
return;
9392
}
9493
if (current_csv_col == 0)
@@ -103,7 +102,7 @@ namespace spartan
103102
}
104103
}
105104

106-
void CsvExporter::NextFrame()
105+
void CsvExporter::NextInterval()
107106
{
108107
if (csv_export_file.is_open())
109108
{
@@ -113,24 +112,17 @@ namespace spartan
113112
}
114113
}
115114

116-
void CsvExporter::StopRecording(bool has_data_changed)
115+
void CsvExporter::StopRecording()
117116
{
118117
if (csv_export_file.is_open())
119118
{
120119
csv_export_file.flush();
121120
csv_export_file.close();
122121
current_csv_col = 0;
123122
current_csv_row = 0;
124-
if (has_data_changed)
125-
{
126-
SP_LOG_WARNING("Stopped recording data for CSV report %s. Time block data were modified.", file_path.generic_string().c_str());
127-
}
128-
else
129-
{
130-
SP_LOG_INFO("Stopped recording %s data for CSV report: %s", current_mode_hardware == 0 ? "GPU" : "CPU", file_path.generic_string().c_str());
131-
}
123+
SP_LOG_INFO("Stopped recording profiling data for CSV report: %s", file_path.generic_string().c_str());
132124
}
133-
else if (!csv_export_file.is_open() && !has_data_changed)
125+
else if (!csv_export_file.is_open())
134126
{
135127
SP_LOG_WARNING("Invalid action. There is no active CSV recording.");
136128
}

source/runtime/Profiling/CsvExporter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace spartan
3030
class CsvExporter
3131
{
3232
public:
33-
static void StartRecording(int mode_hardware);
33+
static void StartRecording();
3434
static void WriteFrameData(const TimeBlock& current_time_block, uint64_t frame_number);
35-
static void NextFrame();
36-
static void StopRecording(bool has_data_changed = false);
35+
static void NextInterval();
36+
static void StopRecording();
3737
};
3838
}

source/runtime/Profiling/Profiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
//= INCLUDES =========================
2323
#include "pch.h"
2424
#include "Profiler.h"
25+
#include "CsvExporter.h"
2526
#include "../RHI/RHI_Device.h"
2627
#include "../RHI/RHI_Implementation.h"
2728
#include "../RHI/RHI_SwapChain.h"
@@ -233,7 +234,9 @@ namespace spartan
233234

234235
// copy
235236
m_time_blocks_read.push_back(time_block);
237+
CsvExporter::WriteFrameData(time_block, Renderer::GetFrameNumber());
236238
}
239+
CsvExporter::NextInterval();
237240

238241
// clear write array
239242
m_time_blocks_write.clear();

0 commit comments

Comments
 (0)