[Timers] TimerGroup::printJSONValue(): print doubles with no precision loss

Summary:
Although this is not stricly required, i would very much prefer
not to have known random precision losses along the way.

Reviewers: george.karpenkov, NoQ, alexfh, sbenza

Reviewed By: george.karpenkov

Subscribers: llvm-commits, cfe-commits

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

llvm-svn: 332504
This commit is contained in:
Roman Lebedev 2018-05-16 18:15:51 +00:00
parent c39ad98d80
commit ddfefc3538
1 changed files with 7 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#include "llvm/Support/Process.h" #include "llvm/Support/Process.h"
#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <limits>
using namespace llvm; using namespace llvm;
// This ugly hack is brought to you courtesy of constructor/destructor ordering // This ugly hack is brought to you courtesy of constructor/destructor ordering
@ -367,10 +369,12 @@ void TimerGroup::printAll(raw_ostream &OS) {
void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R, void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
const char *suffix, double Value) { const char *suffix, double Value) {
assert(yaml::needsQuotes(Name) == yaml::QuotingType::None && 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 && assert(yaml::needsQuotes(R.Name) == yaml::QuotingType::None &&
"Timer name needs no quotes"); "Timer name should not need quotes");
OS << "\t\"time." << Name << '.' << R.Name << suffix << "\": " << Value; 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) { const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {