[Timers] TimerGroup: add constructor from StringMap<TimeRecord>

Summary:
This is needed for the continuation of D46504,
to be able to store the timings.

Reviewers: george.karpenkov, NoQ, alexfh, sbenza

Reviewed By: alexfh

Subscribers: llvm-commits, cfe-commits

Differential Revision: https://reviews.llvm.org/D46939

llvm-svn: 332506
This commit is contained in:
Roman Lebedev 2018-05-16 18:16:01 +00:00
parent e01f705d97
commit 8f67a027ed
2 changed files with 14 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#ifndef LLVM_SUPPORT_TIMER_H
#define LLVM_SUPPORT_TIMER_H
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
@ -194,6 +195,10 @@ class TimerGroup {
public:
explicit TimerGroup(StringRef Name, StringRef Description);
explicit TimerGroup(StringRef Name, StringRef Description,
const StringMap<TimeRecord> &Records);
~TimerGroup();
void setName(StringRef NewName, StringRef NewDescription) {

View File

@ -236,6 +236,15 @@ TimerGroup::TimerGroup(StringRef Name, StringRef Description)
TimerGroupList = this;
}
TimerGroup::TimerGroup(StringRef Name, StringRef Description,
const StringMap<TimeRecord> &Records)
: TimerGroup(Name, Description) {
TimersToPrint.reserve(Records.size());
for (const auto &P : Records)
TimersToPrint.emplace_back(P.getValue(), P.getKey(), P.getKey());
assert(TimersToPrint.size() == Records.size() && "Size mismatch");
}
TimerGroup::~TimerGroup() {
// If the timer group is destroyed before the timers it owns, accumulate and
// print the timing data.