Skip to content

Commit

Permalink
[RaZ] Added file paths as profiling zone texts
Browse files Browse the repository at this point in the history
- This indicates which file is being processed by the current zone for IO operations
  • Loading branch information
Razakhel committed Jan 22, 2025
1 parent 40d66e1 commit 2b6f11c
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/RaZ/Data/BvhFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void loadJoint(std::ifstream& file, std::unordered_map<std::string, SkeletonJoin

Skeleton load(const FilePath& filePath) {
ZoneScopedN("BvhFormat::load");
ZoneTextF("Path: %s", filePath.toUtf8().c_str());

std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary);

Expand Down
2 changes: 2 additions & 0 deletions src/RaZ/Data/FbxLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace {

inline Texture2DPtr loadTexture(const FilePath& textureFilePath, const Color& defaultColor, bool shouldUseSrgb = false) {
ZoneScopedN("[FbxLoad]::loadTexture");
ZoneTextF("Path: %s", textureFilePath.toUtf8().c_str());

if (!FileUtils::isReadable(textureFilePath)) {
Logger::warn("[FbxLoad] Cannot load texture '" + textureFilePath + "'; either the file does not exist or it cannot be opened.");
Expand Down Expand Up @@ -119,6 +120,7 @@ void loadMaterials(fbxsdk::FbxScene* scene, std::vector<Material>& materials, co

std::pair<Mesh, MeshRenderer> 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));
Expand Down
1 change: 1 addition & 0 deletions src/RaZ/Data/GltfLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ void loadMaterials(const std::vector<fastgltf::Material>& materials,

std::pair<Mesh, MeshRenderer> load(const FilePath& filePath) {
ZoneScopedN("GltfFormat::load");
ZoneTextF("Path: %s", filePath.toUtf8().c_str());

Logger::debug("[GltfLoad] Loading glTF file ('" + filePath + "')...");

Expand Down
1 change: 1 addition & 0 deletions src/RaZ/Data/ImageFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'...");

Expand Down
2 changes: 2 additions & 0 deletions src/RaZ/Data/MeshFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Raz::MeshFormat {

std::pair<Mesh, MeshRenderer> load(const FilePath& filePath) {
ZoneScopedN("MeshFormat::load");
ZoneTextF("Path: %s", filePath.toUtf8().c_str());

const std::string fileExt = StrUtils::toLowercaseCopy(filePath.recoverExtension().toUtf8());

Expand All @@ -38,6 +39,7 @@ std::pair<Mesh, MeshRenderer> 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());

Expand Down
7 changes: 5 additions & 2 deletions src/RaZ/Data/ObjLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -34,10 +35,11 @@ inline void loadMtl(const FilePath& mtlFilePath,
std::vector<Material>& materials,
std::unordered_map<std::string, std::size_t>& 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 + "'.");
Expand Down Expand Up @@ -140,10 +142,11 @@ inline void loadMtl(const FilePath& mtlFilePath,

std::pair<Mesh, MeshRenderer> 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 + '\'');
Expand Down
11 changes: 9 additions & 2 deletions src/RaZ/Data/ObjSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<Material>& 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";

Expand Down Expand Up @@ -91,8 +93,11 @@ void saveMtl(const FilePath& mtlFilePath, const std::vector<Material>& 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");
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/RaZ/Data/OffLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'');
Expand Down
7 changes: 6 additions & 1 deletion src/RaZ/Data/TgaFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'");
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/RaZ/Data/WavLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'");
Expand Down
11 changes: 10 additions & 1 deletion src/RaZ/Data/WavSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "RaZ/Utils/FilePath.hpp"
#include "RaZ/Utils/Logger.hpp"

#include "tracy/Tracy.hpp"

#include <array>
#include <fstream>

Expand All @@ -21,7 +23,12 @@ constexpr std::array<char, 2> 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");
Expand Down Expand Up @@ -107,6 +114,8 @@ void save(const FilePath& filePath, const AudioData& data) {
file << "data";
file.write(toLittleEndian32(static_cast<uint32_t>(data.buffer.size())).data(), 4);
file.write(reinterpret_cast<const char*>(data.buffer.data()), static_cast<std::streamsize>(data.buffer.size()));

Logger::debug("[WavSave] Saved WAV file");
}

} // namespace Raz::WavFormat
1 change: 1 addition & 0 deletions src/RaZ/Render/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/RaZ/Script/LuaEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/RaZ/Script/LuaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/RaZ/Script/LuaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/RaZ/Utils/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace {
template <typename T>
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);

Expand Down Expand Up @@ -44,11 +45,13 @@ bool isReadable(const FilePath& filePath) {

std::vector<unsigned char> readFileToArray(const FilePath& filePath) {
ZoneScopedN("FileUtils::readFileToArray");
ZoneTextF("Path: %s", filePath.toUtf8().c_str());
return readFile<std::vector<unsigned char>>(filePath);
}

std::string readFileToString(const FilePath& filePath) {
ZoneScopedN("FileUtils::readFileToString");
ZoneTextF("Path: %s", filePath.toUtf8().c_str());
return readFile<std::string>(filePath);
}

Expand Down

0 comments on commit 2b6f11c

Please sign in to comment.