source: rtems/cpukit/libmisc/rtmonuse/rtmonuse.c @ 738a9ae

4.104.114.84.95
Last change on this file since 738a9ae was 550c3df7, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/08/03 at 08:39:16

2003-07-08 Ralf Corsepius <corsepiu@…>

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