]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/include/lld/Common/Timer.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / include / lld / Common / Timer.h
1 //===- Timer.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_COMMON_TIMER_H
11 #define LLD_COMMON_TIMER_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include <assert.h>
16 #include <chrono>
17 #include <map>
18 #include <memory>
19
20 namespace lld {
21
22 class Timer;
23
24 struct ScopedTimer {
25   explicit ScopedTimer(Timer &T);
26
27   ~ScopedTimer();
28
29   void stop();
30
31   Timer *T = nullptr;
32 };
33
34 class Timer {
35 public:
36   Timer(llvm::StringRef Name, Timer &Parent);
37
38   static Timer &root();
39
40   void start();
41   void stop();
42   void print();
43
44   double millis() const;
45
46 private:
47   explicit Timer(llvm::StringRef Name);
48   void print(int Depth, double TotalDuration, bool Recurse = true) const;
49
50   std::chrono::time_point<std::chrono::high_resolution_clock> StartTime;
51   std::chrono::nanoseconds Total;
52   std::vector<Timer *> Children;
53   std::string Name;
54   Timer *Parent;
55 };
56
57 } // namespace lld
58
59 #endif