diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-07-20 08:49:04 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-07-24 21:25:05 +0100 |
| commit | 46a15534c5d012908eee4975a21dd0d53179b2b3 (patch) | |
| tree | 6a2879d7601b6e6ef109c462b0338bcabe51a35f /src | |
| parent | e391f93a9e1dbf7e087a34bd0b040ef348cce506 (diff) | |
Introduce chrono.hh
Diffstat (limited to 'src')
| -rw-r--r-- | src/clock.hh | 14 | ||||
| -rw-r--r-- | src/event_manager.hh | 5 | ||||
| -rw-r--r-- | src/hook_manager.cc | 6 | ||||
| -rw-r--r-- | src/shell_manager.cc | 14 | ||||
| -rw-r--r-- | src/window.cc | 9 |
5 files changed, 26 insertions, 22 deletions
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 <chrono> + +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 <chrono> #include <functional> #include <sys/select.h> @@ -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 <chrono> - 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<DebugFlags>(); 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 <chrono> - #include <cstring> #include <sys/types.h> #include <sys/wait.h> @@ -115,18 +114,16 @@ std::pair<String, int> 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<DebugFlags>(); 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<String, int> 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<String, int> ShellManager::eval( if (profile) { - auto end_time = steady_clock::now(); + using namespace std::chrono; + auto end_time = Clock::now(); auto full = duration_cast<milliseconds>(end_time - start_time); auto spawn = duration_cast<milliseconds>(wait_time - spawn_time); auto wait = duration_cast<milliseconds>(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 <algorithm> -#include <chrono> #include <sstream> 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>() & 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<milliseconds>(steady_clock::now() - start_time); + using namespace std::chrono; + auto duration = duration_cast<milliseconds>(Clock::now() - start_time); write_to_debug_buffer(format("window display update for '{}' took {} ms", buffer().display_name(), (size_t)duration.count())); } |
