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
#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:

View File

@ -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{};

View File

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

View File

@ -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()));
}