source: rtems/cpukit/libmisc/cpuuse/cpuuse.c @ 5e622a9

4.104.114.84.95
Last change on this file since 5e622a9 was ca5fe67, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:43:44

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

  • cpuuse/cpuuse.c (CPU_usage_Dump) : Corrected so it honors when an object name is raw versus being a string.
  • Property mode set to 100644
File size: 3.8 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#include <ctype.h>
22
23#include <rtems/cpuuse.h>
24
25unsigned32 CPU_usage_Ticks_at_last_reset;
26
27/*PAGE
28 *
29 *  CPU_usage_Dump
30 */
31
32void CPU_usage_Dump( void )
33{
34  unsigned32           i;
35  unsigned32           api_index;
36  Thread_Control      *the_thread;
37  Objects_Information *information;
38  unsigned32           u32_name;
39  char                 name[5];
40  unsigned32           total_units = 0;
41
42  for ( api_index = 1 ;
43        api_index <= OBJECTS_APIS_LAST ;
44        api_index++ ) {
45    if ( !_Objects_Information_table[ api_index ] )
46      continue;
47    information = _Objects_Information_table[ api_index ][ 1 ];
48    if ( information ) {
49      for ( i=1 ; i <= information->maximum ; i++ ) {
50        the_thread = (Thread_Control *)information->local_table[ i ];
51 
52        if ( the_thread )
53          total_units += the_thread->ticks_executed;
54      }
55    }
56  }
57
58  printf("CPU Usage by thread\n");
59#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
60  printf( "   ID        NAME        TICKS    PERCENT\n" );
61#else
62  printf( "   ID        NAME        TICKS\n" );
63#endif
64
65  for ( api_index = 1 ;
66        api_index <= OBJECTS_APIS_LAST ;
67        api_index++ ) {
68    if ( !_Objects_Information_table[ api_index ] )
69      continue;
70    information = _Objects_Information_table[ api_index ][ 1 ];
71    if ( information ) {
72      for ( i=1 ; i <= information->maximum ; i++ ) {
73        the_thread = (Thread_Control *)information->local_table[ i ];
74       
75        if ( !the_thread )
76          continue;
77
78        if ( information->is_string )
79          u32_name = *(unsigned32 *)the_thread->Object.name;
80        else
81          u32_name = (unsigned32)the_thread->Object.name;
82
83        name[ 0 ] = (u32_name >> 24) & 0xff;
84        name[ 1 ] = (u32_name >> 16) & 0xff;
85        name[ 2 ] = (u32_name >>  8) & 0xff;
86        name[ 3 ] = (u32_name >>  0) & 0xff;
87        name[ 4 ] = '\0';
88
89        if ( !isprint(name[0]) ) name[0] = '*';
90        if ( !isprint(name[1]) ) name[1] = '*';
91        if ( !isprint(name[2]) ) name[2] = '*';
92        if ( !isprint(name[3]) ) name[3] = '*';
93
94#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
95        printf( "0x%08x   %4s    %8d     %5.3f\n",
96          the_thread->Object.id,
97          name,
98          the_thread->ticks_executed,
99          (total_units) ?
100            (double)the_thread->ticks_executed / (double)total_units :
101            (double)total_units
102        );
103#else
104        printf( "0x%08x   %4s   %8d\n",
105          the_thread->Object.id,
106          name,
107          the_thread->ticks_executed
108        );
109#endif
110      }
111    }
112  }
113
114  printf(
115    "\nTicks since last reset = %d\n",
116    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
117  );
118  printf( "\nTotal Units = %d\n", total_units );
119}
120
121/*PAGE
122 *
123 *  CPU_usage_Reset
124 */
125
126void CPU_usage_Reset( void )
127{
128  unsigned32           i;
129  unsigned32           api_index;
130  Thread_Control      *the_thread;
131  Objects_Information *information;
132 
133  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
134
135  for ( api_index = 1 ;
136        api_index <= OBJECTS_APIS_LAST ;
137        api_index++ ) {
138    if ( !_Objects_Information_table[ api_index ] )
139      continue;
140    information = _Objects_Information_table[ api_index ][ 1 ];
141    if ( information ) {
142      for ( i=1 ; i <= information->maximum ; i++ ) {
143        the_thread = (Thread_Control *)information->local_table[ i ];
144 
145        if ( !the_thread )
146          continue;
147 
148        the_thread->ticks_executed = 0;
149      }
150    }
151  }
152 
153}
154
Note: See TracBrowser for help on using the repository browser.