Skip to content

Commit 15b1771

Browse files
committed
change path string into AZ::IO::Path
Signed-off-by: Wojciech Czerski <[email protected]>
1 parent 8d2d912 commit 15b1771

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

Gems/FPSProfiler/Code/Include/FPSProfiler/FPSProfilerBus.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ namespace FPSProfiler
5252
* @warning This function is NOT runtime safe. Use @ref SafeChangeSavePath instead.
5353
* @param newSavePath The new file path where profiling data should be saved.
5454
*/
55-
virtual void ChangeSavePath(const AZStd::string& newSavePath) = 0;
55+
virtual void ChangeSavePath(const AZ::IO::Path& newSavePath) = 0;
5656

5757
/**
5858
* @brief Safely changes the save path during runtime.
5959
* This method stops profiling, saves the current data, and then updates the path.
6060
* @param newSavePath The new file path where profiling data should be saved.
6161
*/
62-
virtual void SafeChangeSavePath(const AZStd::string& newSavePath) = 0;
62+
virtual void SafeChangeSavePath(const AZ::IO::Path& newSavePath) = 0;
6363

6464
/**
6565
* @brief Retrieves the minimum recorded FPS during the profiling session.
@@ -107,7 +107,7 @@ namespace FPSProfiler
107107
* @param newSavePath The csv file path where the log should be saved.
108108
* @param useSafeChangePath If true, the function will use @ref SafeChangeSavePath to ensure runtime safety.
109109
*/
110-
virtual void SaveLogToFileWithNewPath(const AZStd::string& newSavePath, bool useSafeChangePath) = 0;
110+
virtual void SaveLogToFileWithNewPath(const AZ::IO::Path& newSavePath, bool useSafeChangePath) = 0;
111111

