source: rtems/cpukit/libmisc/cpuuse/cpuuse.c @ 3160ff6

4.104.114.84.9
Last change on this file since 3160ff6 was 3160ff6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:54:19 PM

2003-09-04 Joel Sherrill <joel@…>

  • cpuuse/cpuuse.c, cpuuse/cpuuse.h, devnull/devnull.c, devnull/devnull.h, dummy/dummy.c, dumpbuf/dumpbuf.c, dumpbuf/dumpbuf.h, fsmount/fsmount.c, fsmount/fsmount.h, serdbg/serdbgio.c, serdbg/termios_printk.c, stackchk/check.c, stackchk/internal.h, stackchk/stackchk.h, untar/untar.c, untar/untar.h: URL for license changed.
  • Property mode set to 100644
File size: 3.4 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                 name[5];
44  unsigned32           total_units = 0;
45
46  for ( api_index = 1 ;
47        api_index <= OBJECTS_APIS_LAST ;
48        api_index++ ) {
49    if ( !_Objects_Information_table[ api_index ] )
50      continue;
51    information = _Objects_Information_table[ api_index ][ 1 ];
52    if ( information ) {
53      for ( i=1 ; i <= information->maximum ; i++ ) {
54        the_thread = (Thread_Control *)information->local_table[ i ];
55 
56        if ( the_thread )
57          total_units += the_thread->ticks_executed;
58      }
59    }
60  }
61
62  printf("CPU Usage by thread\n");
63#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
64  printf( "   ID        NAME        TICKS    PERCENT\n" );
65#else
66  printf( "   ID        NAME        TICKS\n" );
67#endif
68
69  for ( api_index = 1 ; 
70        api_index <= OBJECTS_APIS_LAST ; 
71        api_index++ ) {
72    if ( !_Objects_Information_table[ api_index ] )
73      continue;
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        if ( information->is_string )
83          u32_name = *(unsigned32 *)the_thread->Object.name;
84        else
85          u32_name = (unsigned32)the_thread->Object.name;
86
87        name[ 0 ] = (u32_name >> 24) & 0xff;
88        name[ 1 ] = (u32_name >> 16) & 0xff;
89        name[ 2 ] = (u32_name >>  8) & 0xff;
90        name[ 3 ] = (u32_name >>  0) & 0xff;
91        name[ 4 ] = '\0';
92
93        if ( !isprint(name[0]) ) name[0] = '*';
94        if ( !isprint(name[1]) ) name[1] = '*';
95        if ( !isprint(name[2]) ) name[2] = '*';
96        if ( !isprint(name[3]) ) name[3] = '*';
97
98#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
99        printf( "0x%08x   %4s    %8d     %5.3f\n",
100          the_thread->Object.id,
101          name,
102          the_thread->ticks_executed,
103          (total_units) ? 
104            (double)the_thread->ticks_executed / (double)total_units :
105            (double)total_units
106        );
107#else
108        printf( "0x%08x   %4s   %8d\n",
109          the_thread->Object.id,
110          name,
111          the_thread->ticks_executed
112        );
113#endif
114      }
115    }
116  }
117
118  printf(
119    "\nTicks since last reset = %d\n",
120    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
121  );
122  printf( "\nTotal Units = %d\n", total_units );
123}
124
125/*PAGE
126 *
127 *  CPU_usage_Reset
128 */
129
130static void CPU_usage_Per_thread_handler(
131  Thread_Control *the_thread
132)
133{
134  the_thread->ticks_executed = 0;
135}
136
137void CPU_usage_Reset( void )
138{
139  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
140
141  rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
142}
143
Note: See TracBrowser for help on using the repository browser.