From e090131b8705124e8ab78de076f4e8f25ba7746e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 12 Aug 2023 13:06:53 +1000 Subject: Add a ProfileScope helper class to replace most profiling uses --- src/command_manager.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index e1b44888..68ea6c63 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -8,6 +8,7 @@ #include "file.hh" #include "optional.hh" #include "option_types.hh" +#include "profile.hh" #include "ranges.hh" #include "regex.hh" #include "register_manager.hh" @@ -525,12 +526,9 @@ void CommandManager::execute_single_command(CommandParameters params, if (debug_flags & DebugFlags::Commands) write_to_debug_buffer(format("command {}", join(params, ' '))); - auto profile = on_scope_end([&, start = (debug_flags & DebugFlags::Profile) ? Clock::now() : Clock::time_point{}] { - if (not (debug_flags & DebugFlags::Profile)) - return; - auto full = std::chrono::duration_cast(Clock::now() - start); - write_to_debug_buffer(format("command {} took {} us", params[0], full.count())); - }); + ProfileScope profile{debug_flags, [&](std::chrono::microseconds duration) { + write_to_debug_buffer(format("command {} took {} us", params[0], duration.count())); + }}; command_it->value.func({{params.begin()+1, params.end()}, command_it->value.param_desc}, context, shell_context); -- cgit v1.2.3