time window display buffer update in debug profile mode

This commit is contained in:
Maxime Coste 2016-05-06 00:24:54 +01:00
parent bab174b0ec
commit 457e11bdc9
2 changed files with 24 additions and 9 deletions

View File

@ -115,19 +115,18 @@ std::pair<String, int> ShellManager::eval(
StringView cmdline, const Context& context, StringView input, StringView cmdline, const Context& context, StringView input,
Flags flags, const ShellContext& shell_context) Flags flags, const ShellContext& shell_context)
{ {
using Clock = std::chrono::steady_clock; using namespace std::chrono;
using TimePoint = Clock::time_point;
const DebugFlags debug_flags = context.options()["debug"].get<DebugFlags>(); const DebugFlags debug_flags = context.options()["debug"].get<DebugFlags>();
const bool profile = debug_flags & DebugFlags::Profile; const bool profile = debug_flags & DebugFlags::Profile;
if (debug_flags & DebugFlags::Shell) if (debug_flags & DebugFlags::Shell)
write_to_debug_buffer(format("shell:\n{}\n----\n", cmdline)); 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 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; Pipe child_stdin{not input.empty()}, child_stdout, child_stderr;
pid_t pid = spawn_shell(cmdline, shell_context.params, kak_env, pid_t pid = spawn_shell(cmdline, shell_context.params, kak_env,
@ -154,7 +153,7 @@ std::pair<String, int> ShellManager::eval(
write(child_stdin.write_fd(), input); write(child_stdin.write_fd(), input);
child_stdin.close_write_fd(); 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 struct PipeReader : FDWatcher
{ {
@ -204,10 +203,10 @@ std::pair<String, int> ShellManager::eval(
if (profile) if (profile)
{ {
TimePoint end_time = Clock::now(); auto end_time = steady_clock::now();
auto full = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time); auto full = duration_cast<milliseconds>(end_time - start_time);
auto spawn = std::chrono::duration_cast<std::chrono::milliseconds>(wait_time - spawn_time); auto spawn = duration_cast<milliseconds>(wait_time - spawn_time);
auto wait = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - wait_time); auto wait = duration_cast<milliseconds>(end_time - wait_time);
write_to_debug_buffer(format("shell execution took {} ms (spawn: {}, wait: {})", write_to_debug_buffer(format("shell execution took {} ms (spawn: {}, wait: {})",
(size_t)full.count(), (size_t)spawn.count(), (size_t)wait.count())); (size_t)full.count(), (size_t)spawn.count(), (size_t)wait.count()));
} }

View File

@ -6,8 +6,10 @@
#include "hook_manager.hh" #include "hook_manager.hh"
#include "input_handler.hh" #include "input_handler.hh"
#include "client.hh" #include "client.hh"
#include "buffer_utils.hh"
#include <algorithm> #include <algorithm>
#include <chrono>
#include <sstream> #include <sstream>
namespace Kakoune namespace Kakoune
@ -108,6 +110,13 @@ bool Window::needs_redraw(const Context& context) const
const DisplayBuffer& Window::update_display_buffer(const Context& context) const DisplayBuffer& Window::update_display_buffer(const Context& context)
{ {
using namespace std::chrono;
const bool profile = context.options()["debug"].get<DebugFlags>() &
DebugFlags::Profile;
auto start_time = profile ? steady_clock::now() : steady_clock::time_point{};
DisplayBuffer::LineList& lines = m_display_buffer.lines(); DisplayBuffer::LineList& lines = m_display_buffer.lines();
lines.clear(); lines.clear();
@ -138,6 +147,13 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
m_last_setup = build_setup(context); m_last_setup = build_setup(context);
if (profile and not (buffer().flags() & Buffer::Flags::Debug))
{
auto duration = duration_cast<milliseconds>(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; return m_display_buffer;
} }