Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
TimeTracing.hpp
Go to the documentation of this file.
1//===-- TimeTracing.hpp -- Time tracing helpers --===//
2//
3// Part of the Proteus Project, under the Apache License v2.0 with LLVM
4// Exceptions. See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef PROTEUS_TIME_TRACING_HPP
12#define PROTEUS_TIME_TRACING_HPP
13
14#include <llvm/Support/TimeProfiler.h>
15
16#include <chrono>
17
18#include "proteus/Config.hpp"
19
20namespace proteus {
21
22using namespace llvm;
23
25 TimeTracerRAII() { timeTraceProfilerInitialize(500 /* us */, "jit"); }
26
28 if (auto E = timeTraceProfilerWrite("", "-")) {
29 handleAllErrors(std::move(E));
30 return;
31 }
32 timeTraceProfilerCleanup();
33 }
34};
35
36class Timer {
37 using Clock = std::chrono::steady_clock;
38
39public:
41 if (Config::get().ProteusEnableTimers)
42 Start = Clock::now();
43 }
44
45 uint64_t elapsed() {
46 return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() -
47 Start)
48 .count();
49 }
50
51 void reset() { Start = Clock::now(); }
52
53private:
54 Clock::time_point Start;
55};
56
57#define PROTEUS_TIMER_OUTPUT(x) \
58 if (Config::get().ProteusEnableTimers) \
59 x;
60
61#if PROTEUS_ENABLE_TIME_TRACING
62#define TIMESCOPE(x) TimeTraceScope TTS(x);
63#else
64#define TIMESCOPE(x)
65#endif
66
67} // namespace proteus
68
69#endif
static Config & get()
Definition Config.hpp:112
Definition TimeTracing.hpp:36
Timer()
Definition TimeTracing.hpp:40
void reset()
Definition TimeTracing.hpp:51
uint64_t elapsed()
Definition TimeTracing.hpp:45
Definition Dispatcher.cpp:14
Definition TimeTracing.hpp:24
TimeTracerRAII()
Definition TimeTracing.hpp:25
~TimeTracerRAII()
Definition TimeTracing.hpp:27