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 <chrono>
15#include <optional>
16
17#include <llvm/Support/TimeProfiler.h>
18
19#include "proteus/Config.hpp"
20
21namespace proteus {
22
23using namespace llvm;
24
25using TimeTraceOptional = std::optional<TimeTraceScope>;
26
29 if (Config::get().ProteusEnableTimeTrace) {
30 timeTraceProfilerInitialize(500 /* us */, "proteus");
31 }
32 }
33
35 if (Config::get().ProteusEnableTimeTrace) {
37 if (auto E = timeTraceProfilerWrite(OutputFile, "-")) {
38 handleAllErrors(std::move(E));
39 return;
40 }
42 }
43 }
44};
45
46class Timer {
47 using Clock = std::chrono::steady_clock;
48
49public:
51 if (Config::get().ProteusEnableTimers)
52 Start = Clock::now();
53 }
54
56 return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() -
57 Start)
58 .count();
59 }
60
61 void reset() { Start = Clock::now(); }
62
63private:
64 Clock::time_point Start;
65};
66
67#define PROTEUS_TIMER_OUTPUT(x) \
68 if (Config::get().ProteusEnableTimers) \
69 x;
70
71#define TIMESCOPE(x) \
72 TimeTraceOptional TTS; \
73 if (Config::get().ProteusEnableTimeTrace) { \
74 TTS.emplace(x); \
75 }
76
77} // namespace proteus
78
79#endif
static Config & get()
Definition Config.hpp:298
std::string ProteusTimeTraceFile
Definition Config.hpp:318
Definition TimeTracing.hpp:46
Timer()
Definition TimeTracing.hpp:50
void reset()
Definition TimeTracing.hpp:61
uint64_t elapsed()
Definition TimeTracing.hpp:55
Definition Helpers.h:142
Definition ObjectCacheChain.cpp:25
T getRuntimeConstantValue(void *Arg)
Definition CompilerInterfaceRuntimeConstantInfo.h:114
std::optional< TimeTraceScope > TimeTraceOptional
Definition TimeTracing.hpp:25
Definition TimeTracing.hpp:27
TimeTracerRAII()
Definition TimeTracing.hpp:28
~TimeTracerRAII()
Definition TimeTracing.hpp:34