blob: e2b69510a0b9dfc68d9d1c38fedb49c8ac2fe440 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- Timer.h ----------------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLD_COMMON_TIMER_H
10#define LLD_COMMON_TIMER_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/StringRef.h"
14#include <assert.h>
15#include <chrono>
16#include <map>
17#include <memory>
18
19namespace lld {
20
21class Timer;
22
23struct ScopedTimer {
24 explicit ScopedTimer(Timer &T);
25
26 ~ScopedTimer();
27
28 void stop();
29
30 Timer *T = nullptr;
31};
32
33class Timer {
34public:
35 Timer(llvm::StringRef Name, Timer &Parent);
36
37 static Timer &root();
38
39 void start();
40 void stop();
41 void print();
42
43 double millis() const;
44
45private:
46 explicit Timer(llvm::StringRef Name);
47 void print(int Depth, double TotalDuration, bool Recurse = true) const;
48
49 std::chrono::time_point<std::chrono::high_resolution_clock> StartTime;
50 std::chrono::nanoseconds Total;
51 std::vector<Timer *> Children;
52 std::string Name;
53 Timer *Parent;
54};
55
56} // namespace lld
57
58#endif