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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

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

  • Property mode set to 100644
File size: 6.2 KB
RevLine 
[a6500136]1/**
2 *  @file
[e1bce86]3 *
[a6500136]4 *  @brief RTEMS Report Rate Monotonic Statistics
5 *  @ingroup ClassicRateMon
6 */
7
8/*
[5290c5a]9 *  COPYRIGHT (c) 1989-2010.
[e1bce86]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
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[e1bce86]15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[ecdcf01]21#include <rtems/rtems/ratemonimpl.h>
22#include <rtems/rtems/object.h>
[e1bce86]23
[ecdcf01]24#include <inttypes.h>
[e1bce86]25
[c6f7e060]26#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[c3330a8]27  /* We print to 1/10's of milliseconds */
[8677cf7]28  #define NANOSECONDS_DIVIDER 1000
29  #define PERCENT_FMT     "%04" PRId32
[b0ac06f8]30  #define NANOSECONDS_FMT "%06" PRId32
[c3330a8]31#endif
32
[90a5d194]33void rtems_rate_monotonic_report_statistics_with_plugin(
34  void                  *context,
35  rtems_printk_plugin_t  print
36)
[e1bce86]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
[90a5d194]44  if ( !print )
45    return;
46
47  (*print)( context, "Period information by period\n" );
[c6f7e060]48  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[bbb96ceb]49    (*print)( context, "--- CPU times are in seconds ---\n" );
50    (*print)( context, "--- Wall times are in seconds ---\n" );
51  #endif
[c3330a8]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.
[90a5d194]61  (*print)( context,"\
[c3330a8]621234567890123456789012345678901234567890123456789012345678901234567890123456789\
63\n");
[b0ac06f8]64*/
65  (*print)( context, "   ID     OWNER COUNT MISSED     "
[c6f7e060]66       #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[b0ac06f8]67          "     "
68       #endif
69          "CPU TIME     "
[c6f7e060]70       #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
71          "          "
[c3330a8]72       #endif
73          "   WALL TIME\n"
[e1bce86]74  );
[b0ac06f8]75  (*print)( context, "                               "
[c6f7e060]76       #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[b0ac06f8]77          "     "
78       #endif
79          "MIN/MAX/AVG    "
[c6f7e060]80       #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
81          "          "
[b0ac06f8]82       #endif
83          "  MIN/MAX/AVG\n"
84  );
[e1bce86]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;
[05c1886]96
[e1bce86]97    /* If the above passed, so should this but check it anyway */
[115fb76]98    #if defined(RTEMS_DEBUG)
[5290c5a]99      status = rtems_rate_monotonic_get_status( id, &the_status );
[115fb76]100      if ( status != RTEMS_SUCCESSFUL )
101        continue;
[5290c5a]102    #else
103      (void) rtems_rate_monotonic_get_status( id, &the_status );
[115fb76]104    #endif
[e1bce86]105
[bbb96ceb]106    rtems_object_get_name( the_status.owner, sizeof(name), name );
[e1bce86]107
[c3330a8]108    /*
[05c1886]109     *  Print part of report line that is not dependent on granularity
[c3330a8]110     */
[90a5d194]111    (*print)( context,
[c3330a8]112      "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ",
[e1bce86]113      id, name,
[c3330a8]114      the_stats.count, the_stats.missed_count
[e1bce86]115    );
[c3330a8]116
[b0ac06f8]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
[c3330a8]125    /*
126     *  print CPU Usage part of statistics
127     */
128    {
[c6f7e060]129    #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[9dc2c8d]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;
[c3330a8]134
[9dc2c8d]135      _Timespec_Divide_by_integer( total_cpu, the_stats.count, &cpu_average );
[90a5d194]136      (*print)( context,
[b0ac06f8]137        "%" PRId32 "."  NANOSECONDS_FMT "/"        /* min cpu time */
138        "%" PRId32 "."  NANOSECONDS_FMT "/"        /* max cpu time */
139        "%" PRId32 "."  NANOSECONDS_FMT " ",       /* avg cpu time */
[9dc2c8d]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
[c3330a8]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
[90a5d194]154      (*print)( context,
[c3330a8]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    /*
[bbb96ceb]162     *  print wall time part of statistics
[c3330a8]163     */
164    {
[c6f7e060]165    #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
[9dc2c8d]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;
[c16bcc0]170
[9dc2c8d]171      _Timespec_Divide_by_integer(total_wall, the_stats.count, &wall_average);
[90a5d194]172      (*print)( context,
[b0ac06f8]173        "%" PRId32 "." NANOSECONDS_FMT "/"        /* min wall time */
174        "%" PRId32 "." NANOSECONDS_FMT "/"        /* max wall time */
175        "%" PRId32 "." NANOSECONDS_FMT "\n",      /* avg wall time */
[9dc2c8d]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
[c3330a8]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;
[90a5d194]189      (*print)( context,
[c3330a8]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    }
[e1bce86]195  }
196}
[90a5d194]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.