Introduce chrono.hh

This commit is contained in:
Maxime Coste 2016-07-20 08:49:04 +01:00
parent e391f93a9e
commit 46a15534c5
5 changed files with 26 additions and 22 deletions

14
src/clock.hh Normal file
View File

@ -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

View File

@ -1,11 +1,11 @@
#ifndef event_manager_hh_INCLUDED #ifndef event_manager_hh_INCLUDED
#define event_manager_hh_INCLUDED #define event_manager_hh_INCLUDED
#include "clock.hh"
#include "utils.hh" #include "utils.hh"
#include "flags.hh" #include "flags.hh"
#include "vector.hh" #include "vector.hh"
#include <chrono>
#include <functional> #include <functional>
#include <sys/select.h> #include <sys/select.h>
@ -41,9 +41,6 @@ private:
Callback m_callback; Callback m_callback;
}; };
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
class Timer class Timer
{ {
public: public:

View File

@ -1,5 +1,6 @@
#include "hook_manager.hh" #include "hook_manager.hh"
#include "clock.hh"
#include "containers.hh" #include "containers.hh"
#include "context.hh" #include "context.hh"
#include "buffer_utils.hh" #include "buffer_utils.hh"
@ -7,8 +8,6 @@
#include "face_registry.hh" #include "face_registry.hh"
#include "regex.hh" #include "regex.hh"
#include <chrono>
namespace Kakoune namespace Kakoune
{ {
@ -61,9 +60,6 @@ void HookManager::run_hook(StringView hook_name,
m_running_hooks.emplace_back(hook_name, param); m_running_hooks.emplace_back(hook_name, param);
auto pop_running_hook = on_scope_end([this]{ m_running_hooks.pop_back(); }); 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 DebugFlags debug_flags = context.options()["debug"].get<DebugFlags>();
const bool profile = debug_flags & DebugFlags::Profile; const bool profile = debug_flags & DebugFlags::Profile;
auto start_time = profile ? Clock::now() : TimePoint{}; auto start_time = profile ? Clock::now() : TimePoint{};

View File

@ -1,12 +1,11 @@
#include "shell_manager.hh" #include "shell_manager.hh"
#include "clock.hh"
#include "context.hh" #include "context.hh"
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include "event_manager.hh" #include "event_manager.hh"
#include "file.hh" #include "file.hh"
#include <chrono>
#include <cstring> #include <cstring>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -115,18 +114,16 @@ 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 namespace std::chrono;
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 ? 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 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; 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,
@ -153,7 +150,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 ? steady_clock::now() : steady_clock::time_point{}; auto wait_time = profile ? Clock::now() : Clock::time_point{};
struct PipeReader : FDWatcher struct PipeReader : FDWatcher
{ {
@ -203,7 +200,8 @@ std::pair<String, int> ShellManager::eval(
if (profile) 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 full = duration_cast<milliseconds>(end_time - start_time);
auto spawn = duration_cast<milliseconds>(wait_time - spawn_time); auto spawn = duration_cast<milliseconds>(wait_time - spawn_time);
auto wait = duration_cast<milliseconds>(end_time - wait_time); auto wait = duration_cast<milliseconds>(end_time - wait_time);

View File

@ -1,6 +1,7 @@
#include "window.hh" #include "window.hh"
#include "assert.hh" #include "assert.hh"
#include "clock.hh"
#include "context.hh" #include "context.hh"
#include "highlighter.hh" #include "highlighter.hh"
#include "hook_manager.hh" #include "hook_manager.hh"
@ -9,7 +10,6 @@
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include <algorithm> #include <algorithm>
#include <chrono>
#include <sstream> #include <sstream>
namespace Kakoune namespace Kakoune
@ -109,12 +109,10 @@ 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>() & const bool profile = context.options()["debug"].get<DebugFlags>() &
DebugFlags::Profile; 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(); DisplayBuffer::LineList& lines = m_display_buffer.lines();
lines.clear(); lines.clear();
@ -147,7 +145,8 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
if (profile and not (buffer().flags() & Buffer::Flags::Debug)) 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", write_to_debug_buffer(format("window display update for '{}' took {} ms",
buffer().display_name(), (size_t)duration.count())); buffer().display_name(), (size_t)duration.count()));
} }