From 3b40e53cff86a8e3d381bc994c4aea765ce90057 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Sun, 7 Jul 2019 20:55:17 +0300 Subject: [PATCH] [HIPIFY] Statistics to CSV file dumping revise + Add option -print-stats-csv to dump statistics to CSV file + If -o-dir is specified, CSV file will be dumped there + Generate 1 summary file sum_stat.csv in case of multiple sources --- hipify-clang/src/ArgParse.cpp | 5 +++++ hipify-clang/src/ArgParse.h | 1 + hipify-clang/src/main.cpp | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/hipify-clang/src/ArgParse.cpp b/hipify-clang/src/ArgParse.cpp index 28859c278b..60b0dd390b 100644 --- a/hipify-clang/src/ArgParse.cpp +++ b/hipify-clang/src/ArgParse.cpp @@ -104,6 +104,11 @@ cl::opt PrintStats("print-stats", cl::value_desc("print-stats"), cl::cat(ToolTemplateCategory)); +cl::opt PrintStatsCSV("print-stats-csv", + cl::desc("Print translation statistics in CSV file"), + cl::value_desc("print-stats-csv"), + cl::cat(ToolTemplateCategory)); + cl::opt OutputStatsFilename("o-stats", cl::desc("Output filename for statistics"), cl::value_desc("filename"), diff --git a/hipify-clang/src/ArgParse.h b/hipify-clang/src/ArgParse.h index 04ba48f004..5b8c763647 100644 --- a/hipify-clang/src/ArgParse.h +++ b/hipify-clang/src/ArgParse.h @@ -46,6 +46,7 @@ extern cl::opt Verbose; extern cl::opt NoBackup; extern cl::opt NoOutput; extern cl::opt PrintStats; +extern cl::opt PrintStatsCSV; extern cl::opt OutputStatsFilename; extern cl::opt Examine; extern cl::extrahelp CommonHelp; diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index 368d21a3d4..0edc9d2681 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -291,7 +291,7 @@ int main(int argc, const char **argv) { } int Result = 0; SmallString<128> tmpFile; - StringRef sourceFileName, ext = "hip"; + StringRef sourceFileName, ext = "hip", csv_ext = "csv"; std::string sTmpFileName, sSourceAbsPath; std::string sTmpDirAbsParh = getAbsoluteDirectoryPath(TemporaryDir, EC); if (EC) { @@ -300,7 +300,20 @@ int main(int argc, const char **argv) { // Arguments for the Statistics print routines. std::unique_ptr csv = nullptr; llvm::raw_ostream* statPrint = nullptr; + bool create_csv = false; if (!OutputStatsFilename.empty()) { + PrintStatsCSV = true; + create_csv = true; + } else { + if (PrintStatsCSV && fileSources.size() > 1) { + OutputStatsFilename = "sum_stat.csv"; + create_csv = true; + } + } + if (create_csv) { + if (!OutputDir.empty()) { + OutputStatsFilename = sOutputDirAbsPath + "/" + OutputStatsFilename; + } csv = std::unique_ptr(new std::ofstream(OutputStatsFilename, std::ios_base::trunc)); } if (PrintStats) { @@ -342,6 +355,17 @@ int main(int argc, const char **argv) { Result = 1; continue; } + if (PrintStatsCSV) { + if (OutputStatsFilename.empty()) { + OutputStatsFilename = sourceFileName.str() + "." + csv_ext.str(); + if (!OutputDir.empty()) { + OutputStatsFilename = sOutputDirAbsPath + "/" + OutputStatsFilename; + } + } + if (!csv) { + csv = std::unique_ptr(new std::ofstream(OutputStatsFilename, std::ios_base::trunc)); + } + } // Initialise the statistics counters for this file. Statistics::setActive(src); // RefactoringTool operates on the file in-place. Giving it the output path is no good,