BLT/src/blt/profiling/profiler.cpp

63 lines
1.9 KiB
C++
Raw Normal View History

2022-12-23 13:50:27 -05:00
/*
* Created by Brett on 23/12/22.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
2022-12-26 00:31:00 -05:00
#include <blt/profiling/profiler.h>
2023-01-26 00:59:36 -05:00
#include <mutex>
#include <vector>
#include <blt/std/time.h>
#include <blt/std/logging.h>
#include <iostream>
2022-12-26 00:31:00 -05:00
2023-01-26 00:59:36 -05:00
namespace blt::profiling {
// TODO: a better way
std::mutex profileLock{};
std::unordered_map<std::string, Profile> profiles;
void startInterval(const std::string& profileName, const std::string& intervalName) {
std::scoped_lock lock(profileLock);
CaptureInterval interval{};
interval.start = System::getCurrentTimeNanoseconds();
profiles[profileName].intervals[intervalName] = interval;
}
void endInterval(const std::string& profileName, const std::string& intervalName) {
std::scoped_lock lock(profileLock);
profiles[profileName].intervals[intervalName].end = System::getCurrentTimeNanoseconds();
}
void point(const std::string& profileName, const std::string& pointName) {
}
CaptureInterval getInterval(const std::string& profileName, const std::string& intervalName) {
return profiles[profileName].intervals[intervalName];
}
Profile getProfile(const std::string& profileName) {
return profiles[profileName];
}
void printProfile(const std::string& profileName, int loggingLevel) {
//auto& out = loggingLevel < 0 ? std::cout : logging::loggerLevelDecode[loggingLevel];
}
2023-01-26 00:59:36 -05:00
void printOrderedProfile(const std::string& profileName, int loggingLevel) {
}
void discardProfiles() {
profiles = {};
}
void discardIntervals(const std::string& profileName) {
profiles[profileName].intervals = {};
}
void discardPoints(const std::string& profileName) {
profiles[profileName].points = {};
}
2022-12-26 00:31:00 -05:00
}