From 46a15534c5d012908eee4975a21dd0d53179b2b3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 20 Jul 2016 08:49:04 +0100 Subject: [PATCH] Introduce chrono.hh --- src/clock.hh | 14 ++++++++++++++ src/event_manager.hh | 5 +---- src/hook_manager.cc | 6 +----- src/shell_manager.cc | 14 ++++++-------- src/window.cc | 9 ++++----- 5 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 src/clock.hh diff --git a/src/clock.hh b/src/clock.hh new file mode 100644 index 00000000..b4138de0 --- /dev/null +++ b/src/clock.hh @@ -0,0 +1,14 @@ +#ifndef clock_hh_INCLUDED +#define clock_hh_INCLUDED + +#include + +namespace Kakoune +{ + +using Clock = std::chrono::steady_clock; +using TimePoint = Clock::time_point; + +} + +#endif // clock_hh_INCLUDED diff --git a/src/event_manager.hh b/src/event_manager.hh index 81bfc508..3c1567c9 100644 --- a/src/event_manager.hh +++ b/src/event_manager.hh @@ -1,11 +1,11 @@ #ifndef event_manager_hh_INCLUDED #define event_manager_hh_INCLUDED +#include "clock.hh" #include "utils.hh" #include "flags.hh" #include "vector.hh" -#include #include #include @@ -41,9 +41,6 @@ private: Callback m_callback; }; -using Clock = std::chrono::steady_clock; -using TimePoint = Clock::time_point; - class Timer { public: diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 30f90ae3..be940482 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -1,5 +1,6 @@ #include "hook_manager.hh" +#include "clock.hh" #include "containers.hh" #include "context.hh" #include "buffer_utils.hh" @@ -7,8 +8,6 @@ #include "face_registry.hh" #include "regex.hh" -#include - namespace Kakoune { @@ -61,9 +60,6 @@ void HookManager::run_hook(StringView hook_name, m_running_hooks.emplace_back(hook_name, param); auto pop_running_hook = on_scope_end([this]{ m_running_hooks.pop_back(); }); - using Clock = std::chrono::steady_clock; - using TimePoint = Clock::time_point; - const DebugFlags debug_flags = context.options()["debug"].get(); const bool profile = debug_flags & DebugFlags::Profile; auto start_time = profile ? Clock::now() : TimePoint{}; diff --git a/src/shell_manager.cc b/src/shell_manager.cc index e0345e36..01ff1db2 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -1,12 +1,11 @@ #include "shell_manager.hh" +#include "clock.hh" #include "context.hh" #include "buffer_utils.hh" #include "event_manager.hh" #include "file.hh" -#include - #include #include #include @@ -115,18 +114,16 @@ std::pair ShellManager::eval( StringView cmdline, const Context& context, StringView input, Flags flags, const ShellContext& shell_context) { - 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 ? steady_clock::now() : steady_clock::time_point{}; + auto start_time = profile ? Clock::now() : Clock::time_point{}; auto kak_env = generate_env(cmdline, context, shell_context); - auto spawn_time = profile ? steady_clock::now() : steady_clock::time_point{}; + auto spawn_time = profile ? Clock::now() : Clock::time_point{}; Pipe child_stdin{not input.empty()}, child_stdout, child_stderr; pid_t pid = spawn_shell(cmdline, shell_context.params, kak_env, @@ -153,7 +150,7 @@ std::pair ShellManager::eval( write(child_stdin.write_fd(), input); child_stdin.close_write_fd(); - auto wait_time = profile ? steady_clock::now() : steady_clock::time_point{}; + auto wait_time = profile ? Clock::now() : Clock::time_point{}; struct PipeReader : FDWatcher { @@ -203,7 +200,8 @@ std::pair ShellManager::eval( if (profile) { - auto end_time = steady_clock::now(); + using namespace std::chrono; + auto end_time = 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); diff --git a/src/window.cc b/src/window.cc index de3f4ea4..efffe1e1 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1,6 +1,7 @@ #include "window.hh" #include "assert.hh" +#include "clock.hh" #include "context.hh" #include "highlighter.hh" #include "hook_manager.hh" @@ -9,7 +10,6 @@ #include "buffer_utils.hh" #include -#include #include namespace Kakoune @@ -109,12 +109,10 @@ 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{}; + auto start_time = profile ? Clock::now() : Clock::time_point{}; DisplayBuffer::LineList& lines = m_display_buffer.lines(); lines.clear(); @@ -147,7 +145,8 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) if (profile and not (buffer().flags() & Buffer::Flags::Debug)) { - auto duration = duration_cast(steady_clock::now() - start_time); + using namespace std::chrono; + auto duration = duration_cast(Clock::now() - start_time); write_to_debug_buffer(format("window display update for '{}' took {} ms", buffer().display_name(), (size_t)duration.count())); }