Basic intervals on the profiler

v1
Brett 2022-12-29 00:56:37 -05:00
parent bc66a3ce79
commit c6e173a34e
2 changed files with 36 additions and 4 deletions

View File

@ -10,6 +10,7 @@
#include <string>
#include <string_view>
#include <blt/config.h>
#include <mutex>
#ifdef PHMAP_ENABLED
#include <parallel_hashmap/phmap.h>
@ -30,17 +31,26 @@ namespace BLT {
#ifdef PHMAP_ENABLED
typedef phmap::parallel_flat_hash_map<std::string_view, CaptureInterval> INTERVAL_MAP;
typedef phmap::parallel_flat_hash_map<std::string_view, CapturePoint> POINT_MAP;
typedef phmap::parallel_flat_hash_map<int, std::string_view> ORDER_MAP;
#else
typedef std::unordered_map<std::string_view, CaptureInterval> INTERVAL_MAP;
typedef std::unordered_map<std::string_view, CapturePoint> POINT_MAP;
typedef std::unordered_map<int, std::string_view> ORDER_MAP;
#endif
class Profiler {
private:
INTERVAL_MAP intervals;
POINT_MAP points;
INTERVAL_MAP intervals{};
POINT_MAP points{};
ORDER_MAP order{};
std::mutex timerLock{};
int lastOrder = 0;
public:
Profiler();
Profiler() = default;
void finishCycle();
void startInterval(const std::string_view& name);
void endInterval(const std::string_view& name);
};
}

View File

@ -4,7 +4,29 @@
* See LICENSE file for license detail
*/
#include <blt/profiling/profiler.h>
#include <iostream>
#include <utility>
namespace BLT {
void Profiler::finishCycle() {
}
static inline auto getCurrentTimeNanoseconds() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
void Profiler::startInterval(const std::string_view& name) {
std::scoped_lock lock(timerLock);
CaptureInterval interval{};
interval.start = {getCurrentTimeNanoseconds()};
intervals[name] = interval;
}
void Profiler::endInterval(const std::string_view& name) {
std::scoped_lock lock(timerLock);
intervals[name].end = {getCurrentTimeNanoseconds()};
order[lastOrder++] = name;
}
}