Coverage Report

Created: 2019-05-19 14:56

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