source: rtems/cpukit/rtems/src/ratemonreportstatistics.c @ 1240aade

5
Last change on this file since 1240aade was 506bfc8, checked in by Sebastian Huber <sebastian.huber@…>, on 06/21/16 at 11:30:15

Move printer initialization to separate header

The RTEMS print user need to know nothing about a particular printer
implementation. In particular get rid of the <stdio.h> include which
would be visible via <rtems.h>.

  • Property mode set to 100644
File size: 5.0 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#include <rtems/printer.h>
24
25#include <inttypes.h>
26
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
32void rtems_rate_monotonic_report_statistics_with_plugin(
33  const rtems_printer *printer
34)
35{
36  rtems_status_code                      status;
37  rtems_id                               id;
38  rtems_rate_monotonic_period_statistics the_stats;
39  rtems_rate_monotonic_period_status     the_status;
40  char                                   name[5];
41
42  rtems_printf( printer, "Period information by period\n" );
43  rtems_printf( printer, "--- CPU times are in seconds ---\n" );
44  rtems_printf( printer, "--- Wall times are in seconds ---\n" );
45/*
46Layout by columns -- in memory of Hollerith :)
47
481234567890123456789012345678901234567890123456789012345678901234567890123456789\
49   ID     OWNER COUNT MISSED X
50ididididid NNNN ccccc mmmmmm X
51
52  Uncomment the following if you are tinkering with the formatting.
53  Be sure to test the various cases.
54  (*print)( context,"\
551234567890123456789012345678901234567890123456789012345678901234567890123456789\
56\n");
57*/
58  rtems_printf( printer,
59      "   ID     OWNER COUNT MISSED     "
60      "     CPU TIME                  WALL TIME\n"
61      "                               "
62      "     MIN/MAX/AVG                MIN/MAX/AVG\n"
63  );
64
65  /*
66   * Cycle through all possible ids and try to report on each one.  If it
67   * is a period that is inactive, we just get an error back.  No big deal.
68   */
69  for ( id=_Rate_monotonic_Information.minimum_id ;
70        id <= _Rate_monotonic_Information.maximum_id ;
71        id++ ) {
72    status = rtems_rate_monotonic_get_statistics( id, &the_stats );
73    if ( status != RTEMS_SUCCESSFUL )
74      continue;
75
76    /* If the above passed, so should this but check it anyway */
77    #if defined(RTEMS_DEBUG)
78      status = rtems_rate_monotonic_get_status( id, &the_status );
79      if ( status != RTEMS_SUCCESSFUL )
80        continue;
81    #else
82      (void) rtems_rate_monotonic_get_status( id, &the_status );
83    #endif
84
85    rtems_object_get_name( the_status.owner, sizeof(name), name );
86
87    /*
88     *  Print part of report line that is not dependent on granularity
89     */
90    rtems_printf( printer,
91      "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ",
92      id, name,
93      the_stats.count, the_stats.missed_count
94    );
95
96    /*
97     *  If the count is zero, don't print statistics
98     */
99    if (the_stats.count == 0) {
100      rtems_printf( printer, "\n" );
101      continue;
102    }
103
104    /*
105     *  print CPU Usage part of statistics
106     */
107    {
108      struct timespec  cpu_average;
109      struct timespec *min_cpu = &the_stats.min_cpu_time;
110      struct timespec *max_cpu = &the_stats.max_cpu_time;
111      struct timespec *total_cpu = &the_stats.total_cpu_time;
112
113      _Timespec_Divide_by_integer( total_cpu, the_stats.count, &cpu_average );
114      rtems_printf( printer,
115        "%" PRId32 "."  NANOSECONDS_FMT "/"        /* min cpu time */
116        "%" PRId32 "."  NANOSECONDS_FMT "/"        /* max cpu time */
117        "%" PRId32 "."  NANOSECONDS_FMT " ",       /* avg cpu time */
118        _Timespec_Get_seconds( min_cpu ),
119          _Timespec_Get_nanoseconds( min_cpu ) / NANOSECONDS_DIVIDER,
120        _Timespec_Get_seconds( max_cpu ),
121          _Timespec_Get_nanoseconds( max_cpu ) / NANOSECONDS_DIVIDER,
122        _Timespec_Get_seconds( &cpu_average ),
123          _Timespec_Get_nanoseconds( &cpu_average ) / NANOSECONDS_DIVIDER
124       );
125    }
126
127    /*
128     *  print wall time part of statistics
129     */
130    {
131      struct timespec  wall_average;
132      struct timespec *min_wall = &the_stats.min_wall_time;
133      struct timespec *max_wall = &the_stats.max_wall_time;
134      struct timespec *total_wall = &the_stats.total_wall_time;
135
136      _Timespec_Divide_by_integer(total_wall, the_stats.count, &wall_average);
137      rtems_printf( printer,
138        "%" PRId32 "." NANOSECONDS_FMT "/"        /* min wall time */
139        "%" PRId32 "." NANOSECONDS_FMT "/"        /* max wall time */
140        "%" PRId32 "." NANOSECONDS_FMT "\n",      /* avg wall time */
141        _Timespec_Get_seconds( min_wall ),
142          _Timespec_Get_nanoseconds( min_wall ) / NANOSECONDS_DIVIDER,
143        _Timespec_Get_seconds( max_wall ),
144          _Timespec_Get_nanoseconds( max_wall ) / NANOSECONDS_DIVIDER,
145        _Timespec_Get_seconds( &wall_average ),
146          _Timespec_Get_nanoseconds( &wall_average ) / NANOSECONDS_DIVIDER
147      );
148    }
149  }
150}
151
152void rtems_rate_monotonic_report_statistics( void )
153{
154  rtems_printer printer;
155  rtems_print_printer_printk( &printer );
156  rtems_rate_monotonic_report_statistics_with_plugin( &printer );
157}
Note: See TracBrowser for help on using the repository browser.