Add history to intervals

v1
Brett 2023-02-14 22:06:30 -05:00
parent a196a2aa7d
commit 001b6ae46a
2 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <string>
#include <blt/std/queue.h>
#include <vector>
#include <unordered_map>
#include <blt/std/logging.h>
@ -29,6 +30,7 @@ namespace blt::profiling {
struct Profile {
std::unordered_map<std::string, CaptureInterval> intervals;
std::unordered_map<std::string, std::vector<CaptureInterval>> historicalIntervals;
blt::flat_queue<CapturePoint> points;
};
@ -38,6 +40,7 @@ namespace blt::profiling {
void point(const std::string& profileName, const std::string& pointName);
CaptureInterval getInterval(const std::string& profileName, const std::string& intervalName);
std::vector<CaptureInterval> getAllIntervals(const std::string& profileName, const std::string& intervalName);
Profile getProfile(const std::string& profileName);
void printProfile(const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel = logging::NONE);

View File

@ -28,6 +28,7 @@ namespace blt::profiling {
void endInterval(const std::string& profileName, const std::string& intervalName) {
std::scoped_lock lock(profileLock);
profiles[profileName].intervals[intervalName].end = system::getCurrentTimeNanoseconds();
profiles[profileName].historicalIntervals[intervalName].push_back(profiles[profileName].intervals[intervalName]);
}
void point(const std::string& profileName, const std::string& pointName) {
@ -125,9 +126,14 @@ namespace blt::profiling {
void discardIntervals(const std::string& profileName) {
profiles[profileName].intervals = {};
profiles[profileName].historicalIntervals = {};
}
void discardPoints(const std::string& profileName) {
profiles[profileName].points = {};
}
std::vector<CaptureInterval> getAllIntervals(const std::string& profileName, const std::string& intervalName) {
return profiles[profileName].historicalIntervals[intervalName];
}
}