source: rtems/cpukit/rtems/src/ratemonreportstatistics.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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