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

Last change on this file was c4fb617, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:28:43

cpukit/rtems/src/[a-r]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicRateMonotonic
7 *
8 * @brief This source file contains the implementation of
9 *   rtems_rate_monotonic_report_statistics_with_plugin().
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2010.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#endif
41
42#include <rtems/rtems/ratemonimpl.h>
43#include <rtems/rtems/object.h>
44#include <rtems/printer.h>
45
46#include <inttypes.h>
47#include <rtems/inttypes.h>
48
49/* We print to 1/10's of milliseconds */
50#define NANOSECONDS_DIVIDER 1000L
51#define PERCENT_FMT     "%04" PRId32
52#define NANOSECONDS_FMT "%06ld"
53
54void rtems_rate_monotonic_report_statistics_with_plugin(
55  const rtems_printer *printer
56)
57{
58  rtems_status_code                      status;
59  rtems_id                               maximum_id;
60  rtems_id                               id;
61  rtems_rate_monotonic_period_statistics the_stats;
62  rtems_rate_monotonic_period_status     the_status;
63  char                                   name[5];
64
65  rtems_printf( printer, "Period information by period\n" );
66  rtems_printf( printer, "--- CPU times are in seconds ---\n" );
67  rtems_printf( printer, "--- Wall times are in seconds ---\n" );
68/*
69Layout by columns -- in memory of Hollerith :)
70
711234567890123456789012345678901234567890123456789012345678901234567890123456789\
72   ID     OWNER COUNT MISSED X
73ididididid NNNN ccccc mmmmmm X
74
75  Uncomment the following if you are tinkering with the formatting.
76  Be sure to test the various cases.
77  (*print)( context,"\
781234567890123456789012345678901234567890123456789012345678901234567890123456789\
79\n");
80*/
81  rtems_printf( printer,
82      "   ID     OWNER COUNT MISSED     "
83      "     CPU TIME                  WALL TIME\n"
84      "                               "
85      "     MIN/MAX/AVG                MIN/MAX/AVG\n"
86  );
87
88  /*
89   * Cycle through all possible ids and try to report on each one.  If it
90   * is a period that is inactive, we just get an error back.  No big deal.
91   */
92  maximum_id = _Rate_monotonic_Information.maximum_id;
93  for (
94    id = _Objects_Get_minimum_id( maximum_id ) ;
95    id <= maximum_id ;
96    ++id
97  ) {
98    status = rtems_rate_monotonic_get_statistics( id, &the_stats );
99    if ( status != RTEMS_SUCCESSFUL )
100      continue;
101
102    /* If the above passed, so should this but check it anyway */
103    #if defined(RTEMS_DEBUG)
104      status = rtems_rate_monotonic_get_status( id, &the_status );
105      if ( status != RTEMS_SUCCESSFUL )
106        continue;
107    #else
108      (void) rtems_rate_monotonic_get_status( id, &the_status );
109    #endif
110
111    rtems_object_get_name( the_status.owner, sizeof(name), name );
112
113    /*
114     *  Print part of report line that is not dependent on granularity
115     */
116    rtems_printf( printer,
117      "0x%08" PRIx32 " %4s %5" PRId32 " %6" PRId32 " ",
118      id, name,
119      the_stats.count, the_stats.missed_count
120    );
121
122    /*
123     *  If the count is zero, don't print statistics
124     */
125    if (the_stats.count == 0) {
126      rtems_printf( printer, "\n" );
127      continue;
128    }
129
130    /*
131     *  print CPU Usage part of statistics
132     */
133    {
134      struct timespec  cpu_average;
135      struct timespec *min_cpu = &the_stats.min_cpu_time;
136      struct timespec *max_cpu = &the_stats.max_cpu_time;
137      struct timespec *total_cpu = &the_stats.total_cpu_time;
138
139      _Timespec_Divide_by_integer( total_cpu, the_stats.count, &cpu_average );
140      rtems_printf( printer,
141        "%" PRIdtime_t "."  NANOSECONDS_FMT "/"        /* min cpu time */
142        "%" PRIdtime_t "."  NANOSECONDS_FMT "/"        /* max cpu time */
143        "%" PRIdtime_t "."  NANOSECONDS_FMT " ",       /* avg cpu time */
144        _Timespec_Get_seconds( min_cpu ),
145          _Timespec_Get_nanoseconds( min_cpu ) / NANOSECONDS_DIVIDER,
146        _Timespec_Get_seconds( max_cpu ),
147          _Timespec_Get_nanoseconds( max_cpu ) / NANOSECONDS_DIVIDER,
148        _Timespec_Get_seconds( &cpu_average ),
149          _Timespec_Get_nanoseconds( &cpu_average ) / NANOSECONDS_DIVIDER
150       );
151    }
152
153    /*
154     *  print wall time part of statistics
155     */
156    {
157      struct timespec  wall_average;
158      struct timespec *min_wall = &the_stats.min_wall_time;
159      struct timespec *max_wall = &the_stats.max_wall_time;
160      struct timespec *total_wall = &the_stats.total_wall_time;
161
162      _Timespec_Divide_by_integer(total_wall, the_stats.count, &wall_average);
163      rtems_printf( printer,
164        "%" PRIdtime_t "." NANOSECONDS_FMT "/"        /* min wall time */
165        "%" PRIdtime_t "." NANOSECONDS_FMT "/"        /* max wall time */
166        "%" PRIdtime_t "." NANOSECONDS_FMT "\n",      /* avg wall time */
167        _Timespec_Get_seconds( min_wall ),
168          _Timespec_Get_nanoseconds( min_wall ) / NANOSECONDS_DIVIDER,
169        _Timespec_Get_seconds( max_wall ),
170          _Timespec_Get_nanoseconds( max_wall ) / NANOSECONDS_DIVIDER,
171        _Timespec_Get_seconds( &wall_average ),
172          _Timespec_Get_nanoseconds( &wall_average ) / NANOSECONDS_DIVIDER
173      );
174    }
175  }
176}
177
178void rtems_rate_monotonic_report_statistics( void )
179{
180  rtems_printer printer;
181  rtems_print_printer_printk( &printer );
182  rtems_rate_monotonic_report_statistics_with_plugin( &printer );
183}
Note: See TracBrowser for help on using the repository browser.