[fc7bc51] | 1 | /* |
---|
| 2 | * CPU Usage Reporter |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. 1996. |
---|
[fc7bc51] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[98e4ebf5] | 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
[3160ff6] | 9 | * http://www.rtems.com/license/LICENSE. |
---|
[fc7bc51] | 10 | * |
---|
[6f9c75c3] | 11 | * $Id$ |
---|
[fc7bc51] | 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
[550c3df7] | 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[fc7bc51] | 19 | #include <rtems.h> |
---|
| 20 | |
---|
| 21 | #include <assert.h> |
---|
| 22 | #include <stdio.h> |
---|
| 23 | #include <string.h> |
---|
| 24 | #include <stdlib.h> |
---|
[ca5fe67] | 25 | #include <ctype.h> |
---|
[fc7bc51] | 26 | |
---|
[37de72b] | 27 | #include <rtems/cpuuse.h> |
---|
[fc7bc51] | 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; |
---|
[63977bb4] | 39 | unsigned32 api_index; |
---|
[fc7bc51] | 40 | Thread_Control *the_thread; |
---|
| 41 | Objects_Information *information; |
---|
| 42 | unsigned32 u32_name; |
---|
| 43 | char name[5]; |
---|
| 44 | unsigned32 total_units = 0; |
---|
| 45 | |
---|
[63977bb4] | 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 ) { |
---|
[fc7bc51] | 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 | |
---|
[63977bb4] | 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 ) { |
---|
[fc7bc51] | 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 | |
---|
[ca5fe67] | 82 | if ( information->is_string ) |
---|
| 83 | u32_name = *(unsigned32 *)the_thread->Object.name; |
---|
| 84 | else |
---|
| 85 | u32_name = (unsigned32)the_thread->Object.name; |
---|
[fc7bc51] | 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 | |
---|
[ca5fe67] | 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 | |
---|
[fc7bc51] | 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 | |
---|
[236b701] | 130 | static void CPU_usage_Per_thread_handler( |
---|
| 131 | Thread_Control *the_thread |
---|
| 132 | ) |
---|
| 133 | { |
---|
| 134 | the_thread->ticks_executed = 0; |
---|
| 135 | } |
---|
| 136 | |
---|
[fc7bc51] | 137 | void CPU_usage_Reset( void ) |
---|
| 138 | { |
---|
| 139 | CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot; |
---|
| 140 | |
---|
[236b701] | 141 | rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler); |
---|
[fc7bc51] | 142 | } |
---|
| 143 | |
---|