From 457e11bdc904555edddaa2956236e56ae4cd5971 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 6 May 2016 00:24:54 +0100 Subject: [PATCH] time window display buffer update in debug profile mode --- src/shell_manager.cc | 17 ++++++++--------- src/window.cc | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index cfc364cd..e0345e36 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -115,19 +115,18 @@ std::pair ShellManager::eval( StringView cmdline, const Context& context, StringView input, Flags flags, const ShellContext& shell_context) { - using Clock = std::chrono::steady_clock; - using TimePoint = Clock::time_point; + using namespace std::chrono; const DebugFlags debug_flags = context.options()["debug"].get(); const bool profile = debug_flags & DebugFlags::Profile; if (debug_flags & DebugFlags::Shell) write_to_debug_buffer(format("shell:\n{}\n----\n", cmdline)); - auto start_time = profile ? Clock::now() : TimePoint{}; + auto start_time = profile ? steady_clock::now() : steady_clock::time_point{}; auto kak_env = generate_env(cmdline, context, shell_context); - auto spawn_time = profile ? Clock::now() : TimePoint{}; + auto spawn_time = profile ? steady_clock::now() : steady_clock::time_point{}; Pipe child_stdin{not input.empty()}, child_stdout, child_stderr; pid_t pid = spawn_shell(cmdline, shell_context.params, kak_env, @@ -154,7 +153,7 @@ std::pair ShellManager::eval( write(child_stdin.write_fd(), input); child_stdin.close_write_fd(); - auto wait_time = profile ? Clock::now() : TimePoint{}; + auto wait_time = profile ? steady_clock::now() : steady_clock::time_point{}; struct PipeReader : FDWatcher { @@ -204,10 +203,10 @@ std::pair ShellManager::eval( if (profile) { - TimePoint end_time = Clock::now(); - auto full = std::chrono::duration_cast(end_time - start_time); - auto spawn = std::chrono::duration_cast(wait_time - spawn_time); - auto wait = std::chrono::duration_cast(end_time - wait_time); + auto end_time = steady_clock::now(); + auto full = duration_cast(end_time - start_time); + auto spawn = duration_cast(wait_time - spawn_time); + auto wait = duration_cast(end_time - wait_time); write_to_debug_buffer(format("shell execution took {} ms (spawn: {}, wait: {})", (size_t)full.count(), (size_t)spawn.count(), (size_t)wait.count())); } diff --git a/src/window.cc b/src/window.cc index c80c1e61..6dea389c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -6,8 +6,10 @@ #include "hook_manager.hh" #include "input_handler.hh" #include "client.hh" +#include "buffer_utils.hh" #include +#include #include namespace Kakoune @@ -108,6 +110,13 @@ bool Window::needs_redraw(const Context& context) const const DisplayBuffer& Window::update_display_buffer(const Context& context) { + using namespace std::chrono; + + const bool profile = context.options()["debug"].get() & + DebugFlags::Profile; + + auto start_time = profile ? steady_clock::now() : steady_clock::time_point{}; + DisplayBuffer::LineList& lines = m_display_buffer.lines(); lines.clear(); @@ -138,6 +147,13 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) m_last_setup = build_setup(context); + if (profile and not (buffer().flags() & Buffer::Flags::Debug)) + { + auto duration = duration_cast(steady_clock::now() - start_time); + write_to_debug_buffer(format("window display update for '{}' took {} ms", + buffer().display_name(), (size_t)duration.count())); + } + return m_display_buffer; }