File indexing completed on 2025-05-11 08:24:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <rtems/libcsupport.h>
0033
0034 #include <string.h>
0035
0036 #include <rtems/libio_.h>
0037 #include <rtems/malloc.h>
0038 #include <rtems/score/rbtreeimpl.h>
0039 #include <rtems/score/protectedheap.h>
0040 #include <rtems/score/threadimpl.h>
0041 #include <rtems/score/wkspace.h>
0042 #include <rtems/posix/keyimpl.h>
0043
0044 static const struct {
0045 Objects_APIs api;
0046 uint16_t cls;
0047 } objects_info_table[] = {
0048 { OBJECTS_POSIX_API, OBJECTS_POSIX_KEYS },
0049 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS },
0050 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS },
0051 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES },
0052 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS },
0053 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS },
0054 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PORTS },
0055 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS },
0056 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES },
0057 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS },
0058 { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS },
0059 { OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES },
0060 { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES },
0061 { OBJECTS_POSIX_API, OBJECTS_POSIX_THREADS }
0062 #ifdef RTEMS_POSIX_API
0063 ,
0064 { OBJECTS_POSIX_API, OBJECTS_POSIX_TIMERS }
0065 #endif
0066 };
0067
0068 static int open_files(void)
0069 {
0070 int free_count = 0;
0071 rtems_libio_t *iop;
0072
0073 rtems_libio_lock();
0074
0075 iop = rtems_libio_iop_free_head;
0076 while (iop != NULL) {
0077 ++free_count;
0078
0079 iop = iop->data1;
0080 }
0081
0082 rtems_libio_unlock();
0083
0084 return (int) rtems_libio_number_iops - free_count;
0085 }
0086
0087 static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
0088 {
0089 _Heap_Get_information(heap, info);
0090 memset(&info->Stats, 0, sizeof(info->Stats));
0091 }
0092
0093 static POSIX_Keys_Control *get_next_key(Objects_Id *id)
0094 {
0095 return (POSIX_Keys_Control *)
0096 _Objects_Get_next(*id, &_POSIX_Keys_Information, id);
0097 }
0098
0099 static uint32_t get_active_posix_key_value_pairs(void)
0100 {
0101 uint32_t count = 0;
0102 Objects_Id id = OBJECTS_ID_INITIAL_INDEX;
0103 POSIX_Keys_Control *the_key;
0104
0105 while ((the_key = get_next_key(&id)) != NULL ) {
0106 count += _Chain_Node_count_unprotected(&the_key->Key_value_pairs);
0107 _Objects_Allocator_unlock();
0108 }
0109
0110 return count;
0111 }
0112
0113 void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
0114 {
0115 uint32_t *active;
0116 size_t i;
0117
0118 memset(snapshot, 0, sizeof(*snapshot));
0119
0120 _RTEMS_Lock_allocator();
0121
0122 _Thread_Kill_zombies();
0123
0124 get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
0125 get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
0126
0127 active = &snapshot->active_posix_keys;
0128
0129 for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
0130 const Objects_Information *information;
0131
0132 information = _Objects_Get_information(
0133 objects_info_table[i].api,
0134 objects_info_table[i].cls
0135 );
0136
0137 if (information != NULL) {
0138 active[i] = _Objects_Active_count(information);
0139 }
0140 }
0141
0142 _RTEMS_Unlock_allocator();
0143
0144 snapshot->active_posix_key_value_pairs = get_active_posix_key_value_pairs();
0145 snapshot->open_files = open_files();
0146 }
0147
0148 bool rtems_resource_snapshot_equal(
0149 const rtems_resource_snapshot *a,
0150 const rtems_resource_snapshot *b
0151 )
0152 {
0153 return memcmp(a, b, sizeof(*a)) == 0;
0154 }
0155
0156 bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
0157 {
0158 rtems_resource_snapshot now;
0159
0160 rtems_resource_snapshot_take(&now);
0161
0162 return rtems_resource_snapshot_equal(&now, snapshot);
0163 }