source: rtems/cpukit/libcsupport/src/resource_snapshot.c @ d006b46d

4.11
Last change on this file since d006b46d was 2c3c657, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 27, 2014 at 12:25:22 PM

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
Line 
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
12 * http://www.rtems.org/license/LICENSE.
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>
26#include <rtems/score/threadimpl.h>
27#include <rtems/score/wkspace.h>
28
29#include <rtems/extensionimpl.h>
30
31#include <rtems/rtems/barrierimpl.h>
32#include <rtems/rtems/dpmemimpl.h>
33#include <rtems/rtems/messageimpl.h>
34#include <rtems/rtems/partimpl.h>
35#include <rtems/rtems/ratemonimpl.h>
36#include <rtems/rtems/regionimpl.h>
37#include <rtems/rtems/semimpl.h>
38#include <rtems/rtems/tasksimpl.h>
39#include <rtems/rtems/timerimpl.h>
40
41#ifdef RTEMS_POSIX_API
42  #include <rtems/posix/barrierimpl.h>
43  #include <rtems/posix/condimpl.h>
44  #include <rtems/posix/mqueueimpl.h>
45  #include <rtems/posix/muteximpl.h>
46  #include <rtems/posix/keyimpl.h>
47  #include <rtems/posix/psignal.h>
48  #include <rtems/posix/pthreadimpl.h>
49  #include <rtems/posix/rwlockimpl.h>
50  #include <rtems/posix/semaphoreimpl.h>
51  #include <rtems/posix/spinlockimpl.h>
52  #include <rtems/posix/timerimpl.h>
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
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
107void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
108{
109  uint32_t *active = &snapshot->rtems_api.active_barriers;
110  size_t i;
111
112  _RTEMS_Lock_allocator();
113
114  _Thread_Kill_zombies();
115
116  get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
117  get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
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
123  _RTEMS_Unlock_allocator();
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.