summaryrefslogtreecommitdiff
path: root/src/hook_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-08-12 13:06:53 +1000
committerMaxime Coste <mawww@kakoune.org>2023-08-13 03:57:46 +1000
commite090131b8705124e8ab78de076f4e8f25ba7746e (patch)
treeb97a797e55dfdea7ef55196c259b214e71cc55ee /src/hook_manager.cc
parente605ad8582d8e015806ed9b4d7aba8ca1ea13d57 (diff)
Add a ProfileScope helper class to replace most profiling uses
Diffstat (limited to 'src/hook_manager.cc')
-rw-r--r--src/hook_manager.cc14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index afab5461..a1b29434 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -8,6 +8,7 @@
#include "face_registry.hh"
#include "option.hh"
#include "option_types.hh"
+#include "profile.hh"
#include "ranges.hh"
#include "regex.hh"
@@ -138,9 +139,9 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
m_hooks_trash.clear();
});
- const DebugFlags debug_flags = context.options()["debug"].get<DebugFlags>();
- const bool profile = debug_flags & DebugFlags::Profile;
- auto start_time = profile ? Clock::now() : TimePoint{};
+ ProfileScope profile{context, [&](std::chrono::microseconds duration) {
+ write_to_debug_buffer(format("hook '{}({})' took {} us", hook_name, param, (size_t)duration.count()));
+ }};
bool hook_error = false;
for (auto& to_run : hooks_to_run)
@@ -171,13 +172,6 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
context.print_status({
format("Error running hooks for '{}' '{}', see *debug* buffer",
hook_name, param), context.faces()["Error"] });
-
- if (profile)
- {
- auto end_time = Clock::now();
- auto full = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
- write_to_debug_buffer(format("hook '{}({})' took {} us", hook_name, param, (size_t)full.count()));
- }
}
}