1 | /* |
---|
2 | * CPU Usage Reporter |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1997. 1996. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may in |
---|
9 | * the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * check.c,v 1.13 1996/04/22 16:51:52 joel Exp |
---|
13 | * |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems.h> |
---|
17 | |
---|
18 | extern rtems_configuration_table BSP_Configuration; |
---|
19 | |
---|
20 | #include <assert.h> |
---|
21 | #include <stdio.h> |
---|
22 | #include <string.h> |
---|
23 | #include <stdlib.h> |
---|
24 | |
---|
25 | #include "cpuuse.h" |
---|
26 | |
---|
27 | unsigned32 CPU_usage_Ticks_at_last_reset; |
---|
28 | |
---|
29 | /*PAGE |
---|
30 | * |
---|
31 | * CPU_usage_Dump |
---|
32 | */ |
---|
33 | |
---|
34 | void CPU_usage_Dump( void ) |
---|
35 | { |
---|
36 | unsigned32 i; |
---|
37 | unsigned32 class_index; |
---|
38 | Thread_Control *the_thread; |
---|
39 | Objects_Information *information; |
---|
40 | unsigned32 u32_name; |
---|
41 | char name[5]; |
---|
42 | unsigned32 total_units = 0; |
---|
43 | |
---|
44 | for ( class_index = OBJECTS_CLASSES_FIRST ; |
---|
45 | class_index <= OBJECTS_CLASSES_LAST ; |
---|
46 | class_index++ ) { |
---|
47 | information = _Objects_Information_table[ class_index ]; |
---|
48 | if ( information && information->is_thread ) { |
---|
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 ( class_index = OBJECTS_CLASSES_FIRST ; |
---|
66 | class_index <= OBJECTS_CLASSES_LAST ; |
---|
67 | class_index++ ) { |
---|
68 | information = _Objects_Information_table[ class_index ]; |
---|
69 | if ( information && information->is_thread ) { |
---|
70 | for ( i=1 ; i <= information->maximum ; i++ ) { |
---|
71 | the_thread = (Thread_Control *)information->local_table[ i ]; |
---|
72 | |
---|
73 | if ( !the_thread ) |
---|
74 | continue; |
---|
75 | |
---|
76 | u32_name = *(unsigned32 *)the_thread->Object.name; |
---|
77 | |
---|
78 | name[ 0 ] = (u32_name >> 24) & 0xff; |
---|
79 | name[ 1 ] = (u32_name >> 16) & 0xff; |
---|
80 | name[ 2 ] = (u32_name >> 8) & 0xff; |
---|
81 | name[ 3 ] = (u32_name >> 0) & 0xff; |
---|
82 | name[ 4 ] = '\0'; |
---|
83 | |
---|
84 | #if defined(unix) || ( CPU_HARDWARE_FP == TRUE ) |
---|
85 | printf( "0x%08x %4s %8d %5.3f\n", |
---|
86 | the_thread->Object.id, |
---|
87 | name, |
---|
88 | the_thread->ticks_executed, |
---|
89 | (total_units) ? |
---|
90 | (double)the_thread->ticks_executed / (double)total_units : |
---|
91 | (double)total_units |
---|
92 | ); |
---|
93 | #else |
---|
94 | printf( "0x%08x %4s %8d\n", |
---|
95 | the_thread->Object.id, |
---|
96 | name, |
---|
97 | the_thread->ticks_executed |
---|
98 | ); |
---|
99 | #endif |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | printf( |
---|
105 | "\nTicks since last reset = %d\n", |
---|
106 | _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset |
---|
107 | ); |
---|
108 | printf( "\nTotal Units = %d\n", total_units ); |
---|
109 | } |
---|
110 | |
---|
111 | /*PAGE |
---|
112 | * |
---|
113 | * CPU_usage_Reset |
---|
114 | */ |
---|
115 | |
---|
116 | void CPU_usage_Reset( void ) |
---|
117 | { |
---|
118 | unsigned32 i; |
---|
119 | unsigned32 class_index; |
---|
120 | Thread_Control *the_thread; |
---|
121 | Objects_Information *information; |
---|
122 | |
---|
123 | CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot; |
---|
124 | |
---|
125 | for ( class_index = OBJECTS_CLASSES_FIRST ; |
---|
126 | class_index <= OBJECTS_CLASSES_LAST ; |
---|
127 | class_index++ ) { |
---|
128 | information = _Objects_Information_table[ class_index ]; |
---|
129 | if ( information && information->is_thread ) { |
---|
130 | for ( i=1 ; i <= information->maximum ; i++ ) { |
---|
131 | the_thread = (Thread_Control *)information->local_table[ i ]; |
---|
132 | |
---|
133 | if ( !the_thread ) |
---|
134 | continue; |
---|
135 | |
---|
136 | the_thread->ticks_executed = 0; |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|
142 | |
---|