source: rtems/cpukit/libcsupport/src/resource_snapshot.c @ 2c3c657

4.115
Last change on this file since 2c3c657 was 2c3c657, checked in by Sebastian Huber <sebastian.huber@…>, on 11/27/14 at 12:25:22

score: Return heap stats via _Heap_Get_information

Print out heap statistics via the MALLOC and WKSPACE shell commands.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[c5d2760]1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
[c499856]12 * http://www.rtems.org/license/LICENSE.
[c5d2760]13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/libcsupport.h>
20
21#include <string.h>
22
23#include <rtems/libio_.h>
24#include <rtems/malloc.h>
25#include <rtems/score/protectedheap.h>
[1b1be254]26#include <rtems/score/threadimpl.h>
27#include <rtems/score/wkspace.h>
[c5d2760]28
[ac252bdc]29#include <rtems/extensionimpl.h>
30
[0b32bb8]31#include <rtems/rtems/barrierimpl.h>
[562815c]32#include <rtems/rtems/dpmemimpl.h>
[993a888]33#include <rtems/rtems/messageimpl.h>
[8695cae]34#include <rtems/rtems/partimpl.h>
[ecdcf01]35#include <rtems/rtems/ratemonimpl.h>
[f6c7c57d]36#include <rtems/rtems/regionimpl.h>
[2bbea657]37#include <rtems/rtems/semimpl.h>
[c404828]38#include <rtems/rtems/tasksimpl.h>
[e90b1df]39#include <rtems/rtems/timerimpl.h>
[2bbea657]40
[c5d2760]41#ifdef RTEMS_POSIX_API
[6b4a3770]42  #include <rtems/posix/barrierimpl.h>
[35210b12]43  #include <rtems/posix/condimpl.h>
[972a5c5f]44  #include <rtems/posix/mqueueimpl.h>
[f9d533a5]45  #include <rtems/posix/muteximpl.h>
[2ad250e]46  #include <rtems/posix/keyimpl.h>
[c5d2760]47  #include <rtems/posix/psignal.h>
[0c5317d]48  #include <rtems/posix/pthreadimpl.h>
[0e8656b4]49  #include <rtems/posix/rwlockimpl.h>
[9c743e8e]50  #include <rtems/posix/semaphoreimpl.h>
[eb448eec]51  #include <rtems/posix/spinlockimpl.h>
[f17c779]52  #include <rtems/posix/timerimpl.h>
[c5d2760]53#endif
54
55static const Objects_Information *objects_info_table[] = {
56  &_Barrier_Information,
57  &_Extension_Information,
58  &_Message_queue_Information,
59  &_Partition_Information,
60  &_Rate_monotonic_Information,
61  &_Dual_ported_memory_Information,
62  &_Region_Information,
63  &_Semaphore_Information,
64  &_RTEMS_tasks_Information,
65  &_Timer_Information
66  #ifdef RTEMS_POSIX_API
67    ,
68    &_POSIX_Barrier_Information,
69    &_POSIX_Condition_variables_Information,
70    &_POSIX_Keys_Information,
71    &_POSIX_Message_queue_Information,
72    &_POSIX_Message_queue_Information_fds,
73    &_POSIX_Mutex_Information,
74    &_POSIX_RWLock_Information,
75    &_POSIX_Semaphore_Information,
76    &_POSIX_Spinlock_Information,
77    &_POSIX_Threads_Information,
78    &_POSIX_Timer_Information
79  #endif
80};
81
82static int open_files(void)
83{
84  int free_count = 0;
85  rtems_libio_t *iop;
86
87  rtems_libio_lock();
88
89  iop = rtems_libio_iop_freelist;
90  while (iop != NULL) {
91    ++free_count;
92
93    iop = iop->data1;
94  }
95
96  rtems_libio_unlock();
97
98  return (int) rtems_libio_number_iops - free_count;
99}
100
[2c3c657]101static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
102{
103  _Heap_Get_information(heap, info);
104  memset(&info->Stats, 0, sizeof(info->Stats));
105}
106
[c5d2760]107void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
108{
109  uint32_t *active = &snapshot->rtems_api.active_barriers;
110  size_t i;
111
[23fec9f0]112  _RTEMS_Lock_allocator();
[4f1da72]113
[1b1be254]114  _Thread_Kill_zombies();
115
[2c3c657]116  get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
117  get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
[c5d2760]118
119  for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
120    active [i] = _Objects_Active_count(objects_info_table[i]);
121  }
122
[23fec9f0]123  _RTEMS_Unlock_allocator();
[c5d2760]124
125  #ifndef RTEMS_POSIX_API
126    memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api));
127  #endif
128
129  snapshot->open_files = open_files();
130}
131
132bool rtems_resource_snapshot_equal(
133  const rtems_resource_snapshot *a,
134  const rtems_resource_snapshot *b
135)
136{
137  return memcmp(a, b, sizeof(*a)) == 0;
138}
139
140bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
141{
142  rtems_resource_snapshot now;
143
144  rtems_resource_snapshot_take(&now);
145
146  return rtems_resource_snapshot_equal(&now, snapshot);
147}
Note: See TracBrowser for help on using the repository browser.