BLT/include/blt/profiling/profiler.h

58 lines
1.5 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>
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, CapturePoint> POINT_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: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{};
POINT_MAP points{};
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);
2022-12-26 00:31:00 -05:00
};
}
2022-12-23 13:50:27 -05:00
#endif //BLT_PROFILER_H