diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-08-12 13:06:53 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-08-13 03:57:46 +1000 |
| commit | e090131b8705124e8ab78de076f4e8f25ba7746e (patch) | |
| tree | b97a797e55dfdea7ef55196c259b214e71cc55ee /src/window.cc | |
| parent | e605ad8582d8e015806ed9b4d7aba8ca1ea13d57 (diff) | |
Add a ProfileScope helper class to replace most profiling uses
Diffstat (limited to 'src/window.cc')
| -rw-r--r-- | src/window.cc | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/window.cc b/src/window.cc index 7926183f..2a0469cf 100644 --- a/src/window.cc +++ b/src/window.cc @@ -10,6 +10,7 @@ #include "buffer_utils.hh" #include "option.hh" #include "option_types.hh" +#include "profile.hh" #include <algorithm> @@ -119,10 +120,10 @@ bool Window::needs_redraw(const Context& context) const const DisplayBuffer& Window::update_display_buffer(const Context& context) { - const bool profile = context.options()["debug"].get<DebugFlags>() & - DebugFlags::Profile; - - auto start_time = profile ? Clock::now() : Clock::time_point{}; + ProfileScope profile{context, [&](std::chrono::microseconds duration) { + write_to_debug_buffer(format("window display update for '{}' took {} us", + buffer().display_name(), (size_t)duration.count())); + }, not (buffer().flags() & Buffer::Flags::Debug)}; if (m_display_buffer.timestamp() != -1) { @@ -168,14 +169,6 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) set_position({setup.first_line, setup.first_column}); m_last_setup = build_setup(context); - if (profile and not (buffer().flags() & Buffer::Flags::Debug)) - { - using namespace std::chrono; - auto duration = duration_cast<microseconds>(Clock::now() - start_time); - write_to_debug_buffer(format("window display update for '{}' took {} us", - buffer().display_name(), (size_t)duration.count())); - } - return m_display_buffer; } |
