Skip to content

Commit 0a8d396

Browse files
committed
Remove temporary artifacts from previous GFXR replays so that data shown in UI is consistent
1 parent 32538f4 commit 0a8d396

File tree

5 files changed

+100
-38
lines changed

5 files changed

+100
-38
lines changed

ui/analyze_window.cpp

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ AnalyzeDialog::AnalyzeDialog(QWidget *parent)
142142
m_frame_count_layout->addWidget(m_frame_count_label);
143143
m_frame_count_layout->addWidget(m_frame_count_box);
144144

145+
// Replay Warning
146+
m_replay_warning_layout = new QHBoxLayout();
147+
m_replay_warning_label = new QLabel(tr("WARNING: Initiating replay will clear any temporary "
148+
"artifacts produced by previous replays. Please save "
149+
"them manually in a different folder before proceeding, "
150+
"if those artifacts are desired."));
151+
m_replay_warning_label->setWordWrap(true);
152+
m_replay_warning_layout->addWidget(m_replay_warning_label);
153+
145154
// Left Panel Layout
146155
m_left_panel_layout = new QVBoxLayout();
147156
m_left_panel_layout->addWidget(m_settings_list_label);
@@ -158,6 +167,7 @@ AnalyzeDialog::AnalyzeDialog(QWidget *parent)
158167
m_right_panel_layout->addLayout(m_dump_pm4_layout);
159168
m_right_panel_layout->addLayout(m_gpu_time_layout);
160169
m_right_panel_layout->addLayout(m_frame_count_layout);
170+
m_right_panel_layout->addLayout(m_replay_warning_layout);
161171
m_right_panel_layout->addLayout(m_button_layout);
162172

163173
// Main Layout
@@ -550,34 +560,17 @@ void AnalyzeDialog::SetReplayButton(const std::string &message, bool is_enabled)
550560
QApplication::processEvents();
551561
}
552562

553-
void AnalyzeDialog::UpdatePerfTabView(const std::string remote_file_name)
554-
{
555-
QString directory = m_capture_file_directory.value().c_str();
556-
557-
// Get the original filename from the remote path
558-
QFileInfo original_file_info(QString::fromStdString(remote_file_name));
559-
QString file_name = original_file_info.completeBaseName() + Dive::kProfilingMetricsCsvSuffix;
560-
561-
// Construct the new full path.
562-
QString full_path = QDir(directory).filePath(file_name);
563-
std::string output_path = full_path.toStdString();
564-
565-
emit OnDisplayPerfCounterResults(output_path.c_str());
566-
}
567-
568-
void AnalyzeDialog::UpdateGpuTimingTabView(const std::string remote_file_name)
563+
std::filesystem::path AnalyzeDialog::GetFullLocalPath(const std::string &gfxr_stem,
564+
const std::string &suffix) const
569565
{
570-
QString directory = m_capture_file_directory.value().c_str();
571-
572-
// Get the original filename from the original remote path
573-
QFileInfo original_file_info(QString::fromStdString(remote_file_name));
574-
QString file_name = original_file_info.completeBaseName() + Dive::kGpuTimingCsvSuffix;
575-
576-
// Construct the new full path.
577-
QString full_path = QDir(directory).filePath(file_name);
578-
std::string output_path = full_path.toStdString();
566+
if (!m_local_capture_file_directory.ok())
567+
{
568+
return "";
569+
}
579570

580-
emit OnDisplayGpuTimingResults(output_path.c_str());
571+
std::filesystem::path full_path = m_local_capture_file_directory.value();
572+
full_path /= (gfxr_stem + suffix);
573+
return full_path;
581574
}
582575

583576
//--------------------------------------------------------------------------------------------------
@@ -599,7 +592,7 @@ absl::Status AnalyzeDialog::Pm4Replay(Dive::DeviceManager &device_manager,
599592
return device_manager.RunReplayApk(remote_gfxr_file,
600593
replay_args,
601594
m_dump_pm4_enabled,
602-
m_capture_file_directory.value());
595+
m_local_capture_file_directory.value());
603596
}
604597

