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

4.104.114.84.95
Last change on this file since fc7bc51 was fc7bc51, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 9, 1997 at 8:18:54 PM

new files.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  $Id$
3 */
4
5#include <rtems.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <assert.h>
9
10#include "rtmonuse.h"
11
12typedef struct {
13  rtems_id     id;
14  unsigned32   count;
15  unsigned32   missed_count;
16  unsigned32   min_cpu_time;
17  unsigned32   max_cpu_time;
18  unsigned32   total_cpu_time;
19  unsigned32   min_wall_time;
20  unsigned32   max_wall_time;
21  unsigned32   total_wall_time;
22}  Period_usage_t;
23
24Period_usage_t *Period_usage_Information;
25
26/*PAGE
27 *
28 *  Period_usage_Initialize
29 */
30
31void Period_usage_Initialize( void )
32{
33  int             maximum;
34
35  maximum = _Configuration_Table->RTEMS_api_configuration->maximum_periods;
36 
37  Period_usage_Information = malloc( sizeof(Period_usage_t) * (maximum+1) );
38
39  Period_usage_Reset();
40}
41
42/*PAGE
43 *
44 *  Period_usage_Reset
45 */
46
47void Period_usage_Reset( void )
48{
49  unsigned32      i;
50  Period_usage_t *the_usage;
51
52  for ( i=0 ;
53        i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ;
54        i++ ) {
55    the_usage = &Period_usage_Information[ i ];
56 
57    the_usage->count           = 0;
58    the_usage->missed_count    = 0;
59    the_usage->min_cpu_time    = 0xFFFFFFFF;
60    the_usage->max_cpu_time    = 0;
61    the_usage->total_cpu_time  = 0;
62    the_usage->min_wall_time   = 0xFFFFFFFF;
63    the_usage->max_wall_time   = 0;
64    the_usage->total_wall_time = 0;
65 
66  }
67}
68
69/*PAGE
70 *
71 *  Period_usage_Update
72 */
73
74void Period_usage_Update( 
75  rtems_id     id
76)
77{
78  rtems_rate_monotonic_period_status rm_status;
79  rtems_status_code                  status;
80  Period_usage_t                    *the_usage;
81
82  assert( Period_usage_Information );
83
84  status = rtems_rate_monotonic_get_status( id, &rm_status );
85  assert( status == RTEMS_SUCCESSFUL );
86
87  the_usage = &Period_usage_Information[ rtems_get_index( id ) ];
88
89  the_usage->id = id;
90  the_usage->count++;
91  if ( rm_status.state == RATE_MONOTONIC_EXPIRED )
92    the_usage->missed_count++;
93  the_usage->total_cpu_time  += rm_status.ticks_executed_since_last_period;
94  the_usage->total_wall_time += rm_status.ticks_since_last_period;
95
96  /*
97   *  Update CPU time
98   */
99
100  if ( rm_status.ticks_executed_since_last_period < the_usage->min_cpu_time )
101    the_usage->min_cpu_time = rm_status.ticks_executed_since_last_period;
102
103  if ( rm_status.ticks_executed_since_last_period > the_usage->max_cpu_time )
104    the_usage->max_cpu_time = rm_status.ticks_executed_since_last_period;
105
106  /*
107   *  Update Wall time
108   */
109
110  if ( rm_status.ticks_since_last_period < the_usage->min_wall_time )
111    the_usage->min_wall_time = rm_status.ticks_since_last_period;
112
113  if ( rm_status.ticks_since_last_period > the_usage->max_wall_time )
114    the_usage->max_wall_time = rm_status.ticks_since_last_period;
115
116}
117
118/*PAGE
119 *
120 *  Period_usage_Dump
121 */
122
123void Period_usage_Dump( void )
124{
125  unsigned32              i;
126  Period_usage_t         *the_usage;
127  Rate_monotonic_Control *the_period;
128  unsigned32              u32_name;
129  char                    name[5];
130 
131  printf( "Period information by period\n" ); 
132  printf( "   ID      OWNER   PERIODS  MISSED    CPU TIME    WALL TIME\n" );
133
134  /*
135   *  RTEMS does not use an index of zero for object ids.
136   */
137
138  for ( i=1 ;
139        i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ;
140        i++ ) {
141    the_usage = &Period_usage_Information[ i ];
142    if ( the_usage->count == 0 )
143      continue;
144
145    the_period =
146      (Rate_monotonic_Control *)_Rate_monotonic_Information.local_table[ i ];
147
148    if ( the_period->owner )
149      u32_name = *(unsigned32 *)the_period->owner->Object.name;
150    else
151      u32_name = rtems_build_name(' ', ' ', ' ', ' ');
152
153    name[ 0 ] = (u32_name >> 24) & 0xff;
154    name[ 1 ] = (u32_name >> 16) & 0xff;
155    name[ 2 ] = (u32_name >>  8) & 0xff;
156    name[ 3 ] = (u32_name >>  0) & 0xff;
157    name[ 4 ] = '\0';
158
159    printf(
160      "0x%08x  %4s   %6d   %3d       %d/%d/%5.2f    %d/%d/%3.2f\n",
161      the_usage->id,
162      name,
163      the_usage->count,
164      the_usage->missed_count,
165      the_usage->min_cpu_time,
166      the_usage->max_cpu_time,
167      (double) the_usage->total_cpu_time / (double) the_usage->count,
168      the_usage->min_wall_time,
169      the_usage->max_wall_time,
170      (double) the_usage->total_wall_time / (double) the_usage->count
171    );
172  }
173}
Note: See TracBrowser for help on using the repository browser.