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
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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits