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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 16 04:58:49 PDT 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: george.karpenkov, NoQ, alexfh, sbenza.
Herald added a subscriber: llvm-commits.
lebedev.ri added a dependent revision: D46938: [Timers] TimerGroup: make printJSONValues() method public.
lebedev.ri added a dependency: D46936: [Timers] TimerGroup::printJSONValues(): print mem timer with .mem suffix.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D46937

Files:
  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
@@ -367,10 +369,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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46937.147053.patch
Type: text/x-patch
Size: 1239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180516/e76d7c1e/attachment.bin>


More information about the llvm-commits mailing list