Coverage Report

Created: 2019-07-24 05:18

/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.55k
ScopedTimer::ScopedTimer(Timer &t) : t(&t) { t.start(); }
17
18
6.56k
void ScopedTimer::stop() {
19
6.56k
  if (!t)
20
1.01k
    return;
21
5.55k
  t->stop();
22
5.55k
  t = nullptr;
23
5.55k
}
24
25
5.55k
ScopedTimer::~ScopedTimer() { stop(); }
26
27
4.23k
Timer::Timer(llvm::StringRef name) : name(name), parent(nullptr) {}
28
Timer::Timer(llvm::StringRef name, Timer &parent)
29
55.0k
    : name(name), parent(&parent) {}
30
31
5.55k
void Timer::start() {
32
5.55k
  if (parent && 
total.count() == 04.87k
)
33
3.51k
    parent->children.push_back(this);
34
5.55k
  startTime = std::chrono::high_resolution_clock::now();
35
5.55k
}
36
37
6.12k
void Timer::stop() {
38
6.12k
  total += (std::chrono::high_resolution_clock::now() - startTime);
39
6.12k
}
40
41
30.8k
Timer &Timer::root() {
42
30.8k
  static Timer rootTimer("Total Link Time");
43
30.8k
  return rootTimer;
44
30.8k
}
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
}