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

4.104.11
Last change on this file since bd5984de was bd5984de, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 17, 2008 at 6:37:55 PM

2008-09-17 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/free.c, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_sbrk_helpers.c, libcsupport/src/malloc_statistics_helpers.c, libcsupport/src/malloc_walk.c, libcsupport/src/mallocfreespace.c, libcsupport/src/mallocinfo.c, libcsupport/src/realloc.c, libcsupport/src/rtems_memalign.c, sapi/include/confdefs.h, score/inline/rtems/score/thread.inl: Add support for optionally having a unified work area. In other words, the RTEMS Workspace and C Program Heap are the same pool of memory.
  • 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  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
Note: See TracBrowser for help on using the repository browser.