source: rtems/cpukit/libcsupport/src/resource_snapshot.c @ 26e04e2f

4.115
Last change on this file since 26e04e2f was 7bdb765, checked in by Sebastian Huber <sebastian.huber@…>, on 12/12/14 at 07:46:30

Add POSIX key value pairs to resource snapshot

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2012-2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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/rbtreeimpl.h>
26#include <rtems/score/protectedheap.h>
27#include <rtems/score/threadimpl.h>
28#include <rtems/score/wkspace.h>
29
30#include <rtems/posix/keyimpl.h>
31
32#include <rtems/rtems/barrierimpl.h>
33#include <rtems/extensionimpl.h>
34#include <rtems/rtems/dpmemimpl.h>
35#include <rtems/rtems/messageimpl.h>
36#include <rtems/rtems/partimpl.h>
37#include <rtems/rtems/ratemonimpl.h>
38#include <rtems/rtems/regionimpl.h>
39#include <rtems/rtems/semimpl.h>
40#include <rtems/rtems/tasksimpl.h>
41#include <rtems/rtems/timerimpl.h>
42
43#ifdef RTEMS_POSIX_API
44  #include <rtems/posix/barrierimpl.h>
45  #include <rtems/posix/condimpl.h>
46  #include <rtems/posix/mqueueimpl.h>
47  #include <rtems/posix/muteximpl.h>
48  #include <rtems/posix/psignal.h>
49  #include <rtems/posix/pthreadimpl.h>
50  #include <rtems/posix/rwlockimpl.h>
51  #include <rtems/posix/semaphoreimpl.h>
52  #include <rtems/posix/spinlockimpl.h>
53  #include <rtems/posix/timerimpl.h>
54#endif
55
56static const Objects_Information *const objects_info_table[] = {
57  &_POSIX_Keys_Information,
58  &_Barrier_Information,
59  &_Extension_Information,
60  &_Message_queue_Information,
61  &_Partition_Information,
62  &_Rate_monotonic_Information,
63  &_Dual_ported_memory_Information,
64  &_Region_Information,
65  &_Semaphore_Information,
66  &_RTEMS_tasks_Information,
67  &_Timer_Information
68  #ifdef RTEMS_POSIX_API
69    ,
70    &_POSIX_Barrier_Information,
71    &_POSIX_Condition_variables_Information,
72    &_POSIX_Message_queue_Information,
73    &_POSIX_Message_queue_Information_fds,
74    &_POSIX_Mutex_Information,
75    &_POSIX_RWLock_Information,
76    &_POSIX_Semaphore_Information,
77    &_POSIX_Spinlock_Information,
78    &_POSIX_Threads_Information,
79    &_POSIX_Timer_Information
80  #endif
81};
82
83static int open_files(void)
84{
85  int free_count = 0;
86  rtems_libio_t *iop;
87
88  rtems_libio_lock();
89
90  iop = rtems_libio_iop_freelist;
91  while (iop != NULL) {
92    ++free_count;
93
94    iop = iop->data1;
95  }
96
97  rtems_libio_unlock();
98
99  return (int) rtems_libio_number_iops - free_count;
100}
101
102static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
103{
104  _Heap_Get_information(heap, info);
105  memset(&info->Stats, 0, sizeof(info->Stats));
106}
107
108static bool count_posix_key_value_pairs(
109  const RBTree_Node *node,
110  RBTree_Direction dir,
111  void *visitor_arg
112)
113{
114  uint32_t *count = visitor_arg;
115
116  (void) node;
117  (void) dir;
118
119  ++(*count);
120
121  return false;
122}
123
124static uint32_t get_active_posix_key_value_pairs(void)
125{
126  uint32_t count = 0;
127
128  _Thread_Disable_dispatch();
129  _RBTree_Iterate(
130    &_POSIX_Keys_Key_value_lookup_tree,
131    RBT_LEFT,
132    count_posix_key_value_pairs,
133    &count
134  );
135  _Thread_Enable_dispatch();
136
137  return count;
138}
139
140void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
141{
142  uint32_t *active = &snapshot->active_posix_keys;
143  size_t i;
144
145  memset(snapshot, 0, sizeof(*snapshot));
146
147  _RTEMS_Lock_allocator();
148
149  _Thread_Kill_zombies();
150
151  get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
152  get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
153
154  for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
155    active [i] = _Objects_Active_count(objects_info_table[i]);
156  }
157
158  _RTEMS_Unlock_allocator();
159
160  snapshot->active_posix_key_value_pairs = get_active_posix_key_value_pairs();
161  snapshot->open_files = open_files();
162}
163
164bool rtems_resource_snapshot_equal(
165  const rtems_resource_snapshot *a,
166  const rtems_resource_snapshot *b
167)
168{
169  return memcmp(a, b, sizeof(*a)) == 0;
170}
171
172bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
173{
174  rtems_resource_snapshot now;
175
176  rtems_resource_snapshot_take(&now);
177
178  return rtems_resource_snapshot_equal(&now, snapshot);
179}
Note: See TracBrowser for help on using the repository browser.