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