BLT/include/blt/profiling/profiler.h

68 lines
2.0 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
*/
#ifndef BLT_PROFILER_H
#define BLT_PROFILER_H
2022-12-25 23:19:44 -05:00
#include <string>
#include <string_view>
2022-12-27 00:51:37 -05:00
#include <blt/config.h>
2022-12-29 00:56:37 -05:00
#include <mutex>
#include <queue>
2022-12-27 00:51:37 -05:00
#ifdef PHMAP_ENABLED
#include <parallel_hashmap/phmap.h>
#else
#include <unordered_map>
#endif
2022-12-26 23:44:02 -05:00
2022-12-23 13:50:27 -05:00
2022-12-26 00:31:00 -05:00
namespace BLT {
struct CapturePoint {
long point;
};
struct CaptureInterval {
CapturePoint start;
CapturePoint end;
};
2022-12-27 00:51:37 -05:00
#ifdef PHMAP_ENABLED
typedef phmap::parallel_flat_hash_map<std::string_view, CaptureInterval> INTERVAL_MAP;
typedef phmap::parallel_flat_hash_map<std::string_view, std::queue<CapturePoint>> POINT_MAP;
2022-12-29 00:58:54 -05:00
typedef phmap::parallel_flat_hash_map<std::string_view, POINT_MAP> POINT_HISTORY_MAP;
2022-12-29 00:56:37 -05:00
typedef phmap::parallel_flat_hash_map<int, std::string_view> ORDER_MAP;
2022-12-27 00:51:37 -05:00
#else
typedef std::unordered_map<std::string_view, CaptureInterval> INTERVAL_MAP;
typedef std::unordered_map<std::string_view, CapturePoint> POINT_MAP;
2022-12-29 00:58:54 -05:00
typedef std::unordered_map<std::string_view, CapturePoint> POINT_HISTORY_MAP;
2022-12-29 00:56:37 -05:00
typedef std::unordered_map<int, std::string_view> ORDER_MAP;
2022-12-27 00:51:37 -05:00
#endif
2022-12-26 00:31:00 -05:00
class Profiler {
private:
2022-12-29 00:56:37 -05:00
INTERVAL_MAP intervals{};
std::queue<CapturePoint> points{};
std::queue<CapturePoint> cyclicPoints{};
2022-12-29 00:58:54 -05:00
POINT_HISTORY_MAP cyclicPointsHistory{};
2022-12-29 00:56:37 -05:00
ORDER_MAP order{};
std::mutex timerLock{};
int lastOrder = 0;
2022-12-26 23:36:34 -05:00
public:
2022-12-29 00:56:37 -05:00
Profiler() = default;
void finishCycle();
void startInterval(const std::string_view& name);
void endInterval(const std::string_view& name);
void profilerPoint();
/**
* Uses a separate tracking device that will be reset when finishCycle(); is called.
*/
void profilerPointCyclic();
2022-12-26 00:31:00 -05:00
};
}
2022-12-23 13:50:27 -05:00
#endif //BLT_PROFILER_H