add PAPI performance counter in autoPerf module
[charm.git] / src / ck-tune / trace-autoPerf.h
index d5b4f578314abdcc937dd0f7c1cd21fc7bcde717..1d0f998fc7557838f2959f2f4b8cd8f9cf122d71 100644 (file)
 #include <list>
 
 
+#if CMK_HAS_COUNTER_PAPI
+#include <papi.h>
+#ifdef USE_SPP_PAPI
+#define NUMPAPIEVENTS 8
+#else
+#define NUMPAPIEVENTS 9
+#endif
+#endif
+
+
+
 using namespace std;
 
 extern CkGroupID traceAutoPerfGID;
@@ -176,6 +187,10 @@ public:
     double  commTime;
     double  objLoadMax;
 
+#if CMK_HAS_COUNTER_PAPI
+    LONG_LONG_PAPI papiValues[NUMPAPIEVENTS];
+#endif
+
     // functions
     perfData(){}
 };
@@ -248,6 +263,11 @@ class TraceAutoPerf : public Trace {
 
 public:
 
+#if CMK_HAS_COUNTER_PAPI
+    int papiEventSet;
+    LONG_LONG_PAPI papiValues[NUMPAPIEVENTS];
+    LONG_LONG_PAPI previous_papiValues[NUMPAPIEVENTS];
+#endif
     double  lastBeginExecuteTime;
     int     lastbeginMessageSize;
     int     lastEvent;
@@ -438,6 +458,15 @@ public:
       return totalEntryMethodInvocations;
   }
 
+#if CMK_HAS_COUNTER_PAPI
+  inline void readPAPI()
+  {
+      if (PAPI_read(papiEventSet, papiValues) != PAPI_OK) {
+          CmiAbort("PAPI failed to read at begin execute!\n");
+      }
+  }
+#endif
+
   perfData* getSummary()
   {
       currentSummary->idleMin = currentSummary->idleMax= idleRatio(); 
@@ -449,6 +478,13 @@ public:
       currentSummary->grainsizeAvg = grainSize();
       currentSummary->grainsizeMax = maxGrainSize();
       currentSummary->numInvocations = totalEntryMethodInvocations;
+#if CMK_HAS_COUNTER_PAPI
+      readPAPI();
+      for(int i=0; i<NUMPAPIEVENTS; i++)
+      {
+          currentSummary->papiValues[i] = (papiValues[i] - previous_papiValues[i]);
+      }
+#endif
       return currentSummary;
   }