1 | /* |
---|
2 | * CPU Usage Reporter |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2007 |
---|
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.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #ifdef HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems.h> |
---|
19 | |
---|
20 | #include <assert.h> |
---|
21 | #include <string.h> |
---|
22 | #include <stdlib.h> |
---|
23 | #include <ctype.h> |
---|
24 | #include <inttypes.h> |
---|
25 | |
---|
26 | #include <rtems/cpuuse.h> |
---|
27 | #include <rtems/bspIo.h> |
---|
28 | |
---|
29 | uint32_t CPU_usage_Ticks_at_last_reset; |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * rtems_cpu_usage_report |
---|
34 | */ |
---|
35 | |
---|
36 | void rtems_cpu_usage_report( void ) |
---|
37 | { |
---|
38 | uint32_t i; |
---|
39 | uint32_t api_index; |
---|
40 | Thread_Control *the_thread; |
---|
41 | Objects_Information *information; |
---|
42 | char name[5]; |
---|
43 | uint32_t ival, fval; |
---|
44 | uint32_t 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 | printk( "CPU Usage by thread\n" |
---|
63 | " ID NAME TICKS PERCENT\n" |
---|
64 | ); |
---|
65 | |
---|
66 | for ( api_index = 1 ; |
---|
67 | api_index <= OBJECTS_APIS_LAST ; |
---|
68 | api_index++ ) { |
---|
69 | if ( !_Objects_Information_table[ api_index ] ) |
---|
70 | continue; |
---|
71 | information = _Objects_Information_table[ api_index ][ 1 ]; |
---|
72 | if ( information ) { |
---|
73 | for ( i=1 ; i <= information->maximum ; i++ ) { |
---|
74 | the_thread = (Thread_Control *)information->local_table[ i ]; |
---|
75 | |
---|
76 | if ( !the_thread ) |
---|
77 | continue; |
---|
78 | |
---|
79 | rtems_object_get_name( the_thread->Object.id, sizeof(name), name ); |
---|
80 | |
---|
81 | ival = total_units ? |
---|
82 | the_thread->ticks_executed * 10000 / total_units : 0; |
---|
83 | fval = ival % 100; |
---|
84 | ival /= 100; |
---|
85 | printk( |
---|
86 | "0x%08" PRIx32 " %4s %8" PRId32 " %3" PRId32 |
---|
87 | ".%02" PRId32"\n", |
---|
88 | the_thread->Object.id, |
---|
89 | name, |
---|
90 | the_thread->ticks_executed, |
---|
91 | ival, |
---|
92 | fval |
---|
93 | ); |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | printk( |
---|
99 | "\nTicks since last reset = %" PRId32 "\n", |
---|
100 | _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset |
---|
101 | ); |
---|
102 | printk( "\nTotal Units = %" PRId32 "\n", total_units ); |
---|
103 | } |
---|
104 | |
---|
105 | static void CPU_usage_Per_thread_handler( |
---|
106 | Thread_Control *the_thread |
---|
107 | ) |
---|
108 | { |
---|
109 | the_thread->ticks_executed = 0; |
---|
110 | } |
---|
111 | |
---|
112 | /* |
---|
113 | * rtems_cpu_usage_reset |
---|
114 | */ |
---|
115 | void rtems_cpu_usage_reset( void ) |
---|
116 | { |
---|
117 | CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot; |
---|
118 | |
---|
119 | rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler); |
---|
120 | } |
---|