blob: 6654af626919218f890d129e098c1b02aaf70931 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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
20namespace lld {
21
22class Timer;
23
24struct ScopedTimer {
25 explicit ScopedTimer(Timer &T);
26
27 ~ScopedTimer();
28
29 void stop();
30
31 Timer *T = nullptr;
32};
33
34class Timer {
35public:
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
46private:
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