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

4.104.114.84.95
Last change on this file since cb2f320 was cb2f320, checked in by Joel Sherrill <joel.sherrill@…>, on 03/05/04 at 18:02:41

2004-03-05 Joel Sherrill <joel@…>

  • libblock/src/bdbuf.c, libblock/src/ramdisk.c, libcsupport/src/newlibc.c, libcsupport/src/sync.c, libmisc/cpuuse/cpuuse.c, libmisc/monitor/mon-symbols.c, libmisc/shell/cmds.c, libmisc/shell/shell.c, libnetworking/kern/kern_sysctl.c, libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c, libnetworking/libc/gethostbydns.c, libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c, libnetworking/libc/getnetbyht.c, libnetworking/libc/getnetnamadr.c, libnetworking/libc/inet_addr.c, libnetworking/libc/linkaddr.c, libnetworking/libc/map_v4v6.c, libnetworking/libc/ns_print.c, libnetworking/libc/ns_ttl.c, libnetworking/libc/nsap_addr.c, libnetworking/libc/rcmd.c, libnetworking/libc/res_debug.c, libnetworking/libc/res_mkupdate.c, libnetworking/libc/res_query.c, libnetworking/libc/res_send.c, libnetworking/libc/res_update.c, libnetworking/net/radix.c, libnetworking/rtems/mkrootfs.c, librpc/src/rpc/clnt_perror.c, librpc/src/rpc/svc.c, score/macros/rtems/score/chain.inl, score/src/objectidtoname.c: Too much was accidentally committed -- revert.
  • 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
29unsigned32 CPU_usage_Ticks_at_last_reset;
30
31/*PAGE
32 *
33 *  CPU_usage_Dump
34 */
35
36void CPU_usage_Dump( void )
37{
38  unsigned32           i;
39  unsigned32           api_index;
40  Thread_Control      *the_thread;
41  Objects_Information *information;
42  unsigned32           u32_name;
43  char                *cname;
44  char                 name[5];
45  unsigned32           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  printf("CPU Usage by thread\n");
64#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
65  printf( "   ID        NAME        TICKS    PERCENT\n" );
66#else
67  printf( "   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 = (unsigned32)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        printf( "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        printf( "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  printf(
125    "\nTicks since last reset = %d\n",
126    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
127  );
128  printf( "\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}
149
Note: See TracBrowser for help on using the repository browser.