112112
/**
113113
* @brief Enables or disables FPS display on-screen.

Gems/FPSProfiler/Code/Source/Clients/FPSProfilerComponent.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ namespace FPSProfiler
324324
return m_configRecord.m_RecordStats != Configs::RecordStatistics::None;
325325
}
326326

327-
void FPSProfilerComponent::ChangeSavePath(const AZStd::string& newSavePath)
327+
void FPSProfilerComponent::ChangeSavePath(const AZ::IO::Path& newSavePath)
328328
{
329329
if (!IsPathValid(newSavePath))
330330
{
@@ -335,7 +335,7 @@ namespace FPSProfiler
335335
AZ_Warning("FPS Profiler", !m_configDebug.m_PrintDebugInfo && !m_isProfiling, "Path changed during activated profiling.");
336336
}
337337

338-
void FPSProfilerComponent::SafeChangeSavePath(const AZStd::string& newSavePath)
338+
void FPSProfilerComponent::SafeChangeSavePath(const AZ::IO::Path& newSavePath)
339339
{
340340
// If profiling is enabled, save current opened file and stop profiling.
341341
StopProfiling();
@@ -393,7 +393,7 @@ namespace FPSProfiler
393393
WriteDataToFile();
394394
}
395395

396-
void FPSProfilerComponent::SaveLogToFileWithNewPath(const AZStd::string& newSavePath, bool useSafeChangePath)
396+
void FPSProfilerComponent::SaveLogToFileWithNewPath(const AZ::IO::Path& newSavePath, bool useSafeChangePath)
397397
{
398398
if (useSafeChangePath)
399399
{
@@ -485,10 +485,9 @@ namespace FPSProfiler
485485
char timestamp[20];
486486
strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", &timeInfo);
487487

488-
AZ::IO::Path logFilePath(m_configFile.m_OutputFilename);
489-
logFilePath.ReplaceFilename((logFilePath.Stem().String() + "_" + timestamp + logFilePath.Extension().String()).data());
490-
491-
m_configFile.m_OutputFilename = logFilePath.c_str();
488+
m_configFile.m_OutputFilename.ReplaceFilename(
489+
(m_configFile.m_OutputFilename.Stem().String() + "_" + timestamp + m_configFile.m_OutputFilename.Extension().String())
490+
.data());
492491
}
493492

494493
// Write profiling headers to file
@@ -531,19 +530,17 @@ namespace FPSProfiler
531530
return static_cast<float>(bytes) / (1024.0f * 1024.0f);
532531
}
533532

534-
bool FPSProfilerComponent::IsPathValid(const AZStd::string& path) const
533+
bool FPSProfilerComponent::IsPathValid(const AZ::IO::Path& path) const
535534
{
536535
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
537-
AZ::IO::Path pathToValidate(path.c_str());
538536

539-
if (pathToValidate.empty() || !pathToValidate.HasFilename() || !pathToValidate.HasExtension() || !fileIO ||
540-
!fileIO->ResolvePath(pathToValidate))
537+
if (path.empty() || !path.HasFilename() || !path.HasExtension() || !fileIO || !fileIO->ResolvePath(path))
541538
{
542-
const char* reason = pathToValidate.empty() ? "Path cannot be empty."
543-
: !pathToValidate.HasFilename() ? "Path must have a file at the end."
544-
: !pathToValidate.HasExtension() ? "Path must have a *.csv extension."
545-
: !fileIO ? "Could not get a FileIO object. Try again."
546-
: "Path is not registered or recognizable by O3DE FileIO System.";
539+
const char* reason = path.empty() ? "Path cannot be empty."
540+
: !path.HasFilename() ? "Path must have a file at the end."
541+
: !path.HasExtension() ? "Path must have a *.csv extension."
542+
: !fileIO ? "Could not get a FileIO object. Try again."
543+
: "Path is not registered or recognizable by O3DE FileIO System.";
547544

548545
AZ_Warning("FPSProfiler::IsPathValid", !m_configDebug.m_PrintDebugInfo, "%s", reason);
549546
return false;

Gems/FPSProfiler/Code/Source/Clients/FPSProfilerComponent.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ namespace FPSProfiler
4545
void ResetProfilingData() override;
4646
[[nodiscard]] bool IsProfiling() const override;
4747
[[nodiscard]] bool IsAnySaveOptionEnabled() const override;
48-
void ChangeSavePath(const AZStd::string& newSavePath) override;
49-
void SafeChangeSavePath(const AZStd::string& newSavePath) override;
48+
void ChangeSavePath(const AZ::IO::Path& newSavePath) override;
49+
void SafeChangeSavePath(const AZ::IO::Path& newSavePath) override;
5050
[[nodiscard]] float GetMinFps() const override;
5151
[[nodiscard]] float GetMaxFps() const override;
5252
[[nodiscard]] float GetAvgFps() const override;
5353
[[nodiscard]] float GetCurrentFps() const override;
5454
[[nodiscard]] AZStd::pair<AZStd::size_t, AZStd::size_t> GetCpuMemoryUsed() const override;
5555
[[nodiscard]] AZStd::pair<AZStd::size_t, AZStd::size_t> GetGpuMemoryUsed() const override;
5656
void SaveLogToFile() override;
57-
void SaveLogToFileWithNewPath(const AZStd::string& newSavePath, bool useSafeChangePath) override;
57+
void SaveLogToFileWithNewPath(const AZ::IO::Path& newSavePath, bool useSafeChangePath) override;
5858
void ShowFpsOnScreen(bool enable) override;
5959

6060
public:
@@ -88,7 +88,7 @@ namespace FPSProfiler
8888
// Utility Functions
8989
void CalculateFpsData(const float& deltaTime);
9090
static float BytesToMB(AZStd::size_t bytes);
91-
[[nodiscard]] bool IsPathValid(const AZStd::string& path) const;
91+
[[nodiscard]] bool IsPathValid(const AZ::IO::Path& path) const;
9292

9393
// Debug Display
9494
void ShowFps() const;

Gems/FPSProfiler/Code/Source/Configurations/FPSProfilerConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace FPSProfiler::Configs
4040
AZ_TYPE_INFO(FileSaveSettings, FPSProfilerConfigFileTypeId);
4141
static void Reflect(AZ::ReflectContext* context);
4242

43-
AZStd::string m_OutputFilename = "@user@/fps_log.csv";
43+
AZ::IO::Path m_OutputFilename = "@user@/fps_log.csv";
4444
bool m_AutoSave = true;
4545
int m_AutoSaveAtFrame = 100;
4646
bool m_SaveWithTimestamp = true;

0 commit comments

Comments
 (0)