[PATCH] D46603: [Support] TimerGroup changes
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 9 05:41:47 PDT 2018
lebedev.ri updated this revision to Diff 145900.
lebedev.ri retitled this revision from "[Support] Print TimeRecord as CSV" to "[Support] TimerGroup changes".
lebedev.ri edited the summary of this revision.
lebedev.ri added a reviewer: NoQ.
lebedev.ri added subscribers: xazax.hun, szepet, a.sidorin.
lebedev.ri added a comment.
1. Drop CSV stuff
2. Add constructor from previously-collected `StringMap<TimeRecord>`
3. Make `printJSONValues()` public.
4. Dump floating-point values in scientific format with full precision.
Repository:
rL LLVM
https://reviews.llvm.org/D46603
Files:
include/llvm/Support/Timer.h
lib/Support/Timer.cpp
Index: lib/Support/Timer.cpp
===================================================================
--- lib/Support/Timer.cpp
+++ lib/Support/Timer.cpp
@@ -22,6 +22,8 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
+#include <limits>
+
using namespace llvm;
// This ugly hack is brought to you courtesy of constructor/destructor ordering
@@ -234,6 +236,15 @@
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.
@@ -367,10 +378,12 @@
void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
const char *suffix, double Value) {
assert(yaml::needsQuotes(Name) == yaml::QuotingType::None &&
- "TimerGroup name needs no quotes");
+ "TimerGroup name should not need quotes");
assert(yaml::needsQuotes(R.Name) == yaml::QuotingType::None &&
- "Timer name needs no quotes");
- OS << "\t\"time." << Name << '.' << R.Name << suffix << "\": " << Value;
+ "Timer name should not need quotes");
+ constexpr auto max_digits10 = std::numeric_limits<double>::max_digits10;
+ OS << "\t\"time." << Name << '.' << R.Name << suffix
+ << "\": " << format("%.*e", max_digits10 - 1, Value);
}
const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {
Index: include/llvm/Support/Timer.h
===================================================================
--- include/llvm/Support/Timer.h
+++ include/llvm/Support/Timer.h
@@ -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 @@
public:
explicit TimerGroup(StringRef Name, StringRef Description);
+
+ explicit TimerGroup(StringRef Name, StringRef Description,
+ const StringMap<TimeRecord> &Records);
+
~TimerGroup();
void setName(StringRef NewName, StringRef NewDescription) {
@@ -207,6 +212,8 @@
/// This static method prints all timers and clears them all out.
static void printAll(raw_ostream &OS);
+ const char *printJSONValues(raw_ostream &OS, const char *delim);
+
/// Prints all timers as JSON key/value pairs, and clears them all out.
static const char *printAllJSONValues(raw_ostream &OS, const char *delim);
@@ -223,7 +230,6 @@
void PrintQueuedTimers(raw_ostream &OS);
void printJSONValue(raw_ostream &OS, const PrintRecord &R,
const char *suffix, double Value);
- const char *printJSONValues(raw_ostream &OS, const char *delim);
};
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46603.145900.patch
Type: text/x-patch
Size: 3134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180509/d465cb3e/attachment.bin>
More information about the cfe-commits
mailing list