From 2b6f11c7a5c3a23d460cda109b2e73ec8120bac2 Mon Sep 17 00:00:00 2001 From: Razakhel Date: Wed, 22 Jan 2025 13:21:11 +0100 Subject: [PATCH] [RaZ] Added file paths as profiling zone texts - This indicates which file is being processed by the current zone for IO operations --- src/RaZ/Data/BvhFormat.cpp | 1 + src/RaZ/Data/FbxLoad.cpp | 2 ++ src/RaZ/Data/GltfLoad.cpp | 1 + src/RaZ/Data/ImageFormat.cpp | 1 + src/RaZ/Data/MeshFormat.cpp | 2 ++ src/RaZ/Data/ObjLoad.cpp | 7 +++++-- src/RaZ/Data/ObjSave.cpp | 11 +++++++++-- src/RaZ/Data/OffLoad.cpp | 3 ++- src/RaZ/Data/TgaFormat.cpp | 7 ++++++- src/RaZ/Data/WavLoad.cpp | 3 ++- src/RaZ/Data/WavSave.cpp | 11 ++++++++++- src/RaZ/Render/RenderSystem.cpp | 1 + src/RaZ/Script/LuaEnvironment.cpp | 1 + src/RaZ/Script/LuaScript.cpp | 1 + src/RaZ/Script/LuaWrapper.cpp | 1 + src/RaZ/Utils/FileUtils.cpp | 3 +++ 16 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/RaZ/Data/BvhFormat.cpp b/src/RaZ/Data/BvhFormat.cpp index 1d63e67e..6b6ddfca 100644 --- a/src/RaZ/Data/BvhFormat.cpp +++ b/src/RaZ/Data/BvhFormat.cpp @@ -93,6 +93,7 @@ void loadJoint(std::ifstream& file, std::unordered_map& materials, co std::pair load(const FilePath& filePath) { ZoneScopedN("FbxFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); fbxsdk::FbxManager* manager = fbxsdk::FbxManager::Create(); manager->SetIOSettings(fbxsdk::FbxIOSettings::Create(manager, IOSROOT)); diff --git a/src/RaZ/Data/GltfLoad.cpp b/src/RaZ/Data/GltfLoad.cpp index 5904df50..7ed70990 100644 --- a/src/RaZ/Data/GltfLoad.cpp +++ b/src/RaZ/Data/GltfLoad.cpp @@ -362,6 +362,7 @@ void loadMaterials(const std::vector& materials, std::pair load(const FilePath& filePath) { ZoneScopedN("GltfFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[GltfLoad] Loading glTF file ('" + filePath + "')..."); diff --git a/src/RaZ/Data/ImageFormat.cpp b/src/RaZ/Data/ImageFormat.cpp index df545341..91cd5f1b 100644 --- a/src/RaZ/Data/ImageFormat.cpp +++ b/src/RaZ/Data/ImageFormat.cpp @@ -75,6 +75,7 @@ Image createImageFromData(int width, int height, int channelCount, bool isHdr, c Image load(const FilePath& filePath, bool flipVertically) { ZoneScopedN("ImageFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[ImageFormat] Loading image '" + filePath + "'..."); diff --git a/src/RaZ/Data/MeshFormat.cpp b/src/RaZ/Data/MeshFormat.cpp index 38662b34..bab05275 100644 --- a/src/RaZ/Data/MeshFormat.cpp +++ b/src/RaZ/Data/MeshFormat.cpp @@ -14,6 +14,7 @@ namespace Raz::MeshFormat { std::pair load(const FilePath& filePath) { ZoneScopedN("MeshFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); const std::string fileExt = StrUtils::toLowercaseCopy(filePath.recoverExtension().toUtf8()); @@ -38,6 +39,7 @@ std::pair load(const FilePath& filePath) { void save(const FilePath& filePath, const Mesh& mesh, const MeshRenderer* meshRenderer) { ZoneScopedN("MeshFormat::save"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); const std::string fileExt = StrUtils::toLowercaseCopy(filePath.recoverExtension().toUtf8()); diff --git a/src/RaZ/Data/ObjLoad.cpp b/src/RaZ/Data/ObjLoad.cpp index 0a1199ab..9ab5dc77 100644 --- a/src/RaZ/Data/ObjLoad.cpp +++ b/src/RaZ/Data/ObjLoad.cpp @@ -20,6 +20,7 @@ namespace { inline Texture2DPtr loadTexture(const FilePath& textureFilePath, const Color& defaultColor, bool shouldUseSrgb = false) { ZoneScopedN("[ObjLoad]::loadTexture"); + ZoneTextF("Path: %s", textureFilePath.toUtf8().c_str()); if (!FileUtils::isReadable(textureFilePath)) { Logger::warn("[ObjLoad] Cannot load texture '" + textureFilePath + "'; either the file does not exist or it cannot be opened."); @@ -34,10 +35,11 @@ inline void loadMtl(const FilePath& mtlFilePath, std::vector& materials, std::unordered_map& materialCorrespIndices) { ZoneScopedN("[ObjLoad]::loadMtl"); + ZoneTextF("Path: %s", mtlFilePath.toUtf8().c_str()); Logger::debug("[ObjLoad] Loading MTL file ('" + mtlFilePath + "')..."); - std::ifstream file(mtlFilePath, std::ios_base::in | std::ios_base::binary); + std::ifstream file(mtlFilePath, std::ios_base::binary); if (!file) { Logger::error("[ObjLoad] Could not open the MTL file '" + mtlFilePath + "'."); @@ -140,10 +142,11 @@ inline void loadMtl(const FilePath& mtlFilePath, std::pair load(const FilePath& filePath) { ZoneScopedN("ObjFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[ObjLoad] Loading OBJ file ('" + filePath + "')..."); - std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary); + std::ifstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("Error: Couldn't open the OBJ file '" + filePath + '\''); diff --git a/src/RaZ/Data/ObjSave.cpp b/src/RaZ/Data/ObjSave.cpp index 7e3044c9..82618bcc 100644 --- a/src/RaZ/Data/ObjSave.cpp +++ b/src/RaZ/Data/ObjSave.cpp @@ -5,6 +5,7 @@ #include "RaZ/Render/Material.hpp" #include "RaZ/Render/MeshRenderer.hpp" #include "RaZ/Utils/FilePath.hpp" +#include "RaZ/Utils/Logger.hpp" #include "tracy/Tracy.hpp" @@ -52,8 +53,9 @@ inline void writeTexture(std::ofstream& file, std::string_view tag, const std::s void saveMtl(const FilePath& mtlFilePath, const std::vector& materials) { ZoneScopedN("[ObjSave]::saveMtl"); + ZoneTextF("Path: %s", mtlFilePath.toUtf8().c_str()); - std::ofstream mtlFile(mtlFilePath, std::ios_base::out | std::ios_base::binary); + std::ofstream mtlFile(mtlFilePath, std::ios_base::binary); mtlFile << "# MTL file created with RaZ - https://github.com/Razakhel/RaZ\n"; @@ -91,8 +93,11 @@ void saveMtl(const FilePath& mtlFilePath, const std::vector& materials void save(const FilePath& filePath, const Mesh& mesh, const MeshRenderer* meshRenderer) { ZoneScopedN("ObjFormat::save"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); - std::ofstream file(filePath, std::ios_base::out | std::ios_base::binary); + Logger::debug("[ObjSave] Saving OBJ file ('" + filePath + "')..."); + + std::ofstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("Error: Unable to create an OBJ file as '" + filePath + "'; path to file must exist"); @@ -177,6 +182,8 @@ void save(const FilePath& filePath, const Mesh& mesh, const MeshRenderer* meshRe file << posIndex << '/' << texIndex << '/' << normIndex << '\n'; } } + + Logger::debug("[ObjSave] Saved OBJ file"); } } // namespace Raz::ObjFormat diff --git a/src/RaZ/Data/OffLoad.cpp b/src/RaZ/Data/OffLoad.cpp index c7af9be4..b995bf5b 100644 --- a/src/RaZ/Data/OffLoad.cpp +++ b/src/RaZ/Data/OffLoad.cpp @@ -11,10 +11,11 @@ namespace Raz::OffFormat { Mesh load(const FilePath& filePath) { ZoneScopedN("OffFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[OffLoad] Loading OFF file ('" + filePath + "')..."); - std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary); + std::ifstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("Error: Could not open the OFF file '" + filePath + '\''); diff --git a/src/RaZ/Data/TgaFormat.cpp b/src/RaZ/Data/TgaFormat.cpp index c9e06056..6bccf9d2 100644 --- a/src/RaZ/Data/TgaFormat.cpp +++ b/src/RaZ/Data/TgaFormat.cpp @@ -13,8 +13,11 @@ namespace Raz::TgaFormat { Image load(const FilePath& filePath, bool flipVertically) { ZoneScopedN("TgaFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); - std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary); + Logger::debug("[TgaFormat] Loading TGA file ('" + filePath + "')..."); + + std::ifstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("Error: Could not open the PNG file '" + filePath + "'"); @@ -131,6 +134,8 @@ Image load(const FilePath& filePath, bool flipVertically) { throw std::runtime_error("Error: RLE on TGA images is not handled yet"); } + Logger::debug("[TgaFormat] Loaded TGA file"); + return image; } diff --git a/src/RaZ/Data/WavLoad.cpp b/src/RaZ/Data/WavLoad.cpp index 94b3b0d4..4352a9a5 100644 --- a/src/RaZ/Data/WavLoad.cpp +++ b/src/RaZ/Data/WavLoad.cpp @@ -135,10 +135,11 @@ inline WavInfo validateWav(std::ifstream& file) { AudioData load(const FilePath& filePath) { ZoneScopedN("WavFormat::load"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[WavLoad] Loading WAV file ('" + filePath + "')..."); - std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary); + std::ifstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("[WavLoad] Could not open the WAV file '" + filePath + "'"); diff --git a/src/RaZ/Data/WavSave.cpp b/src/RaZ/Data/WavSave.cpp index 41098439..335879c7 100644 --- a/src/RaZ/Data/WavSave.cpp +++ b/src/RaZ/Data/WavSave.cpp @@ -3,6 +3,8 @@ #include "RaZ/Utils/FilePath.hpp" #include "RaZ/Utils/Logger.hpp" +#include "tracy/Tracy.hpp" + #include #include @@ -21,7 +23,12 @@ constexpr std::array toLittleEndian16(uint16_t val) { } // namespace void save(const FilePath& filePath, const AudioData& data) { - std::ofstream file(filePath, std::ios_base::out | std::ios_base::binary); + ZoneScopedN("WavFormat::save"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); + + Logger::debug("[WavSave] Saving WAV file ('" + filePath + "')..."); + + std::ofstream file(filePath, std::ios_base::binary); if (!file) throw std::invalid_argument("[WavSave] Unable to create a WAV file as '" + filePath + "'; path to file must exist"); @@ -107,6 +114,8 @@ void save(const FilePath& filePath, const AudioData& data) { file << "data"; file.write(toLittleEndian32(static_cast(data.buffer.size())).data(), 4); file.write(reinterpret_cast(data.buffer.data()), static_cast(data.buffer.size())); + + Logger::debug("[WavSave] Saved WAV file"); } } // namespace Raz::WavFormat diff --git a/src/RaZ/Render/RenderSystem.cpp b/src/RaZ/Render/RenderSystem.cpp index 87e0a993..33d720cb 100644 --- a/src/RaZ/Render/RenderSystem.cpp +++ b/src/RaZ/Render/RenderSystem.cpp @@ -162,6 +162,7 @@ void RenderSystem::updateMaterials() const { void RenderSystem::saveToImage(const FilePath& filePath, TextureFormat format, PixelDataType dataType) const { ZoneScopedN("RenderSystem::saveToImage"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); ImageColorspace colorspace = ImageColorspace::RGB; diff --git a/src/RaZ/Script/LuaEnvironment.cpp b/src/RaZ/Script/LuaEnvironment.cpp index d023e340..494b0fad 100644 --- a/src/RaZ/Script/LuaEnvironment.cpp +++ b/src/RaZ/Script/LuaEnvironment.cpp @@ -37,6 +37,7 @@ bool LuaEnvironment::execute(const std::string& code) const { bool LuaEnvironment::executeFromFile(const FilePath& filePath) const { ZoneScopedN("LuaEnvironment::executeFromFile"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); if (filePath.isEmpty()) return false; diff --git a/src/RaZ/Script/LuaScript.cpp b/src/RaZ/Script/LuaScript.cpp index d2af6e80..730ce2f9 100644 --- a/src/RaZ/Script/LuaScript.cpp +++ b/src/RaZ/Script/LuaScript.cpp @@ -46,6 +46,7 @@ void LuaScript::loadCode(const std::string& code) { void LuaScript::loadCodeFromFile(const FilePath& filePath) { ZoneScopedN("LuaScript::loadCodeFromFile"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); Logger::debug("[LuaScript] Loading code from file ('" + filePath + "')..."); loadCode(FileUtils::readFileToString(filePath)); diff --git a/src/RaZ/Script/LuaWrapper.cpp b/src/RaZ/Script/LuaWrapper.cpp index daadb3c7..ae1f2aa4 100644 --- a/src/RaZ/Script/LuaWrapper.cpp +++ b/src/RaZ/Script/LuaWrapper.cpp @@ -78,6 +78,7 @@ bool LuaWrapper::execute(const std::string& code) { bool LuaWrapper::executeFromFile(const FilePath& filePath) { ZoneScopedN("LuaWrapper::executeFromFile"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); if (filePath.isEmpty()) return false; diff --git a/src/RaZ/Utils/FileUtils.cpp b/src/RaZ/Utils/FileUtils.cpp index 9484560b..b8619b25 100644 --- a/src/RaZ/Utils/FileUtils.cpp +++ b/src/RaZ/Utils/FileUtils.cpp @@ -12,6 +12,7 @@ namespace { template T readFile(const FilePath& filePath) { ZoneScopedN("[FileUtils]::readFile"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); std::ifstream file(filePath, std::ios::binary | std::ios::ate); @@ -44,11 +45,13 @@ bool isReadable(const FilePath& filePath) { std::vector readFileToArray(const FilePath& filePath) { ZoneScopedN("FileUtils::readFileToArray"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); return readFile>(filePath); } std::string readFileToString(const FilePath& filePath) { ZoneScopedN("FileUtils::readFileToString"); + ZoneTextF("Path: %s", filePath.toUtf8().c_str()); return readFile(filePath); }