[rtems commit] score: Add heap statistics

Sebastian Huber sebh at rtems.org
Fri Nov 28 12:38:33 UTC 2014


Module:    rtems
Branch:    master
Commit:    d006b46df31f6e5f28237fe40eafb135e684b739
Changeset: http://git.rtems.org/rtems/commit/?id=d006b46df31f6e5f28237fe40eafb135e684b739

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov 28 11:53:55 2014 +0100

score: Add heap statistics

Add lifetime bytes allocated and freed since they were present in the
malloc statistics.  Add number of failed allocations.

---

 cpukit/libmisc/shell/print_heapinfo.c   | 12 +++++++++---
 cpukit/score/include/rtems/score/heap.h | 25 ++++++++++++++++++++++---
 cpukit/score/src/heapallocate.c         | 12 ++++++++----
 cpukit/score/src/heapfree.c             |  1 +
 doc/shell/memory.t                      | 32 +++++++++++++++++++-------------
 5 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/cpukit/libmisc/shell/print_heapinfo.c b/cpukit/libmisc/shell/print_heapinfo.c
index 4ac9c96..b1e34f2 100644
--- a/cpukit/libmisc/shell/print_heapinfo.c
+++ b/cpukit/libmisc/shell/print_heapinfo.c
@@ -43,17 +43,23 @@ void rtems_shell_print_heap_stats(
     "Minimum free size ever in bytes:          %12" PRIuPTR "\n"
     "Maximum number of free blocks ever:       %12" PRIu32 "\n"
     "Maximum number of blocks searched ever:   %12" PRIu32 "\n"
+    "Lifetime number of bytes allocated:       %12" PRIu64 "\n"
+    "Lifetime number of bytes freed:           %12" PRIu64 "\n"
+    "Total number of searches:                 %12" PRIu32 "\n"
     "Total number of successful allocations:   %12" PRIu32 "\n"
-    "Total number of searches ever:            %12" PRIu32 "\n"
-    "Total number of successful calls to free: %12" PRIu32 "\n"
+    "Total number of failed allocations:       %12" PRIu32 "\n"
+    "Total number of successful frees:         %12" PRIu32 "\n"
     "Total number of successful resizes:       %12" PRIu32 "\n",
     s->instance,
     s->size,
     s->min_free_size,
     s->max_free_blocks,
     s->max_search,
-    s->allocs,
+    s->lifetime_allocated,
+    s->lifetime_freed,
     s->searches,
+    s->allocs,
+    s->failed_allocs,
     s->frees,
     s->resizes
   );
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 6042a13..f20b4e6 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -257,6 +257,20 @@ struct Heap_Block {
  */
 typedef struct {
   /**
+   * @brief Lifetime number of bytes allocated from this heap.
+   *
+   * This value is an integral multiple of the page size.
+   */
+  uint64_t lifetime_allocated;
+
+  /**
+   * @brief Lifetime number of bytes freed to this heap.
+   *
+   * This value is an integral multiple of the page size.
+   */
+  uint64_t lifetime_freed;
+
+  /**
    * @brief Instance number of this heap.
    */
   uint32_t instance;
@@ -303,17 +317,22 @@ typedef struct {
   uint32_t max_search;
 
   /**
+   * @brief Total number of searches.
+   */
+  uint32_t searches;
+
+  /**
    * @brief Total number of successful allocations.
    */
   uint32_t allocs;
 
   /**
-   * @brief Total number of searches ever.
+   * @brief Total number of failed allocations.
    */
-  uint32_t searches;
+  uint32_t failed_allocs;
 
   /**
-   * @brief Total number of successful calls to free.
+   * @brief Total number of successful frees.
    */
   uint32_t frees;
 
diff --git a/cpukit/score/src/heapallocate.c b/cpukit/score/src/heapallocate.c
index 597077e..a76ac04 100644
--- a/cpukit/score/src/heapallocate.c
+++ b/cpukit/score/src/heapallocate.c
@@ -254,10 +254,6 @@ void *_Heap_Allocate_aligned_with_boundary(
   } while ( search_again );
 
   if ( alloc_begin != 0 ) {
-    /* Statistics */
-    ++stats->allocs;
-    stats->searches += search_count;
-
     block = _Heap_Block_allocate( heap, block, alloc_begin, alloc_size );
 
     _Heap_Check_allocation(
@@ -268,6 +264,14 @@ void *_Heap_Allocate_aligned_with_boundary(
       alignment,
       boundary
     );
+
+    /* Statistics */
+    ++stats->allocs;
+    stats->searches += search_count;
+    stats->lifetime_allocated += _Heap_Block_size( block );
+  } else {
+    /* Statistics */
+    ++stats->failed_allocs;
   }
 
   /* Statistics */
diff --git a/cpukit/score/src/heapfree.c b/cpukit/score/src/heapfree.c
index 4e69146..13bf5ee 100644
--- a/cpukit/score/src/heapfree.c
+++ b/cpukit/score/src/heapfree.c
@@ -201,6 +201,7 @@ bool _Heap_Free( Heap_Control *heap, void *alloc_begin_ptr )
   --stats->used_blocks;
   ++stats->frees;
   stats->free_size += block_size;
+  stats->lifetime_freed += block_size;
 
   return( true );
 }
diff --git a/doc/shell/memory.t b/doc/shell/memory.t
index e8363ae..cda7ced 100644
--- a/doc/shell/memory.t
+++ b/doc/shell/memory.t
@@ -551,9 +551,12 @@ to the command.  This includes the following information:
 @item Minimum free size ever in bytes
 @item Maximum number of free blocks ever
 @item Maximum number of blocks searched ever
+ at item Lifetime number of bytes allocated
+ at item Lifetime number of bytes freed
+ at item Total number of searches
 @item Total number of successful allocations
- at item Total number of searches ever
- at item Total number of successful calls to free
+ at item Total number of failed allocations
+ at item Total number of successful frees
 @item Total number of successful resizes
 @end itemize
 
@@ -575,20 +578,23 @@ The following is an example of how to use the @code{malloc} command.
 @example
 SHLL [/] $ malloc
 C Program Heap and RTEMS Workspace are the same.
-Number of free blocks:                              14
-Largest free block:                          266157192
-Total bytes free:                            266164928
+Number of free blocks:                               2
+Largest free block:                          266207504
+Total bytes free:                            266208392
 Number of used blocks:                             167
-Largest used block:                              16424
-Total bytes used:                                90888
+Largest used block:                              16392
+Total bytes used:                                83536
 Instance number:                                     0
-Size of the allocatable area in bytes:       266255816
-Minimum free size ever in bytes:             266156136
-Maximum number of free blocks ever:                 15
-Maximum number of blocks searched ever:             15
+Size of the allocatable area in bytes:       266291928
+Minimum free size ever in bytes:             266207360
+Maximum number of free blocks ever:                  6
+Maximum number of blocks searched ever:              5
+Lifetime number of bytes allocated:              91760
+Lifetime number of bytes freed:                   8224
+Total number of searches:                          234
 Total number of successful allocations:            186
-Total number of searches ever:                     186
-Total number of successful calls to free:           19
+Total number of failed allocations:                  0
+Total number of successful frees:                   19
 Total number of successful resizes:                  0
 SHLL [/] $ malloc walk
 malloc walk




More information about the vc mailing list