Add simple block profiler

This commit is contained in:
2021-01-17 22:07:08 +01:00
parent e737a3ce95
commit b72b8a9a19
4 changed files with 39 additions and 5 deletions

View 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);
}
};
}

View File

@@ -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));

View File

@@ -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");

View File

@@ -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.