source: rtems/cpukit/libmisc/cpuuse/cpuuse.c @ eb64f2c6

4.104.114.84.95
Last change on this file since eb64f2c6 was eb64f2c6, checked in by Joel Sherrill <joel.sherrill@…>, on 05/16/07 at 16:25:05

2007-05-16 Joel Sherrill <joel.sherrill@…>

  • libmisc/cpuuse/cpuuse.c: Use rtems_object_get_name and eliminate functionally similar code here. Also cleanup print formats.
  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[fc7bc51]1/*
2 *  CPU Usage Reporter
3 *
[4da36c1a]4 *  COPYRIGHT (c) 1989-2007
[fc7bc51]5 *  On-Line Applications Research Corporation (OAR).
6 *
[98e4ebf5]7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
[3160ff6]9 *  http://www.rtems.com/license/LICENSE.
[fc7bc51]10 *
[bc11ec2]11 *  $Id$
[fc7bc51]12 */
13
[550c3df7]14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
[fc7bc51]18#include <rtems.h>
19
20#include <assert.h>
21#include <string.h>
22#include <stdlib.h>
[ca5fe67]23#include <ctype.h>
[3523321]24#include <inttypes.h>
[fc7bc51]25
[37de72b]26#include <rtems/cpuuse.h>
[eb64f2c6]27#include <rtems/bspIo.h>
[fc7bc51]28
[3e08d4e]29uint32_t   CPU_usage_Ticks_at_last_reset;
[fc7bc51]30
31/*PAGE
32 *
[bc11ec2]33 *  rtems_cpu_usage_report
[fc7bc51]34 */
35
[bc11ec2]36void rtems_cpu_usage_report( void )
[fc7bc51]37{
[3e08d4e]38  uint32_t             i;
39  uint32_t             api_index;
[fc7bc51]40  Thread_Control      *the_thread;
41  Objects_Information *information;
42  char                 name[5];
[1a561f8]43  uint32_t             ival, fval;
[3e08d4e]44  uint32_t             total_units = 0;
[fc7bc51]45
[63977bb4]46  for ( api_index = 1 ;
47        api_index <= OBJECTS_APIS_LAST ;
48        api_index++ ) {
49    if ( !_Objects_Information_table[ api_index ] )
50      continue;
51    information = _Objects_Information_table[ api_index ][ 1 ];
52    if ( information ) {
[fc7bc51]53      for ( i=1 ; i <= information->maximum ; i++ ) {
54        the_thread = (Thread_Control *)information->local_table[ i ];
[aed742c]55
[fc7bc51]56        if ( the_thread )
57          total_units += the_thread->ticks_executed;
58      }
59    }
60  }
61
[eb64f2c6]62  printk( "CPU Usage by thread\n"
63          "   ID        NAME        TICKS    PERCENT\n"
64   );
[fc7bc51]65
[aed742c]66  for ( api_index = 1 ;
67        api_index <= OBJECTS_APIS_LAST ;
[63977bb4]68        api_index++ ) {
69    if ( !_Objects_Information_table[ api_index ] )
70      continue;
71    information = _Objects_Information_table[ api_index ][ 1 ];
72    if ( information ) {
[fc7bc51]73      for ( i=1 ; i <= information->maximum ; i++ ) {
74        the_thread = (Thread_Control *)information->local_table[ i ];
[aed742c]75
[fc7bc51]76        if ( !the_thread )
77          continue;
78
[eb64f2c6]79        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
[ca5fe67]80
[3523321]81        ival = total_units ?
82                 the_thread->ticks_executed * 10000 / total_units : 0;
83        fval = ival % 100;
84        ival /= 100;
[eb64f2c6]85        printk(
86          "0x%08" PRIx32 "   %4s    %8" PRId32 "     %3" PRId32
87             ".%02" PRId32"\n",
[fc7bc51]88          the_thread->Object.id,
89          name,
90          the_thread->ticks_executed,
[3523321]91          ival,
92          fval
[fc7bc51]93        );
94      }
95    }
96  }
97
[eb64f2c6]98  printk(
[3523321]99    "\nTicks since last reset = %" PRId32 "\n",
[fc7bc51]100    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
101  );
[eb64f2c6]102  printk( "\nTotal Units = %" PRId32 "\n", total_units );
[fc7bc51]103}
104
[236b701]105static void CPU_usage_Per_thread_handler(
106  Thread_Control *the_thread
107)
108{
109  the_thread->ticks_executed = 0;
110}
111
[bc11ec2]112/*
113 *  rtems_cpu_usage_reset
114 */
115void rtems_cpu_usage_reset( void )
[fc7bc51]116{
117  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
118
[236b701]119  rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
[fc7bc51]120}
Note: See TracBrowser for help on using the repository browser.