Coverage Report

Created: 2018-08-19 14:04

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/Common/Timer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Timer.cpp ----------------------------------------------------------===//
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
#include "lld/Common/Timer.h"
11
#include "lld/Common/ErrorHandler.h"
12
#include "llvm/Support/Format.h"
13
14
using namespace lld;
15
using namespace llvm;
16
17
3.76k
ScopedTimer::ScopedTimer(Timer &T) : T(&T) { T.start(); }
18
19
4.31k
void ScopedTimer::stop() {
20
4.31k
  if (!T)
21
545
    return;
22
3.76k
  T->stop();
23
3.76k
  T = nullptr;
24
3.76k
}
25
26
3.76k
ScopedTimer::~ScopedTimer() { stop(); }
27
28
3.20k
Timer::Timer(llvm::StringRef Name) : Name(Name), Parent(nullptr) {}
29
Timer::Timer(llvm::StringRef Name, Timer &Parent)
30
41.6k
    : Name(Name), Parent(&Parent) {}
31
32
3.76k
void Timer::start() {
33
3.76k
  if (Parent && 
Total.count() == 03.31k
)
34
2.40k
    Parent->Children.push_back(this);
35
3.76k
  StartTime = std::chrono::high_resolution_clock::now();
36
3.76k
}
37
38
4.17k
void Timer::stop() {
39
4.17k
  Total += (std::chrono::high_resolution_clock::now() - StartTime);
40
4.17k
}
41
42
23.2k
Timer &Timer::root() {
43
23.2k
  static Timer RootTimer("Total Link Time");
44
23.2k
  return RootTimer;
45
23.2k
}
46
47
0
void Timer::print() {
48
0
  double TotalDuration = static_cast<double>(root().millis());
49
0
50
0
  // We want to print the grand total under all the intermediate phases, so we
51
0
  // print all children first, then print the total under that.
52
0
  for (const auto &Child : Children)
53
0
    Child->print(1, TotalDuration);
54
0
55
0
  message(std::string(49, '-'));
56
0
57
0
  root().print(0, root().millis(), false);
58
0
}
59
60
0
double Timer::millis() const {
61
0
  return std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(
62
0
             Total)
63
0
      .count();
64
0
}
65
66
0
void Timer::print(int Depth, double TotalDuration, bool Recurse) const {
67
0
  double P = 100.0 * millis() / TotalDuration;
68
0
69
0
  SmallString<32> Str;
70
0
  llvm::raw_svector_ostream Stream(Str);
71
0
  std::string S = std::string(Depth * 2, ' ') + Name + std::string(":");
72
0
  Stream << format("%-30s%5d ms (%5.1f%%)", S.c_str(), (int)millis(), P);
73
0
74
0
  message(Str);
75
0
76
0
  if (Recurse) {
77
0
    for (const auto &Child : Children)
78
0
      Child->print(Depth + 1, TotalDuration);
79
0
  }
80
0
}