summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-27 13:25:22 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-28 13:09:07 +0100
commit2c3c657625f5129e3062058a2c83f0020fd6bab5 (patch)
tree1b6b2a5b125d4dffc1268768bc067f021c35a412
parentlibcsupport: Delete malloc statistics (diff)
downloadrtems-2c3c657625f5129e3062058a2c83f0020fd6bab5.tar.bz2
score: Return heap stats via _Heap_Get_information
Print out heap statistics via the MALLOC and WKSPACE shell commands.
-rw-r--r--cpukit/libcsupport/src/resource_snapshot.c15
-rw-r--r--cpukit/libmisc/shell/internal.h7
-rw-r--r--cpukit/libmisc/shell/main_mallocinfo.c1
-rw-r--r--cpukit/libmisc/shell/main_wkspaceinfo.c3
-rw-r--r--cpukit/libmisc/shell/print_heapinfo.c39
-rw-r--r--cpukit/score/include/rtems/score/heap.h3
-rw-r--r--cpukit/score/src/heapgetinfo.c1
-rw-r--r--doc/shell/memory.t31
8 files changed, 76 insertions, 24 deletions
diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c
index 6f5038de31..6e4c4ca86f 100644
--- a/cpukit/libcsupport/src/resource_snapshot.c
+++ b/cpukit/libcsupport/src/resource_snapshot.c
@@ -98,6 +98,12 @@ static int open_files(void)
return (int) rtems_libio_number_iops - free_count;
}
+static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
+{
+ _Heap_Get_information(heap, info);
+ memset(&info->Stats, 0, sizeof(info->Stats));
+}
+
void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
{
uint32_t *active = &snapshot->rtems_api.active_barriers;
@@ -107,13 +113,8 @@ void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
_Thread_Kill_zombies();
- #ifdef HEAP_PROTECTION
- _Heap_Protection_free_all_delayed_blocks(RTEMS_Malloc_Heap);
- _Heap_Protection_free_all_delayed_blocks(&_Workspace_Area);
- #endif
-
- _Heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
- _Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info);
+ get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
+ get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
active [i] = _Objects_Active_count(objects_info_table[i]);
diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
index ad51588b15..56b1bb6077 100644
--- a/cpukit/libmisc/shell/internal.h
+++ b/cpukit/libmisc/shell/internal.h
@@ -32,10 +32,13 @@ int rtems_shell_execute_cmd(const char *cmd, int argc, char *argv[]);
extern void rtems_shell_register_monitor_commands(void);
extern void rtems_shell_print_heap_info(
- const char *c,
- Heap_Information *h
+ const char *c,
+ const Heap_Information *h
);
+extern void rtems_shell_print_heap_stats(
+ const Heap_Statistics *s
+);
extern void rtems_shell_print_unified_work_area_message(void);
diff --git a/cpukit/libmisc/shell/main_mallocinfo.c b/cpukit/libmisc/shell/main_mallocinfo.c
index 54c602a6e8..43e988376a 100644
--- a/cpukit/libmisc/shell/main_mallocinfo.c
+++ b/cpukit/libmisc/shell/main_mallocinfo.c
@@ -37,6 +37,7 @@ static int rtems_shell_main_malloc_info(
malloc_info( &info );
rtems_shell_print_heap_info( "free", &info.Free );
rtems_shell_print_heap_info( "used", &info.Used );
+ rtems_shell_print_heap_stats( &info.Stats );
}
return 0;
diff --git a/cpukit/libmisc/shell/main_wkspaceinfo.c b/cpukit/libmisc/shell/main_wkspaceinfo.c
index f4f6f4db78..a9906524db 100644
--- a/cpukit/libmisc/shell/main_wkspaceinfo.c
+++ b/cpukit/libmisc/shell/main_wkspaceinfo.c
@@ -24,7 +24,7 @@
void rtems_shell_print_unified_work_area_message(void)
{
- printf( "\nC Program Heap and RTEMS Workspace are %s.\n",
+ printf( "C Program Heap and RTEMS Workspace are %s.\n",
rtems_configuration_get_unified_work_area() ? "the same" : "separate"
);
}
@@ -41,6 +41,7 @@ static int rtems_shell_main_wkspace_info(
_Protected_heap_Get_information( &_Workspace_Area, &info );
rtems_shell_print_heap_info( "free", &info.Free );
rtems_shell_print_heap_info( "used", &info.Used );
+ rtems_shell_print_heap_stats( &info.Stats );
return 0;
}
diff --git a/cpukit/libmisc/shell/print_heapinfo.c b/cpukit/libmisc/shell/print_heapinfo.c
index 12bc363f71..4ac9c96f88 100644
--- a/cpukit/libmisc/shell/print_heapinfo.c
+++ b/cpukit/libmisc/shell/print_heapinfo.c
@@ -14,22 +14,47 @@
#endif
#include <inttypes.h>
+#include <stdio.h>
-#include <rtems.h>
-#include <rtems/shell.h>
#include "internal.h"
void rtems_shell_print_heap_info(
- const char *c,
- Heap_Information *h
+ const char *c,
+ const Heap_Information *h
)
{
printf(
- "Number of %s blocks: %" PRId32 "\n"
- "Largest %s block: %" PRId32 "\n"
- "Total bytes %s: %" PRId32 "\n",
+ "Number of %s blocks: %12" PRId32 "\n"
+ "Largest %s block: %12" PRId32 "\n"
+ "Total bytes %s: %12" PRId32 "\n",
c, h->number,
c, h->largest,
c, h->total
);
}
+
+void rtems_shell_print_heap_stats(
+ const Heap_Statistics *s
+)
+{
+ printf(
+ "Instance number: %12" PRIu32 "\n"
+ "Size of the allocatable area in bytes: %12" PRIuPTR "\n"
+ "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"
+ "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 successful resizes: %12" PRIu32 "\n",
+ s->instance,
+ s->size,
+ s->min_free_size,
+ s->max_free_blocks,
+ s->max_search,
+ s->allocs,
+ s->searches,
+ s->frees,
+ s->resizes
+ );
+}
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 0120a2bb14..6042a13bf2 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -313,7 +313,7 @@ typedef struct {
uint32_t searches;
/**
- * @brief Total number of suceessful calls to free.
+ * @brief Total number of successful calls to free.
*/
uint32_t frees;
@@ -366,6 +366,7 @@ typedef struct {
typedef struct {
Heap_Information Free;
Heap_Information Used;
+ Heap_Statistics Stats;
} Heap_Information_block;
/**
diff --git a/cpukit/score/src/heapgetinfo.c b/cpukit/score/src/heapgetinfo.c
index 8565be46a5..287d269922 100644
--- a/cpukit/score/src/heapgetinfo.c
+++ b/cpukit/score/src/heapgetinfo.c
@@ -50,4 +50,5 @@ void _Heap_Get_information(
memset( the_info, 0, sizeof(*the_info) );
_Heap_Protection_free_all_delayed_blocks( the_heap );
_Heap_Iterate( the_heap, _Heap_Get_information_visitor, the_info );
+ the_info->Stats = the_heap->stats;
}
diff --git a/doc/shell/memory.t b/doc/shell/memory.t
index 0fdf1f8513..e8363ae5f8 100644
--- a/doc/shell/memory.t
+++ b/doc/shell/memory.t
@@ -546,6 +546,15 @@ to the command. This includes the following information:
@item Number of used blocks
@item Largest used block
@item Total bytes used
+@item Instance number
+@item Size of the allocatable area in bytes
+@item Minimum free size ever in bytes
+@item Maximum number of free blocks ever
+@item Maximum number of blocks searched ever
+@item Total number of successful allocations
+@item Total number of searches ever
+@item Total number of successful calls to free
+@item Total number of successful resizes
@end itemize
When the subcommand @code{walk} is specified, then a heap walk will be
@@ -565,12 +574,22 @@ The following is an example of how to use the @code{malloc} command.
@example
SHLL [/] $ malloc
-Number of free blocks: 3
-Largest free block: 3626672
-Total bytes free: 3627768
-Number of used blocks: 130
-Largest used block: 1048
-Total bytes used: 10136
+C Program Heap and RTEMS Workspace are the same.
+Number of free blocks: 14
+Largest free block: 266157192
+Total bytes free: 266164928
+Number of used blocks: 167
+Largest used block: 16424
+Total bytes used: 90888
+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
+Total number of successful allocations: 186
+Total number of searches ever: 186
+Total number of successful calls to free: 19
+Total number of successful resizes: 0
SHLL [/] $ malloc walk
malloc walk
PASS[0]: page size 8, min block size 48