source: rtems/cpukit/libmisc/cpuuse/cpuusagereport.c @ 24d0ee57

5
Last change on this file since 24d0ee57 was 24d0ee57, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 08:39:50

cpukit, testsuite: Add rtems_printf and rtems_printer support.

This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.

Printk and related functions are made to return a valid number of
characters formatted and output.

The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.

The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.

  • 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/*
34 *  rtems_cpu_usage_report
35 */
36void rtems_cpu_usage_report_with_plugin(
37  const rtems_printer *printer
38)
39{
40  uint32_t             i;
41  uint32_t             api_index;
42  Thread_Control      *the_thread;
43  Objects_Information *information;
44  char                 name[13];
45  uint32_t             ival, fval;
46  Timestamp_Control    uptime, total, used, uptime_at_last_reset;
47  uint32_t             seconds, nanoseconds;
48
49  /*
50   *  When not using nanosecond CPU usage resolution, we have to count
51   *  the number of "ticks" we gave credit for to give the user a rough
52   *  guideline as to what each number means proportionally.
53   */
54  _Timestamp_Set_to_zero( &total );
55  uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
56
57  rtems_printf(
58     printer,
59     "-------------------------------------------------------------------------------\n"
60     "                              CPU USAGE BY THREAD\n"
61     "------------+----------------------------------------+---------------+---------\n"
62     " ID         | NAME                                   | SECONDS       | PERCENT\n"
63     "------------+----------------------------------------+---------------+---------\n"
64  );
65
66  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
67    #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
68      if ( !_Objects_Information_table[ api_index ] )
69        continue;
70    #endif
71
72    information = _Objects_Information_table[ api_index ][ 1 ];
73    if ( information ) {
74      for ( i=1 ; i <= information->maximum ; i++ ) {
75        the_thread = (Thread_Control *)information->local_table[ i ];
76
77        if ( !the_thread )
78          continue;
79
80        rtems_object_get_name( the_thread->Object.id, sizeof(name), name );
81
82        rtems_printf(
83          printer,
84          " 0x%08" PRIx32 " | %-38s |",
85          the_thread->Object.id,
86          name
87        );
88
89        _Thread_Get_CPU_time_used( the_thread, &used );
90        _TOD_Get_uptime( &uptime );
91        _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
92        _Timestamp_Divide( &used, &total, &ival, &fval );
93
94        /*
95         * Print the information
96         */
97
98        seconds = _Timestamp_Get_seconds( &used );
99        nanoseconds = _Timestamp_Get_nanoseconds( &used ) /
100          TOD_NANOSECONDS_PER_MICROSECOND;
101        rtems_printf( printer,
102          "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
103          seconds, nanoseconds,
104          ival, fval
105        );
106      }
107    }
108  }
109
110  seconds = _Timestamp_Get_seconds( &total );
111  nanoseconds = _Timestamp_Get_nanoseconds( &total ) /
112    TOD_NANOSECONDS_PER_MICROSECOND;
113  rtems_printf(
114     printer,
115     "------------+----------------------------------------+---------------+---------\n"
116     " TIME SINCE LAST CPU USAGE RESET IN SECONDS:                    %7" PRIu32 ".%06" PRIu32 "\n"
117     "-------------------------------------------------------------------------------\n",
118     seconds, nanoseconds
119  );
120}
121
122void rtems_cpu_usage_report( void )
123{
124  rtems_printer printer;
125  rtems_print_printer_printk( &printer );
126  rtems_cpu_usage_report_with_plugin( &printer );
127}
Note: See TracBrowser for help on using the repository browser.