source: rtems/cpukit/libmisc/cpuuse/cpuusagereport.c @ e0938c2

4.115
Last change on this file since e0938c2 was e6b31b27, checked in by Joel Sherrill <joel.sherrill@…>, on 05/27/15 at 15:13:58

Remove use ticks for statistics configure option.

This was obsolete and broken based upon recent time keeping changes.

Thie build option was previously enabled by adding
USE_TICKS_FOR_STATISTICS=1 to the configure command line.

This propagated into the code as preprocessor conditionals
using the RTEMS_USE_TICKS_FOR_STATISTICS conditional.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief CPU Usage Report
5 * @ingroup libmisc_cpuuse CPU Usage
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 <string.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <ctype.h>
25#include <inttypes.h>
26
27#include <rtems/cpuuse.h>
28#include <rtems/score/objectimpl.h>
29#include <rtems/score/threadimpl.h>
30#include <rtems/score/todimpl.h>
31#include <rtems/score/watchdogimpl.h>
32
33/*
34 *  rtems_cpu_usage_report
35 */
36void rtems_cpu_usage_report_with_plugin(
37  void                  *context,
38  rtems_printk_plugin_t  print
39)
40{
41  uint32_t             i;
42  uint32_t             api_index;
43  Thread_Control      *the_thread;
44  Objects_Information *information;
45  char                 name[13];
46  uint32_t             ival, fval;
47  Timestamp_Control  uptime, total, ran, uptime_at_last_reset;
48  uint32_t seconds, nanoseconds;
49
50  if ( !print )
51    return;
52
53  /*
54   *  When not using nanosecond CPU usage resolution, we have to count
55   *  the number of "ticks" we gave credit for to give the user a rough
56   *  guideline as to what each number means proportionally.
57   */
58  _Timestamp_Set_to_zero( &total );
59  uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
60
61  (*print)(
62     context,
63     "-------------------------------------------------------------------------------\n"
64     "                              CPU USAGE BY THREAD\n"
65     "------------+----------------------------------------+---------------+---------\n"
66     " ID         | NAME                                   | SECONDS       | PERCENT\n"
67     "------------+----------------------------------------+---------------+---------\n"
68  );
69
70  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
71    #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
72      if ( !_Objects_Information_table[ api_index ] )
73        continue;
74    #endif
75
76    information = _Objects_Information_table[ api_index ][ 1 ];
77    if ( information ) {
78      for ( i=1 ; i <= information->maximum ; i++ ) {
79        the_thread = (Thread_Control *)information->local_table[ i ];
80
81        if ( !the_thread )
82          continue;
83
84        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
85
86        (*print)(
87          context,
88          " 0x%08" PRIx32 " | %-38s |",
89          the_thread->Object.id,
90          name
91        );
92
93        {
94          Timestamp_Control last;
95
96          /*
97           * If this is the currently executing thread, account for time
98           * since the last context switch.
99           */
100          ran = the_thread->cpu_time_used;
101          if ( _Thread_Get_time_of_last_context_switch( the_thread, &last ) ) {
102            Timestamp_Control used;
103            _TOD_Get_uptime( &uptime );
104            _Timestamp_Subtract( &last, &uptime, &used );
105            _Timestamp_Add_to( &ran, &used );
106          } else {
107            _TOD_Get_uptime( &uptime );
108          }
109          _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
110          _Timestamp_Divide( &ran, &total, &ival, &fval );
111
112          /*
113           * Print the information
114           */
115
116          seconds = _Timestamp_Get_seconds( &ran );
117          nanoseconds = _Timestamp_Get_nanoseconds( &ran ) /
118            TOD_NANOSECONDS_PER_MICROSECOND;
119          (*print)( context,
120            "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
121            seconds, nanoseconds,
122            ival, fval
123          );
124        }
125      }
126    }
127  }
128
129  seconds = _Timestamp_Get_seconds( &total );
130  nanoseconds = _Timestamp_Get_nanoseconds( &total ) /
131    TOD_NANOSECONDS_PER_MICROSECOND;
132  (*print)(
133     context,
134     "------------+----------------------------------------+---------------+---------\n"
135     " TIME SINCE LAST CPU USAGE RESET IN SECONDS:                    %7" PRIu32 ".%06" PRIu32 "\n"
136     "-------------------------------------------------------------------------------\n",
137     seconds, nanoseconds
138  );
139}
140
141void rtems_cpu_usage_report( void )
142{
143  rtems_cpu_usage_report_with_plugin( NULL, printk_plugin );
144}
Note: See TracBrowser for help on using the repository browser.