Bläddra i källkod

Added GCGetStats().

Brucey 2 år sedan
förälder
incheckning
36c52e53ed
3 ändrade filer med 69 tillägg och 0 borttagningar
  1. 63 0
      blitz.mod/blitz.bmx
  2. 4 0
      blitz.mod/blitz_gc.c
  3. 2 0
      blitz.mod/blitz_gc.h

+ 63 - 0
blitz.mod/blitz.bmx

@@ -548,6 +548,69 @@ accessible after the thread is unregistered.
 End Rem
 Function GCUnregisterMyThread:Int()="bbGCUnregisterMyThread"
 
+Rem
+bbdoc: Structure for holding Garbage Collection statistics as provided by #GCGetStats().
+End Rem
+Struct SGCStats
+	Rem
+	bbdoc: Heap size in bytes (including the area unmapped to OS).
+	End Rem
+	Field heapsize:Long
+	Rem
+	bbdoc: Total bytes contained in free and unmapped blocks.
+	End Rem
+	Field freeBytes:Long
+	Rem
+	bbdoc: Amount of memory unmapped to OS.
+	End Rem
+	Field unmappedBytes:Long
+	Rem
+	bbdoc: Number of bytes allocated since the recent collection.
+	End Rem
+	Field bytesAllocedSinceGC:Long
+	Rem
+	bbdoc: Number of bytes allocated before the recent garbage collection.
+	about: The value may wrap.
+	End Rem
+	Field allocedBytesBeforeGC:Long
+	Rem
+	bbdoc: Number of bytes not considered candidates for garbage collection.
+	End Rem
+	Field nonGCBytes:Long
+	Rem
+	bbdoc: Garbage collection cycle number.
+	about: The value may wrap (and could be -1).
+	End Rem
+	Field GCCycleNo:Long
+	Rem
+	bbdoc: Number of marker threads (excluding the initiating one).
+	about: 0 if the collector is single-threaded.
+	End Rem
+	Field markersM1:Long
+	Rem
+	bbdoc: Approximate number of reclaimed bytes after recent GC.
+	End Rem
+	Field bytesReclaimedSinceGC:Long
+	Rem
+	bbdoc: Approximate number of bytes reclaimed before the recent garbage collection.
+	about: The value may wrap.
+	End Rem
+	Field reclaimedBytesBeforeGC:Long
+	Rem
+	bbdoc: Number of bytes freed explicitly since the recent GC.
+	End Rem
+	Field freedBytesSinceGC:Long
+	Rem
+	bbdoc: Total amount of memory obtained from OS, in bytes.
+	End Rem
+	Field obtainedFromOSBytes:Long
+End Struct
+
+Rem
+bbdoc: Retrieves GC statistics (various global counters), populating the provided #SGCStats struct.
+End Rem
+Function GCGetStats(stats:SGCStats Var)="void bbGCGetStats(void*)!"
+
 Rem
 bbdoc: Convert object to integer handle
 returns: An integer object handle

+ 4 - 0
blitz.mod/blitz_gc.c

@@ -261,3 +261,7 @@ int bbGCUnregisterMyThread() {
 	return -1;
 #endif
 }
+
+void bbGCGetStats(struct GC_prof_stats_s * stats) {
+	GC_get_prof_stats(stats, sizeof(struct GC_prof_stats_s));
+}

+ 2 - 0
blitz.mod/blitz_gc.h

@@ -69,6 +69,8 @@ int			bbGCThreadIsRegistered();
 int			bbGCRegisterMyThread();
 int			bbGCUnregisterMyThread();
 
+void bbGCGetStats(struct GC_prof_stats_s * stats);
+
 // BBRETAIN/BBRELEASE should be used to prevent an object from garbage collection.
 //
 // This is mainly of use if an object is being stored outside of BlitzMax's 'sight' - say, in a C++ table.