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

4.104.114.84.95
Last change on this file since b2b143f4 was b2b143f4, checked in by Joel Sherrill <joel.sherrill@…>, on 03/05/04 at 17:58:51

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/rtems_rpc.c, librpc/src/rpc/svc.c, sapi/include/confdefs.h, score/macros/rtems/score/chain.inl, score/src/objectidtoname.c:
  • 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) || \
105  ( (CPU_HARDWARE_FP == TRUE) && !defined(__mips_single_float) )
106        printf( "0x%08x   %4s    %8d     %5.3f\n",
107          the_thread->Object.id,
108          name,
109          the_thread->ticks_executed,
110          (total_units) ?
111            (double)the_thread->ticks_executed / (double)total_units :
112            (double)total_units
113        );
114#else
115        printf( "0x%08x   %4s   %8d\n",
116          the_thread->Object.id,
117          name,
118          the_thread->ticks_executed
119        );
120#endif
121      }
122    }
123  }
124
125  printf(
126    "\nTicks since last reset = %d\n",
127    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
128  );
129  printf( "\nTotal Units = %d\n", total_units );
130}
131
132/*PAGE
133 *
134 *  CPU_usage_Reset
135 */
136
137static void CPU_usage_Per_thread_handler(
138  Thread_Control *the_thread
139)
140{
141  the_thread->ticks_executed = 0;
142}
143
144void CPU_usage_Reset( void )
145{
146  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
147
148  rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
149}
150
Note: See TracBrowser for help on using the repository browser.