소스 검색

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;
+    }
+}