summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
blob: d332942fa24b7e437d1b1075a630cb702e579f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//===--- ClangTidyProfiling.cpp - clang-tidy --------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ClangTidyProfiling.h"
#include "llvm/ADT/STLExtras.h"

#define DEBUG_TYPE "clang-tidy-profiling"

namespace clang {
namespace tidy {

void ClangTidyProfiling::preprocess() {
  // Convert from a insertion-friendly map to sort-friendly vector.
  Timers.clear();
  Timers.reserve(Records.size());
  for (const auto &P : Records) {
    Timers.emplace_back(P.getValue(), P.getKey());
    Total += P.getValue();
  }
  assert(Timers.size() == Records.size() && "Size mismatch after processing");

  // We want the measurements to be sorted by decreasing time spent.
  llvm::sort(Timers.begin(), Timers.end());
}

void ClangTidyProfiling::printProfileData(llvm::raw_ostream &OS) const {
  std::string Line = "===" + std::string(73, '-') + "===\n";
  OS << Line;

  if (Total.getUserTime())
    OS << "   ---User Time---";
  if (Total.getSystemTime())
    OS << "   --System Time--";
  if (Total.getProcessTime())
    OS << "   --User+System--";
  OS << "   ---Wall Time---";
  if (Total.getMemUsed())
    OS << "  ---Mem---";
  OS << "  --- Name ---\n";

  // Loop through all of the timing data, printing it out.
  for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
    I->first.print(Total, OS);
    OS << I->second << '\n';
  }

  Total.print(Total, OS);
  OS << "Total\n";
  OS << Line << "\n";
  OS.flush();
}

ClangTidyProfiling::~ClangTidyProfiling() {
  preprocess();
  printProfileData(llvm::errs());
}

} // namespace tidy
} // namespace clang
OpenPOWER on IntegriCloud