605598
//--------------------------------------------------------------------------------------------------
@@ -610,7 +603,7 @@ absl::Status AnalyzeDialog::PerfCounterReplay(Dive::DeviceManager &device_manage
610603

611604
return device_manager.RunProfilingOnReplay(remote_gfxr_file,
612605
*m_enabled_settings_vector,
613-
m_capture_file_directory.value());
606+
m_local_capture_file_directory.value());
614607
}
615608

616609
//--------------------------------------------------------------------------------------------------
@@ -624,7 +617,7 @@ absl::Status AnalyzeDialog::GpuTimeReplay(Dive::DeviceManager &device_manager,
624617
return device_manager.RunReplayApk(remote_gfxr_file,
625618
replay_args,
626619
false,
627-
m_capture_file_directory.value());
620+
m_local_capture_file_directory.value());
628621
}
629622

630623
//--------------------------------------------------------------------------------------------------
@@ -690,17 +683,41 @@ void AnalyzeDialog::OnReplay()
690683
}
691684

692685
// Set the download directory to the directory of the current capture file
693-
m_capture_file_directory = GetCaptureFileDirectory();
694-
if (!m_capture_file_directory.ok())
686+
m_local_capture_file_directory = GetCaptureFileDirectory();
687+
if (!m_local_capture_file_directory.ok())
695688
{
696689
std::string err_msg = absl::StrCat("Failed to set download directory: ",
697-
m_capture_file_directory.status().message());
690+
m_local_capture_file_directory.status().message());
698691
qDebug() << err_msg.c_str();
699692
ShowErrorMessage(err_msg);
700693
SetReplayButton(kDefaultReplayButtonText, true);
701694
return;
702695
}
703696

697+
// Delete any temporary artifacts from previous runs (.rd, .csv, etc)
698+
std::filesystem::path gfxr_filename_stem = std::filesystem::path(remote_file.value()).stem();
699+
std::filesystem::path perf_counter_csv = GetFullLocalPath(gfxr_filename_stem.string(),
700+
Dive::kProfilingMetricsCsvSuffix);
701+
std::filesystem::path gpu_timing_csv = GetFullLocalPath(gfxr_filename_stem.string(),
702+
Dive::kGpuTimingCsvSuffix);
703+
qDebug() << "Attempting to delete temporary artifacts from previous runs...";
704+
if (std::filesystem::remove(perf_counter_csv))
705+
{
706+
qDebug() << "Successfully deleted: " << perf_counter_csv.string().c_str();
707+
}
708+
else
709+
{
710+
qDebug() << "Was not present: " << perf_counter_csv.string().c_str();
711+
}
712+
if (std::filesystem::remove(gpu_timing_csv))
713+
{
714+
qDebug() << "Successfully deleted: " << gpu_timing_csv.string().c_str();
715+
}
716+
else
717+
{
718+
qDebug() << "Was not present: " << gpu_timing_csv.string().c_str();
719+
}
720+
704721
// Get the enabled settings
705722
m_dump_pm4_enabled = m_dump_pm4_box->currentIndex() == 0;
706723
m_gpu_time_enabled = m_gpu_time_box->currentIndex() == 0;
@@ -740,12 +757,18 @@ void AnalyzeDialog::OnReplay()
740757
SetReplayButton(kDefaultReplayButtonText, true);
741758
return;
742759
}
743-
744-
UpdatePerfTabView(remote_file.value());
745760
WaitForReplay(*device);
761+
qDebug() << "Loading perf counter data: " << perf_counter_csv.string().c_str();
762+
emit OnDisplayPerfCounterResults(QString::fromStdString(perf_counter_csv.string()));
763+
}
764+
else
765+
{
766+
qDebug() << "Cleared perf counter data";
767+
emit OnDisplayPerfCounterResults("");
746768
}
747769

748770
// Run the gpu_time replay
771+
std::string gpu_time_csv_stem = "";
749772
if (m_gpu_time_enabled)
750773
{
751774
ret = GpuTimeReplay(device_manager, remote_file.value());
@@ -757,8 +780,14 @@ void AnalyzeDialog::OnReplay()
757780
SetReplayButton(kDefaultReplayButtonText, true);
758781
return;
759782
}
760-
UpdateGpuTimingTabView(remote_file.value());
761783
WaitForReplay(*device);
784+
qDebug() << "Loading gpu timing data: " << perf_counter_csv.string().c_str();
785+
emit OnDisplayGpuTimingResults(QString::fromStdString(gpu_timing_csv.string()));
786+
}
787+
else
788+
{
789+
qDebug() << "Cleared gpu timing data";
790+
emit OnDisplayGpuTimingResults("");
762791
}
763792

