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 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 + 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::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