1#ifndef LIBSBX_CORE_PROFILER_HPP_
2#define LIBSBX_CORE_PROFILER_HPP_
6#include <unordered_map>
9#include <libsbx/units/time.hpp>
11#include <libsbx/utility/hashed_string.hpp>
25 std::vector<group_entry> entries;
30 _measurements[scope] = measurement;
33 template<
typename Callable>
34 requires (std::is_invocable_v<Callable, const utility::hashed_string&, const group&>)
35 auto for_each(Callable&&
callable) ->
void {
36 auto grouped = std::unordered_map<utility::hashed_string, group>{};
38 for (
const auto& [scope, measurement] : _measurements) {
39 const auto position = scope.rfind(
"::");
41 const auto has_namespace = (position != utility::hashed_string::npos);
43 const auto group = has_namespace ? scope.substr(0, position) : scope;
44 const auto name = has_namespace ? scope.substr(position + 2u) : scope;
47 grouped[group].overall = measurement;
49 grouped[group].entries.emplace_back(name.str(), measurement);
53 for (
auto& [group_name, group] : grouped) {
54 std::sort(group.entries.begin(), group.entries.end(), [](
const auto& lhs,
const auto& rhs){
55 return lhs.measurement.value() > rhs.measurement.value();
58 std::invoke(callable, group_name, group);
64 std::unordered_map<utility::hashed_string, units::second> _measurements;
Definition: profiler.hpp:15
Definition: quantity.hpp:65
Definition: hashed_string.hpp:15
Describes a type or object that can be invoked with the give parameters and return the given type.
Definition: concepts.hpp:17
Definition: profiler.hpp:19
Definition: profiler.hpp:24