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

4.115
Last change on this file since e6b31b27 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
RevLine 
[f5f2676]1/**
2 * @file
[fc7bc51]3 *
[f5f2676]4 * @brief CPU Usage Report
5 * @ingroup libmisc_cpuuse CPU Usage
6 */
7
8/*
[77c330ce]9 *  COPYRIGHT (c) 1989-2010.
[fc7bc51]10 *  On-Line Applications Research Corporation (OAR).
11 *
[98e4ebf5]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.
[fc7bc51]15 */
16
[550c3df7]17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[fc7bc51]21#include <string.h>
22#include <stdlib.h>
[3462c34]23#include <stdio.h>
[ca5fe67]24#include <ctype.h>
[3523321]25#include <inttypes.h>
[fc7bc51]26
[37de72b]27#include <rtems/cpuuse.h>
[a2e3f33]28#include <rtems/score/objectimpl.h>
[a5ac9da]29#include <rtems/score/threadimpl.h>
[f031df0e]30#include <rtems/score/todimpl.h>
[4b48ece0]31#include <rtems/score/watchdogimpl.h>
[fc7bc51]32
[c1a84bf8]33/*
[bc11ec2]34 *  rtems_cpu_usage_report
[fc7bc51]35 */
[90a5d194]36void rtems_cpu_usage_report_with_plugin(
37  void                  *context,
38  rtems_printk_plugin_t  print
39)
[fc7bc51]40{
[3e08d4e]41  uint32_t             i;
42  uint32_t             api_index;
[fc7bc51]43  Thread_Control      *the_thread;
44  Objects_Information *information;
[6728035]45  char                 name[13];
[1a561f8]46  uint32_t             ival, fval;
[e6b31b27]47  Timestamp_Control  uptime, total, ran, uptime_at_last_reset;
48  uint32_t seconds, nanoseconds;
[c3330a8]49
[90a5d194]50  if ( !print )
51    return;
52
[c3330a8]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   */
[e6b31b27]58  _Timestamp_Set_to_zero( &total );
59  uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
[0893220]60
[e41eaa88]61  (*print)(
62     context,
63     "-------------------------------------------------------------------------------\n"
64     "                              CPU USAGE BY THREAD\n"
65     "------------+----------------------------------------+---------------+---------\n"
[e6b31b27]66     " ID         | NAME                                   | SECONDS       | PERCENT\n"
[e41eaa88]67     "------------+----------------------------------------+---------------+---------\n"
[c3330a8]68  );
[fc7bc51]69
[77c330ce]70  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
[8720a3a]71    #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
72      if ( !_Objects_Information_table[ api_index ] )
73        continue;
74    #endif
[77c330ce]75
[63977bb4]76    information = _Objects_Information_table[ api_index ][ 1 ];
77    if ( information ) {
[fc7bc51]78      for ( i=1 ; i <= information->maximum ; i++ ) {
79        the_thread = (Thread_Control *)information->local_table[ i ];
[aed742c]80
[fc7bc51]81        if ( !the_thread )
82          continue;
83
[eb64f2c6]84        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
[0893220]85
[6728035]86        (*print)(
87          context,
[e41eaa88]88          " 0x%08" PRIx32 " | %-38s |",
[6728035]89          the_thread->Object.id,
90          name
91        );
[c3330a8]92
[c1a84bf8]93        {
94          Timestamp_Control last;
95
[3462c34]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;
[7c797a1]101          if ( _Thread_Get_time_of_last_context_switch( the_thread, &last ) ) {
[c16bcc0]102            Timestamp_Control used;
[db498aba]103            _TOD_Get_uptime( &uptime );
104            _Timestamp_Subtract( &last, &uptime, &used );
[c16bcc0]105            _Timestamp_Add_to( &ran, &used );
[db498aba]106          } else {
107            _TOD_Get_uptime( &uptime );
108          }
109          _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
[c16bcc0]110          _Timestamp_Divide( &ran, &total, &ival, &fval );
[3462c34]111
112          /*
113           * Print the information
114           */
[90a5d194]115
[baef6771]116          seconds = _Timestamp_Get_seconds( &ran );
117          nanoseconds = _Timestamp_Get_nanoseconds( &ran ) /
118            TOD_NANOSECONDS_PER_MICROSECOND;
[90a5d194]119          (*print)( context,
[e41eaa88]120            "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
[baef6771]121            seconds, nanoseconds,
[3462c34]122            ival, fval
[c3330a8]123          );
[c1a84bf8]124        }
[fc7bc51]125      }
126    }
127  }
128
[e6b31b27]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  );
[fc7bc51]139}
[90a5d194]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.