瀏覽代碼

implement get_utilization_index

Ioannis Koutras 12 年之前
父節點
當前提交
9d70704523
共有 2 個文件被更改,包括 13 次插入2 次删除
  1. 3 0
      include/dmmlib/dmmstats.h
  2. 10 2
      src/statistics.c

+ 3 - 0
include/dmmlib/dmmstats.h

@@ -50,4 +50,7 @@ size_t get_total_requested_memory(void);
 /** Returns the total memory currently allocated for the application. */
 size_t get_total_allocated_memory(void);
 
+/** Returns the current utilization index. */
+float get_utilization_index(void);
+
 #endif /* DMMSTATS_H */

+ 10 - 2
src/statistics.c

@@ -76,13 +76,21 @@ void update_stats
 }
 
 #ifdef REQUEST_SIZE_INFO
-/** Returns the total memory that is currently requested */
+/** Returns the total memory currently requested by the application. */
 size_t get_total_requested_memory(void) {
     return systemallocator.dmm_stats.total_mem_requested;
 }
 #endif /* REQUEST_SIZE_INFO */
 
-/** Returns the total memory that is currently allocated */
 size_t get_total_allocated_memory(void) {
     return systemallocator.dmm_stats.total_mem_allocated;
 }
+
+float get_utilization_index(void) {
+    if(systemallocator.dmm_stats.total_mem_allocated != 0) {
+        return (float) systemallocator.dmm_stats.total_mem_requested /
+            systemallocator.dmm_stats.total_mem_allocated;
+    } else {
+        return 1.0;
+    }
+}