LCOV - code coverage report
Current view: top level - src - lfr_cpu_usage_report.c (source / functions) Hit Total Coverage
Test: trace.info Lines: 18 18 100.0 %
Date: 2023-02-20 11:47:14 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.14