source: rtems/cpukit/libcsupport/src/malloc_statistics_helpers.c @ cfcc4e20

4.104.114.95
Last change on this file since cfcc4e20 was cfcc4e20, checked in by Joel Sherrill <joel.sherrill@…>, on 01/08/08 at 22:59:14

2008-01-08 Joel Sherrill <joel.sherrill@…>

  • libcsupport/Makefile.am: Add malloc_sbrk_helpers.c.
  • libcsupport/include/rtems/malloc.h, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_statistics_helpers.c: Make sbrk() support pluggable and optional. This eliminates the need for heap extend and sbrk in the minimum footprint which is ~2.5K on the SPARC.
  • sapi/include/confdefs.h: Add the following configuration points: + CONFIGURE_MALLOC_STATISTICS + CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
  • libcsupport/src/malloc_sbrk_helpers.c: New file.
  • Property mode set to 100644
File size: 1.5 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()
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  size_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  size_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
76
Note: See TracBrowser for help on using the repository browser.