Add simple block profiler
This commit is contained in:
31
openVulkanoCpp/Base/BlockProfiler.hpp
Normal file
31
openVulkanoCpp/Base/BlockProfiler.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
class BlockProfiler final
|
||||
{
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start;
|
||||
const std::string name;
|
||||
|
||||
public:
|
||||
BlockProfiler(const std::string& name) : name(name)
|
||||
{
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
~BlockProfiler()
|
||||
{
|
||||
const std::chrono::time_point<std::chrono::high_resolution_clock> done = std::chrono::high_resolution_clock::now();
|
||||
const auto time = std::chrono::duration_cast<std::chrono::microseconds>(done - start);
|
||||
Logger::PERF->info("Block {} took {:.3f} ms", name, time.count() / 1000.0);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -33,6 +33,7 @@ namespace openVulkanoCpp
|
||||
Logger::Ptr Logger::INPUT = nullptr;
|
||||
Logger::Ptr Logger::FILESYS = nullptr;
|
||||
Logger::Ptr Logger::AR = nullptr;
|
||||
Logger::Ptr Logger::PERF = nullptr;
|
||||
|
||||
void Logger::SetupLogger(const std::string& logFolder, const std::string& logFile)
|
||||
{
|
||||
@@ -66,6 +67,7 @@ namespace openVulkanoCpp
|
||||
INPUT = CreateLogger("input");
|
||||
FILESYS = CreateLogger("filesys");
|
||||
AR = CreateLogger("ar");
|
||||
PERF = CreateLogger("perf");
|
||||
|
||||
spdlog::flush_every(std::chrono::seconds(5));
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace openVulkanoCpp
|
||||
static Ptr INPUT;
|
||||
static Ptr FILESYS;
|
||||
static Ptr AR;
|
||||
static Ptr PERF;
|
||||
|
||||
static void SetupLogger(const std::string& logFolder = "logs", const std::string& logFile = "openVulkano.log");
|
||||
|
||||
|
||||
@@ -71,19 +71,19 @@ namespace openVulkanoCpp
|
||||
totalSeconds += tickSeconds;
|
||||
}
|
||||
|
||||
int64_t GetTickNanoseconds() const { return tickNanoseconds; }
|
||||
[[nodiscard]] int64_t GetTickNanoseconds() const { return tickNanoseconds; }
|
||||
|
||||
int64_t GetTickMilliseconds() const { return tickMilliseconds; }
|
||||
[[nodiscard]] int64_t GetTickMilliseconds() const { return tickMilliseconds; }
|
||||
|
||||
double GetTickSeconds() const { return tickSeconds; }
|
||||
[[nodiscard]] double GetTickSeconds() const { return tickSeconds; }
|
||||
|
||||
uint64_t GetTotalNanoseconds() const { return totalNanoseconds; }
|
||||
[[nodiscard]] uint64_t GetTotalNanoseconds() const { return totalNanoseconds; }
|
||||
|
||||
/**
|
||||
* \brief Gets the total amount of seconds past since the timer has been started. This will drift over time!
|
||||
* \return The summed total runtime of the timer.
|
||||
*/
|
||||
double GetTotalSeconds() const { return totalSeconds; }
|
||||
[[nodiscard]] double GetTotalSeconds() const { return totalSeconds; }
|
||||
|
||||
/**
|
||||
* \brief Will recalculate the past time from the total nanoseconds and return it. This is more precise but also slower.
|
||||
|
||||
Reference in New Issue
Block a user