1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #ifdef HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <rtems.h> |
---|
10 | #include <stdlib.h> |
---|
11 | #include <stdio.h> |
---|
12 | #include <assert.h> |
---|
13 | #include <ctype.h> |
---|
14 | |
---|
15 | #include <rtems/rtmonuse.h> |
---|
16 | |
---|
17 | typedef struct { |
---|
18 | rtems_id id; |
---|
19 | uint32_t count; |
---|
20 | uint32_t missed_count; |
---|
21 | uint32_t min_cpu_time; |
---|
22 | uint32_t max_cpu_time; |
---|
23 | uint32_t total_cpu_time; |
---|
24 | uint32_t min_wall_time; |
---|
25 | uint32_t max_wall_time; |
---|
26 | uint32_t total_wall_time; |
---|
27 | } Period_usage_t; |
---|
28 | |
---|
29 | Period_usage_t *Period_usage_Information; |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * Period_usage_Initialize |
---|
34 | */ |
---|
35 | |
---|
36 | void Period_usage_Initialize( void ) |
---|
37 | { |
---|
38 | int maximum; |
---|
39 | |
---|
40 | maximum = _Configuration_Table->RTEMS_api_configuration->maximum_periods; |
---|
41 | |
---|
42 | Period_usage_Information = malloc( sizeof(Period_usage_t) * (maximum+1) ); |
---|
43 | |
---|
44 | Period_usage_Reset(); |
---|
45 | } |
---|
46 | |
---|
47 | /*PAGE |
---|
48 | * |
---|
49 | * Period_usage_Reset |
---|
50 | */ |
---|
51 | |
---|
52 | void Period_usage_Reset( void ) |
---|
53 | { |
---|
54 | uint32_t i; |
---|
55 | Period_usage_t *the_usage; |
---|
56 | |
---|
57 | for ( i=0 ; |
---|
58 | i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ; |
---|
59 | i++ ) { |
---|
60 | the_usage = &Period_usage_Information[ i ]; |
---|
61 | |
---|
62 | the_usage->count = 0; |
---|
63 | the_usage->missed_count = 0; |
---|
64 | the_usage->min_cpu_time = 0xFFFFFFFF; |
---|
65 | the_usage->max_cpu_time = 0; |
---|
66 | the_usage->total_cpu_time = 0; |
---|
67 | the_usage->min_wall_time = 0xFFFFFFFF; |
---|
68 | the_usage->max_wall_time = 0; |
---|
69 | the_usage->total_wall_time = 0; |
---|
70 | |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | /*PAGE |
---|
75 | * |
---|
76 | * Period_usage_Update |
---|
77 | */ |
---|
78 | |
---|
79 | void Period_usage_Update( |
---|
80 | rtems_id id |
---|
81 | ) |
---|
82 | { |
---|
83 | rtems_rate_monotonic_period_status rm_status; |
---|
84 | rtems_status_code status; |
---|
85 | Period_usage_t *the_usage; |
---|
86 | |
---|
87 | assert( Period_usage_Information ); |
---|
88 | |
---|
89 | status = rtems_rate_monotonic_get_status( id, &rm_status ); |
---|
90 | assert( status == RTEMS_SUCCESSFUL ); |
---|
91 | |
---|
92 | the_usage = &Period_usage_Information[ rtems_get_index( id ) ]; |
---|
93 | |
---|
94 | the_usage->id = id; |
---|
95 | the_usage->count++; |
---|
96 | if ( rm_status.state == RATE_MONOTONIC_EXPIRED ) |
---|
97 | the_usage->missed_count++; |
---|
98 | the_usage->total_cpu_time += rm_status.ticks_executed_since_last_period; |
---|
99 | the_usage->total_wall_time += rm_status.ticks_since_last_period; |
---|
100 | |
---|
101 | /* |
---|
102 | * Update CPU time |
---|
103 | */ |
---|
104 | |
---|
105 | if ( rm_status.ticks_executed_since_last_period < the_usage->min_cpu_time ) |
---|
106 | the_usage->min_cpu_time = rm_status.ticks_executed_since_last_period; |
---|
107 | |
---|
108 | if ( rm_status.ticks_executed_since_last_period > the_usage->max_cpu_time ) |
---|
109 | the_usage->max_cpu_time = rm_status.ticks_executed_since_last_period; |
---|
110 | |
---|
111 | /* |
---|
112 | * Update Wall time |
---|
113 | */ |
---|
114 | |
---|
115 | if ( rm_status.ticks_since_last_period < the_usage->min_wall_time ) |
---|
116 | the_usage->min_wall_time = rm_status.ticks_since_last_period; |
---|
117 | |
---|
118 | if ( rm_status.ticks_since_last_period > the_usage->max_wall_time ) |
---|
119 | the_usage->max_wall_time = rm_status.ticks_since_last_period; |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | /*PAGE |
---|
124 | * |
---|
125 | * Period_usage_Dump |
---|
126 | */ |
---|
127 | |
---|
128 | void Period_usage_Dump( void ) |
---|
129 | { |
---|
130 | uint32_t i; |
---|
131 | Period_usage_t *the_usage; |
---|
132 | Rate_monotonic_Control *the_period; |
---|
133 | uint32_t u32_name; |
---|
134 | char *cname; |
---|
135 | char name[5]; |
---|
136 | uint32_t api_index; |
---|
137 | Objects_Information *information; |
---|
138 | |
---|
139 | if ( !Period_usage_Information ) { |
---|
140 | fprintf(stdout, "Period statistics library is not initialized\n" ); |
---|
141 | return; |
---|
142 | } |
---|
143 | |
---|
144 | fprintf(stdout, "Period information by period\n" ); |
---|
145 | fprintf(stdout, " ID OWNER PERIODS MISSED CPU TIME WALL TIME\n" ); |
---|
146 | |
---|
147 | /* |
---|
148 | * RTEMS does not use an index of zero for object ids. |
---|
149 | */ |
---|
150 | |
---|
151 | for ( i=1 ; |
---|
152 | i<=_Configuration_Table->RTEMS_api_configuration->maximum_periods ; |
---|
153 | i++ ) { |
---|
154 | the_usage = &Period_usage_Information[ i ]; |
---|
155 | if ( the_usage->count == 0 ) |
---|
156 | continue; |
---|
157 | |
---|
158 | the_period = |
---|
159 | (Rate_monotonic_Control *)_Rate_monotonic_Information.local_table[ i ]; |
---|
160 | |
---|
161 | name[ 0 ] = ' '; |
---|
162 | name[ 1 ] = ' '; |
---|
163 | name[ 2 ] = ' '; |
---|
164 | name[ 3 ] = ' '; |
---|
165 | name[ 4 ] = '\0'; |
---|
166 | |
---|
167 | if ( the_period->owner ) { |
---|
168 | api_index = _Objects_Get_API(the_period->owner->Object.id); |
---|
169 | information = _Objects_Information_table[ api_index ][ 1 ]; |
---|
170 | |
---|
171 | if ( information->is_string ) { |
---|
172 | cname = the_period->owner->Object.name; |
---|
173 | name[ 0 ] = cname[0]; |
---|
174 | name[ 1 ] = cname[1]; |
---|
175 | name[ 2 ] = cname[2]; |
---|
176 | name[ 3 ] = cname[3]; |
---|
177 | name[ 4 ] = '\0'; |
---|
178 | } else { |
---|
179 | u32_name = (uint32_t )the_period->owner->Object.name; |
---|
180 | name[ 0 ] = (u32_name >> 24) & 0xff; |
---|
181 | name[ 1 ] = (u32_name >> 16) & 0xff; |
---|
182 | name[ 2 ] = (u32_name >> 8) & 0xff; |
---|
183 | name[ 3 ] = (u32_name >> 0) & 0xff; |
---|
184 | name[ 4 ] = '\0'; |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | if ( !isprint(name[0]) ) name[0] = '*'; |
---|
189 | if ( !isprint(name[1]) ) name[1] = '*'; |
---|
190 | if ( !isprint(name[2]) ) name[2] = '*'; |
---|
191 | if ( !isprint(name[3]) ) name[3] = '*'; |
---|
192 | |
---|
193 | |
---|
194 | fprintf(stdout, |
---|
195 | "0x%08x %4s %6d %3d %d/%d/%5.2f %d/%d/%3.2f\n", |
---|
196 | the_usage->id, |
---|
197 | name, |
---|
198 | the_usage->count, |
---|
199 | the_usage->missed_count, |
---|
200 | the_usage->min_cpu_time, |
---|
201 | the_usage->max_cpu_time, |
---|
202 | (double) the_usage->total_cpu_time / (double) the_usage->count, |
---|
203 | the_usage->min_wall_time, |
---|
204 | the_usage->max_wall_time, |
---|
205 | (double) the_usage->total_wall_time / (double) the_usage->count |
---|
206 | ); |
---|
207 | } |
---|
208 | } |
---|