source: rtems/cpukit/libmisc/cpuuse/cpuuse.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was 714f06c, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 17, 2004 at 8:12:02 AM

2004-04-17 Ralf Corsepius <ralf_corsepius@…>

  • libmisc/capture/capture-cli.c, libmisc/cpuuse/cpuuse.c, libmisc/dumpbuf/dumpbuf.c, libmisc/fsmount/fsmount.c, libmisc/monitor/mon-command.c, libmisc/monitor/mon-config.c, libmisc/monitor/mon-dname.c, libmisc/monitor/mon-driver.c, libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c, libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-queue.c, libmisc/monitor/mon-symbols.c, libmisc/monitor/mon-task.c, libmisc/rtmonuse/rtmonuse.c, libmisc/shell/cmds.c, libmisc/shell/shell.c, libmisc/shell/shell.h, libmisc/stackchk/check.c, libmisc/untar/untar.c: Use fprintf(stdout,...) instead of printf.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  CPU Usage Reporter
3 *
4 *  COPYRIGHT (c) 1989-1999. 1996.
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
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems.h>
20
21#include <assert.h>
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25#include <ctype.h>
26
27#include <rtems/cpuuse.h>
28
29uint32_t   CPU_usage_Ticks_at_last_reset;
30
31/*PAGE
32 *
33 *  CPU_usage_Dump
34 */
35
36void CPU_usage_Dump( void )
37{
38  uint32_t             i;
39  uint32_t             api_index;
40  Thread_Control      *the_thread;
41  Objects_Information *information;
42  uint32_t             u32_name;
43  char                *cname;
44  char                 name[5];
45  uint32_t             total_units = 0;
46
47  for ( api_index = 1 ;
48        api_index <= OBJECTS_APIS_LAST ;
49        api_index++ ) {
50    if ( !_Objects_Information_table[ api_index ] )
51      continue;
52    information = _Objects_Information_table[ api_index ][ 1 ];
53    if ( information ) {
54      for ( i=1 ; i <= information->maximum ; i++ ) {
55        the_thread = (Thread_Control *)information->local_table[ i ];
56
57        if ( the_thread )
58          total_units += the_thread->ticks_executed;
59      }
60    }
61  }
62
63  fprintf(stdout,"CPU Usage by thread\n");
64#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
65  fprintf(stdout, "   ID        NAME        TICKS    PERCENT\n" );
66#else
67  fprintf(stdout, "   ID        NAME        TICKS\n" );
68#endif
69
70  for ( api_index = 1 ;
71        api_index <= OBJECTS_APIS_LAST ;
72        api_index++ ) {
73    if ( !_Objects_Information_table[ api_index ] )
74      continue;
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        if ( information->is_string ) {
84          cname = the_thread->Object.name;
85          name[ 0 ] = cname[0];
86          name[ 1 ] = cname[1];
87          name[ 2 ] = cname[2];
88          name[ 3 ] = cname[3];
89          name[ 4 ] = '\0';
90        } else {
91          u32_name = (uint32_t  )the_thread->Object.name;
92          name[ 0 ] = (u32_name >> 24) & 0xff;
93          name[ 1 ] = (u32_name >> 16) & 0xff;
94          name[ 2 ] = (u32_name >>  8) & 0xff;
95          name[ 3 ] = (u32_name >>  0) & 0xff;
96          name[ 4 ] = '\0';
97        }
98
99        if ( !isprint(name[0]) ) name[0] = '*';
100        if ( !isprint(name[1]) ) name[1] = '*';
101        if ( !isprint(name[2]) ) name[2] = '*';
102        if ( !isprint(name[3]) ) name[3] = '*';
103
104#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
105        fprintf(stdout, "0x%08x   %4s    %8d     %5.3f\n",
106          the_thread->Object.id,
107          name,
108          the_thread->ticks_executed,
109          (total_units) ?
110            (double)the_thread->ticks_executed / (double)total_units :
111            (double)total_units
112        );
113#else
114        fprintf(stdout, "0x%08x   %4s   %8d\n",
115          the_thread->Object.id,
116          name,
117          the_thread->ticks_executed
118        );
119#endif
120      }
121    }
122  }
123
124  fprintf(stdout,
125    "\nTicks since last reset = %d\n",
126    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
127  );
128  fprintf(stdout, "\nTotal Units = %d\n", total_units );
129}
130
131/*PAGE
132 *
133 *  CPU_usage_Reset
134 */
135
136static void CPU_usage_Per_thread_handler(
137  Thread_Control *the_thread
138)
139{
140  the_thread->ticks_executed = 0;
141}
142
143void CPU_usage_Reset( void )
144{
145  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
146
147  rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
148}
Note: See TracBrowser for help on using the repository browser.