summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-05-16 18:15:51 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-05-16 18:15:51 +0000
commitddfefc3538f6e501e8dd62441546880ce4190695 (patch)
treec96d34834615a49d79a066a810596bc6edb2fd66 /llvm/lib/Support/Timer.cpp
parentc39ad98d80de35c58b506019cb6ca3b047e8bbb6 (diff)
downloadbcm5719-llvm-ddfefc3538f6e501e8dd62441546880ce4190695.tar.gz
bcm5719-llvm-ddfefc3538f6e501e8dd62441546880ce4190695.zip
[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
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
-rw-r--r--llvm/lib/Support/Timer.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index 9b8cd76fbfb..4dbc8ed034d 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/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
@@ -367,10 +369,12 @@ void TimerGroup::printAll(raw_ostream &OS) {
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) {
OpenPOWER on IntegriCloud