source: rtems/cpukit/rtems/src/ratemonreportstatistics.c @ 8677cf7

4.104.114.84.95
Last change on this file since 8677cf7 was 8677cf7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/06/07 at 22:09:18

2007-09-06 Joel Sherrill <joel.sherrill@…>

  • rtems/src/ratemonperiod.c: Clean up.
  • rtems/src/ratemonreportstatistics.c: Clarify period statistics output.
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 *  Rate Monotonic Manager -- Report Statistics for All Periods
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems.h>
19#include <stdlib.h>
20#include <ctype.h>
21#include <inttypes.h>
22
23#include <rtems/bspIo.h>
24
25#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
26    defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
27  #include <rtems/score/timespec.h>
28
29  /* We print to 1/10's of milliseconds */
30  #define NANOSECONDS_DIVIDER 1000
31  #define PERCENT_FMT     "%04" PRId32
32  #define NANOSECONDS_FMT "%" PRId32
33#endif
34
35/*
36 *  This directive allows a thread to print the statistics information
37 *  on ALL period instances which have non-zero counts using printk.
38 *
39 *  The implementation of this directive straddles the fence between
40 *  inside and outside of RTEMS.  It is presented as part of the Manager
41 *  but actually uses other services of the Manager.
42 */
43void rtems_rate_monotonic_report_statistics( void )
44{
45  rtems_status_code                      status;
46  rtems_id                               id;
47  rtems_rate_monotonic_period_statistics the_stats;
48  rtems_rate_monotonic_period_status     the_status;
49  char                                   name[5];
50
51  printk( "Period information by period\n" );
52#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS)
53  printk( "--- Period times are seconds:microseconds ---\n" );
54#endif
55   
56#if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
57  printk( "--- CPU Usage times are seconds:microseconds ---\n" );
58#endif
59/*
60Layout by columns -- in memory of Hollerith :)
61
621234567890123456789012345678901234567890123456789012345678901234567890123456789\
63   ID     OWNER COUNT MISSED X
64ididididid NNNN ccccc mmmmmm X
65
66  Uncomment the following if you are tinkering with the formatting.
67  Be sure to test the various cases.
68*/
69  printk("\
701234567890123456789012345678901234567890123456789012345678901234567890123456789\
71\n");
72  printk( "   ID     OWNER COUNT MISSED     CPU TIME     "
73       #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
74          "    "
75       #endif
76       #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
77          "   "
78       #endif
79          "   WALL TIME\n"
80  );
81
82  /*
83   * Cycle through all possible ids and try to report on each one.  If it
84   * is a period that is inactive, we just get an error back.  No big deal.
85   */
86  for ( id=_Rate_monotonic_Information.minimum_id ;
87        id <= _Rate_monotonic_Information.maximum_id ;
88        id++ ) {
89    status = rtems_rate_monotonic_get_statistics( id, &the_stats );
90    if ( status != RTEMS_SUCCESSFUL )
91      continue;
92   
93    /* If the above passed, so should this but check it anyway */
94    status = rtems_rate_monotonic_get_status( id, &the_status );
95    if ( status != RTEMS_SUCCESSFUL )
96      continue;
97   
98    if ( the_stats.count == 0 )
99      continue;
100
101    name[ 0 ] = '\0';
102
103    if ( the_status.owner ) {
104      rtems_object_get_name( the_status.owner, sizeof(name), name );
105    }
106
107    /*
108     *  Print part of report line that is not dependent on granularity
109     */
110
111    printk(
112      "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ",
113      id, name,
114      the_stats.count, the_stats.missed_count
115    );
116
117    /*
118     *  print CPU Usage part of statistics
119     */
120    {
121    #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
122      struct timespec   cpu_average;
123
124      _Timespec_Divide_by_integer(
125         &the_stats.total_cpu_time,
126         the_stats.count,
127         &cpu_average
128      );
129      printk(
130        "%" PRId32 ":"  NANOSECONDS_FMT "/"        /* min cpu time */
131        "%" PRId32 ":"  NANOSECONDS_FMT "/"        /* max cpu time */
132        "%" PRId32 ":"  NANOSECONDS_FMT " ",       /* avg cpu time */
133        the_stats.min_cpu_time.tv_sec,
134          the_stats.min_cpu_time.tv_nsec / NANOSECONDS_DIVIDER,
135        the_stats.max_cpu_time.tv_sec,
136          the_stats.max_cpu_time.tv_nsec / NANOSECONDS_DIVIDER,
137        cpu_average.tv_sec,
138          cpu_average.tv_nsec / NANOSECONDS_DIVIDER
139       );
140    #else
141      uint32_t ival_cpu, fval_cpu;
142
143      ival_cpu = the_stats.total_cpu_time * 100 / the_stats.count;
144      fval_cpu = ival_cpu % 100;
145      ival_cpu /= 100;
146
147      printk(
148        "%3" PRId32 "/%4" PRId32 "/%3" PRId32 ".%02" PRId32 " ",
149        the_stats.min_cpu_time, the_stats.max_cpu_time, ival_cpu, fval_cpu
150      );
151    #endif
152    }
153
154    /*
155     *  print Wall time part of statistics
156     */
157    {
158    #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
159      struct timespec  wall_average;
160      _Timespec_Divide_by_integer(
161         &the_stats.total_wall_time,
162         the_stats.count,
163         &wall_average
164      );
165      printk(
166        "%" PRId32 ":" PERCENT_FMT "/"        /* min wall time */
167        "%" PRId32 ":" PERCENT_FMT "/"        /* max wall time */
168        "%" PRId32 ":" PERCENT_FMT "\n",      /* avg wall time */
169        the_stats.min_wall_time.tv_sec,
170          the_stats.min_wall_time.tv_nsec / NANOSECONDS_DIVIDER,
171        the_stats.max_wall_time.tv_sec,
172          the_stats.max_wall_time.tv_nsec / NANOSECONDS_DIVIDER,
173        wall_average.tv_sec,
174          wall_average.tv_nsec / NANOSECONDS_DIVIDER
175      );
176    #else
177      uint32_t  ival_wall, fval_wall;
178
179      ival_wall = the_stats.total_wall_time * 100 / the_stats.count;
180      fval_wall = ival_wall % 100;
181      ival_wall /= 100;
182      printk(
183        "%3" PRId32 "/%4" PRId32 "/%3" PRId32 ".%02" PRId32 "\n",
184        the_stats.min_wall_time, the_stats.max_wall_time, ival_wall, fval_wall
185      );
186    #endif
187    }
188  }
189}
Note: See TracBrowser for help on using the repository browser.