764793
SetReplayButton(kDefaultReplayButtonText, true);

ui/analyze_window.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ private slots:
7373
void SetReplayButton(const std::string &message, bool is_enabled);
7474
void PopulateSettings();
7575
void UpdateSelectedSettingsList();
76-
void UpdatePerfTabView(const std::string remote_file_name);
77-
void UpdateGpuTimingTabView(const std::string remote_file_name);
76+
std::filesystem::path GetFullLocalPath(const std::string &gfxr_stem,
77+
const std::string &suffix) const;
7878
void WaitForReplay(Dive::AndroidDevice &device);
7979
absl::StatusOr<std::string> GetCaptureFileDirectory();
8080
absl::StatusOr<std::string> GetAssetFile();
@@ -122,6 +122,9 @@ private slots:
122122
QLabel *m_frame_count_label;
123123
QSpinBox *m_frame_count_box;
124124

125+
QHBoxLayout *m_replay_warning_layout;
126+
QLabel *m_replay_warning_label;
127+
125128
QHBoxLayout *m_button_layout;
126129
QPushButton *m_load_settings_button;
127130
QPushButton *m_replay_button;
@@ -139,7 +142,7 @@ private slots:
139142
const int kDataRole = Qt::UserRole + 1;
140143
const int kDefaultFrameCount = 3;
141144
const std::string kDefaultReplayButtonText = "Replay";
142-
absl::StatusOr<std::string> m_capture_file_directory = "";
145+
absl::StatusOr<std::string> m_local_capture_file_directory = "";
143146

144147
bool m_dump_pm4_enabled;
145148
bool m_gpu_time_enabled;

ui/gpu_timing_model.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ void GpuTimingModel::OnGpuTimingResultsGenerated(const QString &file_path)
2929
emit beginResetModel();
3030
m_available_gpu_timing_data = {}; // Need to create a new AvailableGpuTiming object because it
3131
// can only be loaded once
32+
33+
if (file_path.size() == 0)
34+
{
35+
emit endResetModel();
36+
return;
37+
}
38+
3239
ParseCsv(file_path);
3340
emit endResetModel();
3441
}

ui/main_window.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,11 @@ bool MainWindow::LoadFile(const std::string &file_name, bool is_temp_file)
10661066
QString::fromStdWString(perf_counter_file_path.wstring()));
10671067
qDebug() << "Loaded: " << perf_counter_file_path.string().c_str();
10681068
}
1069+
else
1070+
{
1071+
m_perf_counter_model->OnPerfCounterResultsGenerated("");
1072+
qDebug() << "Failed to find perf counter data";
1073+
}
10691074

10701075
// Check if there is existing gpu timing data
10711076
qDebug() << "Attempting to load gpu timing data from: "
@@ -1076,6 +1081,11 @@ bool MainWindow::LoadFile(const std::string &file_name, bool is_temp_file)
10761081
QString::fromStdWString(gpu_time_file_path.wstring()));
10771082
qDebug() << "Loaded: " << gpu_time_file_path.string().c_str();
10781083
}
1084+
else
1085+
{
1086+
m_gpu_timing_model->OnGpuTimingResultsGenerated("");
1087+
qDebug() << "Failed to find gpu timing data";
1088+
}
10791089
}
10801090

10811091
bool file_loaded = false;

ui/perf_counter_model.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ PerfCounterModel::PerfCounterModel(QObject *parent) :
2727
void PerfCounterModel::OnPerfCounterResultsGenerated(const QString &file_path)
2828
{
2929
emit beginResetModel();
30+
31+
m_csv_data.clear();
32+
m_search_results.clear();
33+
m_search_iterator = nullptr;
34+
m_headers.clear();
35+
m_column_count = 0;
36+
37+
if (file_path.length() == 0)
38+
{
39+
emit endResetModel();
40+
return;
41+
}
42+
3043
ParseCsv(file_path);
3144
emit endResetModel();
3245
}

0 commit comments

Comments
 (0)