2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-03-26 13:57:24 +00:00
|
|
|
|
2020-04-02 15:02:01 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common.hpp"
|
2022-08-29 10:29:44 +00:00
|
|
|
|
|
|
|
#include "warning-disable.hpp"
|
2020-03-26 13:57:24 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2020-03-26 13:57:24 +00:00
|
|
|
|
2021-06-23 11:03:40 +00:00
|
|
|
namespace streamfx::util {
|
|
|
|
class profiler : public std::enable_shared_from_this<streamfx::util::profiler> {
|
2020-03-26 13:57:24 +00:00
|
|
|
std::map<std::chrono::nanoseconds, size_t> _timings;
|
|
|
|
std::mutex _timings_lock;
|
|
|
|
|
|
|
|
public:
|
|
|
|
class instance {
|
|
|
|
std::shared_ptr<profiler> _parent;
|
|
|
|
std::chrono::high_resolution_clock::time_point _start;
|
|
|
|
|
|
|
|
public:
|
|
|
|
instance(std::shared_ptr<profiler> parent);
|
|
|
|
|
|
|
|
~instance();
|
|
|
|
|
|
|
|
void cancel();
|
|
|
|
|
|
|
|
void reparent(std::shared_ptr<profiler> parent);
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
profiler();
|
|
|
|
|
|
|
|
public:
|
|
|
|
~profiler();
|
|
|
|
|
2021-06-23 11:03:40 +00:00
|
|
|
std::shared_ptr<class streamfx::util::profiler::instance> track();
|
2020-03-26 13:57:24 +00:00
|
|
|
|
|
|
|
void track(std::chrono::nanoseconds duration);
|
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
uint64_t count();
|
2020-03-26 13:57:24 +00:00
|
|
|
|
|
|
|
std::chrono::nanoseconds total_duration();
|
|
|
|
|
|
|
|
double_t average_duration();
|
|
|
|
|
|
|
|
std::chrono::nanoseconds percentile(double_t percentile, bool by_time = false);
|
|
|
|
|
|
|
|
public:
|
2021-06-23 11:03:40 +00:00
|
|
|
static std::shared_ptr<streamfx::util::profiler> create()
|
2020-03-26 13:57:24 +00:00
|
|
|
{
|
2021-06-23 11:03:40 +00:00
|
|
|
return std::shared_ptr<streamfx::util::profiler>{new profiler()};
|
2020-03-26 13:57:24 +00:00
|
|
|
}
|
|
|
|
};
|
2021-06-23 11:03:40 +00:00
|
|
|
} // namespace streamfx::util
|