source: rtems/c/src/libmisc/cpuuse/cpuuse.c @ 63977bb4

4.104.114.84.95
Last change on this file since 63977bb4 was 63977bb4, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:19:33

2002-07-01 Joel Sherrill <joel@…>

  • capture/capture-cli.c, cpuuse/cpuuse.c, monitor/mon-monitor.c, monitor/mon-object.c, monitor/monitor.h: Corrected use of _Objects_Information_table now that it is a two dimensional array based upon API and class. In addition, in the monitor, corrected an error which occured when a target has 64 bit pointers.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  CPU Usage Reporter
3 *
4 *  COPYRIGHT (c) 1989-1999. 1996.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 *
13 */
14
15#include <rtems.h>
16
17#include <assert.h>
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21
22#include <rtems/cpuuse.h>
23
24unsigned32 CPU_usage_Ticks_at_last_reset;
25
26/*PAGE
27 *
28 *  CPU_usage_Dump
29 */
30
31void CPU_usage_Dump( void )
32{
33  unsigned32           i;
34  unsigned32           api_index;
35  Thread_Control      *the_thread;
36  Objects_Information *information;
37  unsigned32           u32_name;
38  char                 name[5];
39  unsigned32           total_units = 0;
40
41  for ( api_index = 1 ;
42        api_index <= OBJECTS_APIS_LAST ;
43        api_index++ ) {
44    if ( !_Objects_Information_table[ api_index ] )
45      continue;
46    information = _Objects_Information_table[ api_index ][ 1 ];
47    if ( information ) {
48      for ( i=1 ; i <= information->maximum ; i++ ) {
49        the_thread = (Thread_Control *)information->local_table[ i ];
50 
51        if ( the_thread )
52          total_units += the_thread->ticks_executed;
53      }
54    }
55  }
56
57  printf("CPU Usage by thread\n");
58#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
59  printf( "   ID        NAME        TICKS    PERCENT\n" );
60#else
61  printf( "   ID        NAME        TICKS\n" );
62#endif
63
64  for ( api_index = 1 ;
65        api_index <= OBJECTS_APIS_LAST ;
66        api_index++ ) {
67    if ( !_Objects_Information_table[ api_index ] )
68      continue;
69    information = _Objects_Information_table[ api_index ][ 1 ];
70    if ( information ) {
71      for ( i=1 ; i <= information->maximum ; i++ ) {
72        the_thread = (Thread_Control *)information->local_table[ i ];
73       
74        if ( !the_thread )
75          continue;
76
77        u32_name = *(unsigned32 *)the_thread->Object.name;
78
79        name[ 0 ] = (u32_name >> 24) & 0xff;
80        name[ 1 ] = (u32_name >> 16) & 0xff;
81        name[ 2 ] = (u32_name >>  8) & 0xff;
82        name[ 3 ] = (u32_name >>  0) & 0xff;
83        name[ 4 ] = '\0';
84
85#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
86        printf( "0x%08x   %4s    %8d     %5.3f\n",
87          the_thread->Object.id,
88          name,
89          the_thread->ticks_executed,
90          (total_units) ?
91            (double)the_thread->ticks_executed / (double)total_units :
92            (double)total_units
93        );
94#else
95        printf( "0x%08x   %4s   %8d\n",
96          the_thread->Object.id,
97          name,
98          the_thread->ticks_executed
99        );
100#endif
101      }
102    }
103  }
104
105  printf(
106    "\nTicks since last reset = %d\n",
107    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
108  );
109  printf( "\nTotal Units = %d\n", total_units );
110}
111
112/*PAGE
113 *
114 *  CPU_usage_Reset
115 */
116
117void CPU_usage_Reset( void )
118{
119  unsigned32           i;
120  unsigned32           api_index;
121  Thread_Control      *the_thread;
122  Objects_Information *information;
123 
124  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
125
126  for ( api_index = 1 ;
127        api_index <= OBJECTS_APIS_LAST ;
128        api_index++ ) {
129    if ( !_Objects_Information_table[ api_index ] )
130      continue;
131    information = _Objects_Information_table[ api_index ][ 1 ];
132    if ( information ) {
133      for ( i=1 ; i <= information->maximum ; i++ ) {
134        the_thread = (Thread_Control *)information->local_table[ i ];
135 
136        if ( !the_thread )
137          continue;
138 
139        the_thread->ticks_executed = 0;
140      }
141    }
142  }
143 
144}
145
Note: See TracBrowser for help on using the repository browser.