summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2021-03-31 17:17:22 +1100
committerMaxime Coste <mawww@kakoune.org>2021-03-31 17:17:22 +1100
commitda9a196fa0e08463265534fecd82e12dae3ce45a (patch)
treec49a67da6715fed80ae95504c763135f4cf3e410 /src
parentd1e19727ff9d3ae9c90609e4b6a1671f43b15dd6 (diff)
Profile individual command runtime
Different approach than the one suggested by eraserhd Closes $4095
Diffstat (limited to 'src')
-rw-r--r--src/command_manager.cc12
1 files changed, 10 insertions, 2 deletions
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<DebugFlags>();
+ auto debug_flags = context.options()["debug"].get<DebugFlags>();
+ 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<std::chrono::microseconds>(Clock::now() - start);
+ write_to_debug_buffer(format("command {} took {} us", params[0], full.count()));
+ });
try
{