[Openmp-commits] [openmp] r273273 - [STATS] Adding process id to output filename

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Tue Jun 21 08:20:34 PDT 2016


Author: jlpeyton
Date: Tue Jun 21 10:20:33 2016
New Revision: 273273

URL: http://llvm.org/viewvc/llvm-project?rev=273273&view=rev
Log:
[STATS] Adding process id to output filename

This change appends the process id to the KMP_STATS_FILE (if specified) which
enables MPI processes to output their stats to separate files.

Differential Revision: http://reviews.llvm.org/D21386

Modified:
    openmp/trunk/runtime/src/kmp_stats.cpp
    openmp/trunk/runtime/src/kmp_stats.h

Modified: openmp/trunk/runtime/src/kmp_stats.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_stats.cpp?rev=273273&r1=273272&r2=273273&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_stats.cpp (original)
+++ openmp/trunk/runtime/src/kmp_stats.cpp Tue Jun 21 10:20:33 2016
@@ -356,7 +356,6 @@ kmp_stats_list* kmp_stats_list::iterator
 /* *************************************************************** */
 /* *************  kmp_stats_output_module functions ************** */
 
-const char* kmp_stats_output_module::outputFileName = NULL;
 const char* kmp_stats_output_module::eventsFileName = NULL;
 const char* kmp_stats_output_module::plotFileName   = NULL;
 int kmp_stats_output_module::printPerThreadFlag       = 0;
@@ -372,7 +371,24 @@ void kmp_stats_output_module::init()
     char * threadEvents   = getenv("KMP_STATS_EVENTS");
 
     // set the stats output filenames based on environment variables and defaults
-    outputFileName = statsFileName;
+    if(statsFileName) {
+        // append the process id to the output filename
+        // events.csv --> events-pid.csv
+        size_t index;
+        std::string baseFileName, pid, suffix;
+        std::stringstream ss;
+        outputFileName = std::string(statsFileName);
+        index = outputFileName.find_last_of('.');
+        if(index == std::string::npos) {
+            baseFileName = outputFileName;
+        } else {
+            baseFileName = outputFileName.substr(0, index);
+            suffix = outputFileName.substr(index);
+        }
+        ss << getpid();
+        pid = ss.str();
+        outputFileName = baseFileName + "-" + pid + suffix;
+    }
     eventsFileName = eventsFileName ? eventsFileName : "events.dat";
     plotFileName   = plotFileName   ? plotFileName   : "events.plt";
 
@@ -573,7 +589,7 @@ void kmp_stats_output_module::outputStat
     statistic totalStats[TIMER_LAST];           /* Synthesized, cross threads versions of normal timer stats */
     statistic allCounters[COUNTER_LAST];
 
-    FILE * statsOut = outputFileName ? fopen (outputFileName, "a+") : stderr;
+    FILE * statsOut = !outputFileName.empty() ? fopen (outputFileName.c_str(), "a+") : stderr;
     if (!statsOut)
         statsOut = stderr;
 

Modified: openmp/trunk/runtime/src/kmp_stats.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_stats.h?rev=273273&r1=273272&r2=273273&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_stats.h (original)
+++ openmp/trunk/runtime/src/kmp_stats.h Tue Jun 21 10:20:33 2016
@@ -687,7 +687,7 @@ class kmp_stats_output_module {
     };
 
  private:
-    static const char* outputFileName;
+    std::string outputFileName;
     static const char* eventsFileName;
     static const char* plotFileName;
     static int printPerThreadFlag;




More information about the Openmp-commits mailing list