]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lld/include/lld/Common/Timer.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lld / include / lld / Common / Timer.h
1 //===- Timer.h ----------------------------------------------*- C++ -*-===//
2 //
3 // 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
6 //
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
19 namespace lld {
20
21 class Timer;
22
23 struct ScopedTimer {
24   explicit ScopedTimer(Timer &t);
25
26   ~ScopedTimer();
27
28   void stop();
29
30   Timer *t = nullptr;
31 };
32
33 class Timer {
34 public:
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
45 private:
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