source: rtems/cpukit/libmisc/cpuuse/cpuusagereport.c @ 5e072f6d

5
Last change on this file since 5e072f6d was 5e072f6d, checked in by Sebastian Huber <sebastian.huber@…>, on 05/31/16 at 07:52:36

cpuuse: Hide implementation details

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief CPU Usage Report
5 * @ingroup libmisc_cpuuse CPU Usage
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <string.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <ctype.h>
25#include <inttypes.h>
26
27#include <rtems/cpuuse.h>
28#include <rtems/score/objectimpl.h>
29#include <rtems/score/threadimpl.h>
30#include <rtems/score/todimpl.h>
31#include <rtems/score/watchdogimpl.h>
32
33#include "cpuuseimpl.h"
34
35/*
36 *  rtems_cpu_usage_report
37 */
38void rtems_cpu_usage_report_with_plugin(
39  const rtems_printer *printer
40)
41{
42  uint32_t             i;
43  uint32_t             api_index;
44  Thread_Control      *the_thread;
45  Objects_Information *information;
46  char                 name[13];
47  uint32_t             ival, fval;
48  Timestamp_Control    uptime, total, used, uptime_at_last_reset;
49  uint32_t             seconds, nanoseconds;
50
51  /*
52   *  When not using nanosecond CPU usage resolution, we have to count
53   *  the number of "ticks" we gave credit for to give the user a rough
54   *  guideline as to what each number means proportionally.
55   */
56  _Timestamp_Set_to_zero( &total );
57  uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
58
59  rtems_printf(
60     printer,
61     "-------------------------------------------------------------------------------\n"
62     "                              CPU USAGE BY THREAD\n"
63     "------------+----------------------------------------+---------------+---------\n"
64     " ID         | NAME                                   | SECONDS       | PERCENT\n"
65     "------------+----------------------------------------+---------------+---------\n"
66  );
67
68  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
69    #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
70      if ( !_Objects_Information_table[ api_index ] )
71        continue;
72    #endif
73
74    information = _Objects_Information_table[ api_index ][ 1 ];
75    if ( information ) {
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
82        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
83
84        rtems_printf(
85          printer,
86          " 0x%08" PRIx32 " | %-38s |",
87          the_thread->Object.id,
88          name
89        );
90
91        _Thread_Get_CPU_time_used( the_thread, &used );
92        _TOD_Get_uptime( &uptime );
93        _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
94        _Timestamp_Divide( &used, &total, &ival, &fval );
95
96        /*
97         * Print the information
98         */
99
100        seconds = _Timestamp_Get_seconds( &used );
101        nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
102          TOD_NANOSECONDS_PER_MICROSECOND;
103        rtems_printf( printer,
104          "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
105          seconds, nanoseconds,
106          ival, fval
107        );
108      }
109    }
110  }
111
112  seconds = _Timestamp_Get_seconds( &total );
113  nanoseconds = _Timestamp_Get_nanoseconds( &total ) /
114    TOD_NANOSECONDS_PER_MICROSECOND;
115  rtems_printf(
116     printer,
117     "------------+----------------------------------------+---------------+---------\n"
118     " TIME SINCE LAST CPU USAGE RESET IN SECONDS:                    %7" PRIu32 ".%06" PRIu32 "\n"
119     "-------------------------------------------------------------------------------\n",
120     seconds, nanoseconds
121  );
122}
123
124void rtems_cpu_usage_report( void )
125{
126  rtems_printer printer;
127  rtems_print_printer_printk( &printer );
128  rtems_cpu_usage_report_with_plugin( &printer );
129}
Note: See TracBrowser for help on using the repository browser.