source: rtems/cpukit/score/src/heapgetinfo.c @ bd029d87

4.8
Last change on this file since bd029d87 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 2.2 KB
Line 
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#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/score/sysstate.h>
20#include <rtems/score/heap.h>
21
22/*PAGE
23 *
24 *  _Heap_Get_information
25 *
26 *  This kernel routine walks the heap and tots up the free and allocated
27 *  sizes.  Derived from _Heap_Walk.
28 *
29 *  Input parameters:
30 *    the_heap  - pointer to heap header
31 *    the_info  - pointer for information to be returned
32 *
33 *  Output parameters:
34 *    *the_info  - contains information about heap
35 *    return 0=success, otherwise heap is corrupt.
36 */
37
38Heap_Get_information_status _Heap_Get_information(
39  Heap_Control            *the_heap,
40  Heap_Information_block  *the_info
41)
42{
43  Heap_Block *the_block = the_heap->start;
44  Heap_Block *const end = the_heap->final;
45
46  _HAssert(the_block->prev_size == HEAP_PREV_USED);
47  _HAssert(_Heap_Is_prev_used(the_block));
48
49  the_info->Free.number  = 0;
50  the_info->Free.total   = 0;
51  the_info->Free.largest = 0;
52  the_info->Used.number  = 0;
53  the_info->Used.total   = 0;
54  the_info->Used.largest = 0;
55
56  while ( the_block != end ) {
57    uint32_t const the_size = _Heap_Block_size(the_block);
58    Heap_Block *const next_block = _Heap_Block_at(the_block, the_size);
59
60    if ( _Heap_Is_prev_used(next_block) ) {
61      the_info->Used.number++;
62      the_info->Used.total += the_size;
63      if ( the_info->Used.largest < the_size )
64        the_info->Used.largest = the_size;
65    } else {
66      the_info->Free.number++;
67      the_info->Free.total += the_size;
68      if ( the_info->Free.largest < the_size )
69        the_info->Free.largest = the_size;
70      if ( the_size != next_block->prev_size )
71        return HEAP_GET_INFORMATION_BLOCK_ERROR;
72    }
73
74    the_block = next_block;
75  }
76
77  /* Handle the last dummy block. Don't consider this block to be
78     "used" as client never allocated it. Make 'Used.total' contain this
79     blocks' overhead though. */
80  the_info->Used.total += HEAP_OVERHEAD;
81
82  return HEAP_GET_INFORMATION_SUCCESSFUL;
83}
Note: See TracBrowser for help on using the repository browser.