From da9a196fa0e08463265534fecd82e12dae3ce45a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 31 Mar 2021 17:17:22 +1100 Subject: Profile individual command runtime Different approach than the one suggested by eraserhd Closes $4095 --- src/command_manager.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index cb7ddf82..e1e11b52 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -508,9 +508,17 @@ void CommandManager::execute_single_command(CommandParameters params, if (command_it == m_commands.end()) throw command_not_found(params[0]); - const DebugFlags debug_flags = context.options()["debug"].get(); + auto debug_flags = context.options()["debug"].get(); + auto start = (debug_flags & DebugFlags::Profile) ? Clock::now() : Clock::time_point{}; if (debug_flags & DebugFlags::Commands) - write_to_debug_buffer(format("command {} {}", params[0], join(param_view, ' '))); + write_to_debug_buffer(format("command {}", join(params, ' '))); + + on_scope_end([&] { + 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())); + }); try { -- cgit v1.2.3