1 | /* |
---|
2 | * Heap Handler |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2000. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | |
---|
15 | #include <rtems/system.h> |
---|
16 | #include <rtems/score/sysstate.h> |
---|
17 | #include <rtems/score/heap.h> |
---|
18 | |
---|
19 | /*PAGE |
---|
20 | * |
---|
21 | * _Heap_Get_information |
---|
22 | * |
---|
23 | * This kernel routine walks the heap and tots up the free and allocated |
---|
24 | * sizes. Derived from _Heap_Walk. |
---|
25 | * |
---|
26 | * Input parameters: |
---|
27 | * the_heap - pointer to heap header |
---|
28 | * the_info - pointer for information to be returned |
---|
29 | * |
---|
30 | * Output parameters: |
---|
31 | * *the_info - contains information about heap |
---|
32 | * return 0=success, otherwise heap is corrupt. |
---|
33 | */ |
---|
34 | |
---|
35 | |
---|
36 | Heap_Get_information_status _Heap_Get_information( |
---|
37 | Heap_Control *the_heap, |
---|
38 | Heap_Information_block *the_info |
---|
39 | ) |
---|
40 | { |
---|
41 | Heap_Block *the_block = the_heap->start; |
---|
42 | Heap_Block *const end = the_heap->final; |
---|
43 | |
---|
44 | _HAssert(the_block->prev_size == HEAP_PREV_USED); |
---|
45 | _HAssert(_Heap_Is_prev_used(the_block)); |
---|
46 | |
---|
47 | the_info->Free.number = 0; |
---|
48 | the_info->Free.total = 0; |
---|
49 | the_info->Free.largest = 0; |
---|
50 | the_info->Used.number = 0; |
---|
51 | the_info->Used.total = 0; |
---|
52 | the_info->Used.largest = 0; |
---|
53 | |
---|
54 | while ( the_block != end ) { |
---|
55 | uint32_t const the_size = _Heap_Block_size(the_block); |
---|
56 | Heap_Block *const next_block = _Heap_Block_at(the_block, the_size); |
---|
57 | |
---|
58 | if ( _Heap_Is_prev_used(next_block) ) { |
---|
59 | the_info->Used.number++; |
---|
60 | the_info->Used.total += the_size; |
---|
61 | if ( the_info->Used.largest < the_size ) |
---|
62 | the_info->Used.largest = the_size; |
---|
63 | } else { |
---|
64 | the_info->Free.number++; |
---|
65 | the_info->Free.total += the_size; |
---|
66 | if ( the_info->Free.largest < the_size ) |
---|
67 | the_info->Free.largest = the_size; |
---|
68 | if ( the_size != next_block->prev_size ) |
---|
69 | return HEAP_GET_INFORMATION_BLOCK_ERROR; |
---|
70 | } |
---|
71 | |
---|
72 | the_block = next_block; |
---|
73 | } |
---|
74 | |
---|
75 | /* Handle the last dummy block. Don't consider this block to be |
---|
76 | "used" as client never allocated it. Make 'Used.total' contain this |
---|
77 | blocks' overhead though. */ |
---|
78 | the_info->Used.total += HEAP_OVERHEAD; |
---|
79 | |
---|
80 | return HEAP_GET_INFORMATION_SUCCESSFUL; |
---|
81 | } |
---|