summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-05-31 14:33:53 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-05-31 14:33:53 +0200
commit2b72e02eccdcdf76d78e06492ef96fd8cbd02a14 (patch)
tree03dcd5d55731e28dc348f59f5608decdfb3c9e15
parenteb27c2c7dd5ecce18737e5003394382bd1773ba1 (diff)
parentf5ed8f3a1b1b23af2b06ba9d6fc4e4bc80e1f4cf (diff)
downloadNim-2b72e02eccdcdf76d78e06492ef96fd8cbd02a14.tar.gz
Merge pull request #1208 from jbe/shared_mem_stats
added getTotalSharedMem et al.
-rw-r--r--lib/system.nim14
-rw-r--r--lib/system/alloc.nim16
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim
index ad98540a7..c69a335e4 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1434,6 +1434,20 @@ when not defined(nimrodVM) and hostOS != "standalone":
   proc getTotalMem*(): int {.rtl.}
     ## returns the number of bytes that are owned by the process.
 
+  when hasThreadSupport:
+    proc getOccupiedSharedMem*(): int {.rtl.}
+      ## returns the number of bytes that are owned by the process
+      ## on the shared heap and hold data. This is only available when
+      ## threads are enabled.
+
+    proc getFreeSharedMem*(): int {.rtl.}
+      ## returns the number of bytes that are owned by the
+      ## process on the shared heap, but do not hold any meaningful data.
+      ## This is only available when threads are enabled.
+
+    proc getTotalSharedMem*(): int {.rtl.}
+      ## returns the number of bytes on the shared heap that are owned by the
+      ## process. This is only available when threads are enabled.
 
 iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
   ## Counts from ordinal value `a` down to `b` with the given
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index eaef6cd95..602e5c7fa 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -835,4 +835,20 @@ template instantiateForRegion(allocator: expr) =
     else:
       result = realloc(p, newsize)
 
+  when hasThreadSupport:
+
+    template sharedMemStatsShared(v: int) {.immediate.} =
+      acquireSys(heapLock)
+      result = v
+      releaseSys(heapLock)
+
+    proc getFreeSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.freeMem)
+
+    proc getTotalSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.currMem)
+
+    proc getOccupiedSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.currMem - sharedHeap.freeMem)
+
 {.pop.}