Changeset 4cf58905 in rtems


Ignore:
Timestamp:
Oct 31, 2016, 1:45:30 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
b7694c8c
Parents:
d271c3bb
git-author:
Sebastian Huber <sebastian.huber@…> (10/31/16 13:45:30)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/02/16 07:46:48)
Message:

cpuuse: Use rtems_task_iterate()

Update #2423.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/cpuuse/cpuusagereport.c

    rd271c3bb r4cf58905  
    2727#include <rtems/cpuuse.h>
    2828#include <rtems/printer.h>
    29 #include <rtems/score/objectimpl.h>
    3029#include <rtems/score/threadimpl.h>
    3130#include <rtems/score/todimpl.h>
    32 #include <rtems/score/watchdogimpl.h>
    3331
    3432#include "cpuuseimpl.h"
     33
     34typedef struct {
     35  const rtems_printer *printer;
     36  Timestamp_Control    total;
     37  Timestamp_Control    uptime_at_last_reset;
     38} cpu_usage_context;
     39
     40static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
     41{
     42  cpu_usage_context *ctx;
     43  char               name[ 13 ];
     44  uint32_t           ival;
     45  uint32_t           fval;
     46  Timestamp_Control  uptime;
     47  Timestamp_Control  used;
     48  uint32_t           seconds;
     49  uint32_t           nanoseconds;
     50
     51  ctx = arg;
     52  rtems_object_get_name( the_thread->Object.id, sizeof( name ), name );
     53
     54  rtems_printf(
     55    ctx->printer,
     56    " 0x%08" PRIx32 " | %-38s |",
     57    the_thread->Object.id,
     58    name
     59  );
     60
     61  _Thread_Get_CPU_time_used( the_thread, &used );
     62  _TOD_Get_uptime( &uptime );
     63  _Timestamp_Subtract( &ctx->uptime_at_last_reset, &uptime, &ctx->total );
     64  _Timestamp_Divide( &used, &ctx->total, &ival, &fval );
     65
     66  /*
     67   * Print the information
     68   */
     69
     70  seconds = _Timestamp_Get_seconds( &used );
     71  nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
     72    TOD_NANOSECONDS_PER_MICROSECOND;
     73  rtems_printf( ctx->printer,
     74    "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
     75    seconds, nanoseconds,
     76    ival, fval
     77  );
     78
     79  return false;
     80}
    3581
    3682/*
     
    4187)
    4288{
    43   uint32_t             i;
    44   uint32_t             api_index;
    45   Thread_Control      *the_thread;
    46   Objects_Information *information;
    47   char                 name[13];
    48   uint32_t             ival, fval;
    49   Timestamp_Control    uptime, total, used, uptime_at_last_reset;
    50   uint32_t             seconds, nanoseconds;
     89  cpu_usage_context  ctx;
     90  uint32_t           seconds;
     91  uint32_t           nanoseconds;
     92
     93  ctx.printer = printer;
    5194
    5295  /*
     
    5598   *  guideline as to what each number means proportionally.
    5699   */
    57   _Timestamp_Set_to_zero( &total );
    58   uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
     100  _Timestamp_Set_to_zero( &ctx.total );
     101  ctx.uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
    59102
    60103  rtems_printf(
     
    67110  );
    68111
    69   for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
    70     #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
    71       if ( !_Objects_Information_table[ api_index ] )
    72         continue;
    73     #endif
     112  rtems_task_iterate( cpu_usage_visitor, &ctx );
    74113
    75     information = _Objects_Information_table[ api_index ][ 1 ];
    76     if ( information ) {
    77       for ( i=1 ; i <= information->maximum ; i++ ) {
    78         the_thread = (Thread_Control *)information->local_table[ i ];
    79 
    80         if ( !the_thread )
    81           continue;
    82 
    83         rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
    84 
    85         rtems_printf(
    86           printer,
    87           " 0x%08" PRIx32 " | %-38s |",
    88           the_thread->Object.id,
    89           name
    90         );
    91 
    92         _Thread_Get_CPU_time_used( the_thread, &used );
    93         _TOD_Get_uptime( &uptime );
    94         _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
    95         _Timestamp_Divide( &used, &total, &ival, &fval );
    96 
    97         /*
    98          * Print the information
    99          */
    100 
    101         seconds = _Timestamp_Get_seconds( &used );
    102         nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
    103           TOD_NANOSECONDS_PER_MICROSECOND;
    104         rtems_printf( printer,
    105           "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
    106           seconds, nanoseconds,
    107           ival, fval
    108         );
    109       }
    110     }
    111   }
    112 
    113   seconds = _Timestamp_Get_seconds( &total );
    114   nanoseconds = _Timestamp_Get_nanoseconds( &total ) /
     114  seconds = _Timestamp_Get_seconds( &ctx.total );
     115  nanoseconds = _Timestamp_Get_nanoseconds( &ctx.total ) /
    115116    TOD_NANOSECONDS_PER_MICROSECOND;
    116117  rtems_printf(
Note: See TracChangeset for help on using the changeset viewer.