GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/lfr_cpu_usage_report.c Lines: 17 17 100.0 %
Date: 2018-11-13 11:16:07 Branches: 11 12 91.7 %

Line Branch Exec Source
1
/*
2
 *  CPU Usage Reporter
3
 *
4
 *  COPYRIGHT (c) 1989-2009
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
#include "lfr_cpu_usage_report.h"
15
#include "fsw_params.h"
16
17
extern rtems_id    Task_id[];
18
19
129632
unsigned char lfr_rtems_cpu_usage_report( void )
20
{
21
    uint32_t             api_index;
22
    uint32_t             information_index;
23
    Thread_Control      *the_thread;
24
    Objects_Information *information;
25
    uint32_t             ival;
26
    uint32_t             fval;
27
#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
28
    Timestamp_Control  uptime;
29
    Timestamp_Control  total;
30
    Timestamp_Control  ran;
31
32
#else
33
    #error "Can't compute CPU usage using ticks on LFR"
34
#endif
35
36
    unsigned char cpu_load;
37
38
129632
    ival = 0;
39
129632
    cpu_load = 0;
40
41
648160
    for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
42
    {
43
518528
        if ( !_Objects_Information_table[ api_index ] ) { }
44
        else
45
        {
46
388896
            information = _Objects_Information_table[ api_index ][ 1 ];
47
388896
            if ( information != NULL )
48
            {
49
3500064
                for(information_index=1;information_index<=information->maximum;information_index++)
50
                {
51
3111168
                    the_thread = (Thread_Control *)information->local_table[ information_index ];
52
53
3111168
                    if ( the_thread == NULL) { }
54
2981536
                    else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing
55
                    {
56
129632
                        _TOD_Get_uptime( &uptime );
57
129632
                        _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
58
129632
                        ran = the_thread->cpu_time_used;
59
129632
                        _Timestamp_Divide( &ran, &total, &ival, &fval);
60
129632
                        cpu_load = (unsigned char) (CONST_255 - ((((ival*CONST_10) + (fval/CONST_100))*CONST_256)/CONST_1000));
61
                    }
62
                }
63
            }
64
        }
65
    }
66
129632
    return cpu_load;
67
}
68
69