lfr_cpu_usage_report.c
69 lines
| 2.1 KiB
| text/x-c
|
CLexer
/ src / lfr_cpu_usage_report.c
paul
|
r135 | /* | ||
* CPU Usage Reporter | ||||
* | ||||
* COPYRIGHT (c) 1989-2009 | ||||
* On-Line Applications Research Corporation (OAR). | ||||
* | ||||
* The license and distribution terms for this file may be | ||||
* found in the file LICENSE in this distribution or at | ||||
* http://www.rtems.com/license/LICENSE. | ||||
* | ||||
* $Id$ | ||||
*/ | ||||
#include "lfr_cpu_usage_report.h" | ||||
r378 | #include "fsw_params.h" | |||
extern rtems_id Task_id[]; | ||||
paul
|
r135 | |||
unsigned char lfr_rtems_cpu_usage_report( void ) | ||||
{ | ||||
uint32_t api_index; | ||||
r378 | uint32_t information_index; | |||
paul
|
r135 | Thread_Control *the_thread; | ||
Objects_Information *information; | ||||
paul
|
r318 | uint32_t ival; | ||
uint32_t fval; | ||||
paul
|
r135 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ | ||
paul
|
r166 | Timestamp_Control uptime; | ||
Timestamp_Control total; | ||||
Timestamp_Control ran; | ||||
r378 | ||||
paul
|
r135 | #else | ||
r378 | #error "Can't compute CPU usage using ticks on LFR" | |||
paul
|
r135 | #endif | ||
unsigned char cpu_load; | ||||
paul
|
r320 | |||
ival = 0; | ||||
paul
|
r135 | cpu_load = 0; | ||
for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) | ||||
{ | ||||
paul
|
r166 | if ( !_Objects_Information_table[ api_index ] ) { } | ||
else | ||||
paul
|
r135 | { | ||
paul
|
r166 | information = _Objects_Information_table[ api_index ][ 1 ]; | ||
if ( information != NULL ) | ||||
paul
|
r135 | { | ||
r378 | for(information_index=1;information_index<=information->maximum;information_index++) | |||
paul
|
r166 | { | ||
r378 | the_thread = (Thread_Control *)information->local_table[ information_index ]; | |||
if ( the_thread == NULL) { } | ||||
else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing | ||||
paul
|
r166 | { | ||
r381 | _TOD_Get_uptime( &uptime ); | |||
_Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); | ||||
ran = the_thread->cpu_time_used; | ||||
r378 | _Timestamp_Divide( &ran, &total, &ival, &fval); | |||
r399 | cpu_load = (unsigned char) (CONST_255 - ((((ival*CONST_10) + (fval/CONST_100))*CONST_256)/CONST_1000)); | |||
paul
|
r166 | } | ||
} | ||||
paul
|
r135 | } | ||
} | ||||
} | ||||
return cpu_load; | ||||
} | ||||