fix profile code
[IRC.git] / Robust / src / Runtime / bamboo / multicoregcprofile.h
index 4a63185fcfc13b6f69ccc2680d486e82207c6bff..9ddbf86aaa83a82c227646a23153a165326cd95b 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef BAMBOO_MULTICORE_GC_PROFILE_H
 #define BAMBOO_MULTICORE_GC_PROFILE_H
-#ifdef MULTICORE_GC
+#if defined(MULTICORE_GC)||defined(PMC_GC)
 #include "multicore.h"
+#include "runtime_arch.h"
+#include "structdefs.h"
 
 #ifdef GC_PROFILE
 #define GCINFOLENGTH 100
@@ -34,13 +36,53 @@ unsigned int gc_num_profiles;
 volatile bool gc_profile_flag;
 #endif
 
-
-INLINE void initmulticoregcprofiledata(void);
-INLINE void gc_profileInit(void);
-INLINE void gc_profileStart(void);
-INLINE void gc_profileItem(void);
-INLINE void gc_profileEnd(void);
+void initmulticoregcprofiledata(void);
 void gc_outputProfileData();
+void gc_outputProfileDataReadable();
+
+INLINE static void gc_profileInit() {
+  gc_num_livespace = 0;
+  gc_num_freespace = 0;
+  gc_num_lobj = 0;
+  gc_num_lobjspace = 0;
+  gc_num_liveobj = 0;
+  gc_num_forwardobj = 0;
+  gc_num_profiles = NUMCORESACTIVE - 1;
+}
+
+INLINE static void gc_profileStart(void) {
+  if(!gc_infoOverflow) {
+    GCInfo* gcInfo = RUNMALLOC(sizeof(struct gc_info));
+    gc_infoArray[gc_infoIndex] = gcInfo;
+    gcInfo->index = 1;
+    gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
+  }
+}
+
+INLINE static void gc_profileItem(void) {
+  if(!gc_infoOverflow) {
+    GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
+    gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
+  }
+}
+
+INLINE static void gc_profileEnd(void) {
+  if(!gc_infoOverflow) {
+    GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
+    gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
+    gcInfo->time[gcInfo->index++] = gc_num_livespace;
+    gcInfo->time[gcInfo->index++] = gc_num_freespace;
+    gcInfo->time[gcInfo->index++] = gc_num_lobj;
+    gcInfo->time[gcInfo->index++] = gc_num_lobjspace;
+    gcInfo->time[gcInfo->index++] = gc_num_obj;
+    gcInfo->time[gcInfo->index++] = gc_num_liveobj;
+    gcInfo->time[gcInfo->index++] = gc_num_forwardobj;
+    gc_infoIndex++;
+    if(gc_infoIndex == GCINFOLENGTH) {
+      gc_infoOverflow = true;
+    }
+  }
+}
 
 #define INIT_MULTICORE_GCPROFILE_DATA() initmulticoregcprofiledata()
 #define GC_OUTPUT_PROFILE_DATA() gc_outputProfileData()
@@ -57,9 +99,7 @@ void gc_outputProfileData();
 // record lobj info
 #define GCPROFILE_RECORD_LOBJ() \
   { \
-    if(gc_profile_flag) { \
       gc_num_lobj++; \
-    } \
   }
 // record lobj space info
 #define GCPROFILE_RECORD_LOBJSPACE() \
@@ -72,26 +112,26 @@ void gc_outputProfileData();
 #define GCPROFILE_RECORD_SPACE() \
   { \
     if(gc_profile_flag) { \
-      gc_num_livespace = 0; \
-      for(int tmpi = 0; tmpi < gcnumblock; tmpi++) { \
-        gc_num_livespace += bamboo_smemtbl[tmpi]; \
+      gc_num_freespace = 0; \
+      block_t lowestblock=allocationinfo.lowestfreeblock; \
+      for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) { \
+        struct blockrecord * block=&allocationinfo.blocktable[searchblock]; \
+        if (block->status==BS_FREE) { \
+          gc_num_freespace+=block->freespace&~BAMBOO_CACHE_LINE_MASK; \
+        } \
       } \
-      gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \
+      gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
     } \
   }
 // record forward obj info
 #define GCPROFILE_RECORD_FORWARD_OBJ() \
   { \
-    if(gc_profile_flag) { \
       gc_num_forwardobj++; \
-    } \
   }
 // record live obj info
 #define GCPROFILE_RECORD_LIVE_OBJ() \
   { \
-    if(gc_profile_flag) { \
       gc_num_liveobj++; \
-    } \
   }
 #define GCPROFILE_START() \
   { \
@@ -117,7 +157,7 @@ void gc_outputProfileData();
 #define GCPROFILE_RECORD_SPACE() \
   { \
     gc_num_livespace = 0; \
-    for(int tmpi = 0; tmpi < gcnumblock; tmpi++) { \
+    for(int tmpi = 0; tmpi < GCNUMBLOCK; tmpi++) { \
       gc_num_livespace += bamboo_smemtbl[tmpi]; \
     } \
     gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \