source: rtems/cpukit/libcsupport/src/malloc_statistics_helpers.c @ 6fee038

4.104.115
Last change on this file since 6fee038 was 6fee038, checked in by Joel Sherrill <joel.sherrill@…>, on 12/21/08 at 21:29:03

2008-12-21 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/malloc_statistics_helpers.c: Use intptr_t not ssize_t.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1
2/*
3 *  _calloc_r Implementation
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#ifdef RTEMS_NEWLIB
20#include "malloc_p.h"
21
22#include <sys/reent.h>
23#include <stdlib.h>
24
25
26void rtems_malloc_statistics_initialize( void )
27{
28  /*
29   * Zero all the statistics
30   */
31  (void) memset(&rtems_malloc_statistics, 0, sizeof(rtems_malloc_statistics));
32}
33
34void rtems_malloc_statistics_at_malloc(
35  void *pointer
36)
37{
38  intptr_t  actual_size = 0;
39  uint32_t  current_depth;
40  rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
41
42  if ( !pointer )
43    return;
44
45  _Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size);
46
47  MSBUMP(lifetime_allocated, actual_size);
48
49  current_depth = s->lifetime_allocated - s->lifetime_freed;
50  if (current_depth > s->max_depth)
51      s->max_depth = current_depth;
52}
53
54/*
55 *  If the pointer is not in the heap, then we won't be able to get its
56 *  size and thus we skip updating the statistics.
57 */
58void rtems_malloc_statistics_at_free(
59  void *pointer
60)
61{
62  intptr_t size;
63
64  if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) {
65    MSBUMP(lifetime_freed, size);
66  }
67}
68
69rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
70  rtems_malloc_statistics_initialize,
71  rtems_malloc_statistics_at_malloc,
72  rtems_malloc_statistics_at_free,
73};
74
75#endif
Note: See TracBrowser for help on using the repository browser.