[PATCH] D46603: [Support] Print TimeRecord as CSV
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 8 14:44:51 PDT 2018
lebedev.ri created this revision.
lebedev.ri added reviewers: alexfh, sbenza, bkramer, george.karpenkov.
This is needed for the continuation of https://reviews.llvm.org/D46504,
to be able to store the timings as CSV.
The floating-point values are dumped with no precision loss.
See dependent differential https://reviews.llvm.org/D46602 for details/use-case.
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
@@ -169,6 +171,35 @@
OS << format("%9" PRId64 " ", (int64_t)getMemUsed());
}
+static void dumpVal(double Val, raw_ostream &OS) {
+ constexpr auto max_digits10 = std::numeric_limits<double>::max_digits10;
+ // FIXME: can ',' be a decimal separator?
+ OS << format("%.*e", max_digits10 - 1, Val);
+}
+
+void TimeRecord::printCSV(const TimeRecord &Total, raw_ostream &OS) const {
+ int Column = 0;
+ auto comma = [&Column, &OS]() {
+ if (Column)
+ OS << ','; // FIXME: can ',' be a decimal separator?
+ ++Column;
+ };
+ auto printColumn = [comma, &OS](bool Print, double Val) {
+ if (!Print)
+ return;
+ comma();
+ dumpVal(Val, OS);
+ };
+
+ printColumn(Total.getUserTime(), getUserTime());
+ printColumn(Total.getSystemTime(), getSystemTime());
+ printColumn(Total.getProcessTime(), getProcessTime());
+ printColumn(true, getWallTime());
+ if (Total.getMemUsed()) {
+ comma();
+ OS << format("%9" PRId64, (int64_t)getMemUsed());
+ }
+}
//===----------------------------------------------------------------------===//
// NamedRegionTimer Implementation
Index: include/llvm/Support/Timer.h
===================================================================
--- include/llvm/Support/Timer.h
+++ include/llvm/Support/Timer.h
@@ -64,6 +64,10 @@
/// Print the current time record to \p OS, with a breakdown showing
/// contributions to the \p Total time record.
void print(const TimeRecord &Total, raw_ostream &OS) const;
+
+ /// Print the current time record to \p OS as CSV, with full precision.
+ /// Only the values in this timer are printed, no percentages.
+ void printCSV(const TimeRecord &Total, raw_ostream &OS) const;
};
/// This class is used to track the amount of time spent between invocations of
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46603.145789.patch
Type: text/x-patch
Size: 2186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180508/87e0ee68/attachment.bin>
More information about the cfe-commits
mailing list