source: rtems/cpukit/libmisc/rtmonuse/rtmonuse.c @ e482c592

4.104.114.84.9
Last change on this file since e482c592 was e482c592, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 11, 2003 at 2:21:00 PM

2003-12-11 Joel Sherrill <joel@…>

PR 540/rtems_misc

  • cpuuse/cpuuse.c, rtmonuse/rtmonuse.c: Correct object name printing.
  • Property mode set to 100644
File size: 5.0 KB
Line 
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
17typedef struct {
18  rtems_id     id;
19  unsigned32   count;
20  unsigned32   missed_count;
21  unsigned32   min_cpu_time;
22  unsigned32   max_cpu_time;
23  unsigned32   total_cpu_time;
24  unsigned32   min_wall_time;
25  unsigned32   max_wall_time;
26  unsigned32   total_wall_time;
27}  Period_usage_t;
28
29Period_usage_t *Period_usage_Information;
30
31/*PAGE
32 *
33 *  Period_usage_Initialize
34 */
35
36void 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
52void Period_usage_Reset( void )
53{
54  unsigned32      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
79void 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
128void Period_usage_Dump( void )
129{
130  unsigned32              i;
131  Period_usage_t         *the_usage;
132  Rate_monotonic_Control *the_period;
133  unsigned32              u32_name;
134  char                   *cname;
135  char                    name[5];
136  unsigned32              api_index;
137  Objects_Information    *information;
138 
139  if ( !Period_usage_Information ) {
140    printf( "Period statistics library is not initialized\n" );
141    return;
142  }
143
144  printf( "Period information by period\n" ); 
145  printf( "   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 = (unsigned32)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    printf(
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}
Note: See TracBrowser for help on using the repository browser.