From ab24a8733bc445a0a8da2a085a2e89896195d57a Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 5 Oct 2023 01:40:36 -0400 Subject: [PATCH] add partial API compatability with profiler v1 the general idea is the same however due to how profiles are handled after calling write or print profile the intervals inside are no longer valid. (they are deleted and will be removed from the internal hashmap) print profile is also now consistent with the new API, old calls will need to be updated. --- include/blt/profiling/profiler_v2.h | 5 +++-- src/blt/profiling/profiler_v2.cpp | 33 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/blt/profiling/profiler_v2.h b/include/blt/profiling/profiler_v2.h index b4e9204..7f57fc5 100644 --- a/include/blt/profiling/profiler_v2.h +++ b/include/blt/profiling/profiler_v2.h @@ -103,9 +103,10 @@ namespace blt void endInterval(const std::string& profile_name, const std::string& interval_name); - void printProfile(const std::string& profile_name); + void printProfile(const std::string& profile_name, std::uint32_t flags = PRINT_HISTORY | PRINT_CYCLES | PRINT_THREAD | PRINT_WALL, + sort_by sort = sort_by::CYCLES, blt::logging::log_level log_level = blt::logging::log_level::NONE); - void writeProfile(const std::string& profile_name); + void writeProfile(std::ifstream& stream, const std::string& profile_name); } class auto_interval diff --git a/src/blt/profiling/profiler_v2.cpp b/src/blt/profiling/profiler_v2.cpp index f3f51a1..abc8d0c 100644 --- a/src/blt/profiling/profiler_v2.cpp +++ b/src/blt/profiling/profiler_v2.cpp @@ -212,28 +212,45 @@ namespace blt } /** - * profiler V1 backwards compat + * profiler V1 partial backwards compat + * ---------------------------- */ - + HASHMAP> profiles; void _internal::startInterval(const std::string& profile_name, const std::string& interval_name) { - + auto& profile = profiles[profile_name]; + if (!profile.contains(interval_name)) + { + auto interval = new interval_t(); + interval->interval_name = interval_name; + profile[interval_name] = interval; + } + blt::startInterval(profile[interval_name]); } void _internal::endInterval(const std::string& profile_name, const std::string& interval_name) { - + blt::endInterval(profiles[profile_name].at(interval_name)); } - void _internal::printProfile(const std::string& profile_name) + void _internal::writeProfile(std::ifstream& stream, const std::string& profile_name) { - + auto& pref = profiles[profile_name]; + profile_t profile{profile_name}; + for (const auto& i : pref) + profile.intervals.push_back(i.second); + profiles.erase(profile_name); } - void _internal::writeProfile(const std::string& profile_name) + void _internal::printProfile(const std::string& profile_name, std::uint32_t flags, sort_by sort, blt::logging::log_level log_level) { - + auto& pref = profiles[profile_name]; + profile_t profile{profile_name}; + for (const auto& i : pref) + profile.intervals.push_back(i.second); + blt::printProfile(profile, flags, sort, log_level); + profiles.erase(profile_name); } } \ No newline at end of file