source: rtems/cpukit/libmisc/cpuuse/cpuuse.c @ 130291f

4.104.114.84.95
Last change on this file since 130291f was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • 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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 *
13 */
14
15#include <rtems.h>
16
17#include <assert.h>
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21
22#include <rtems/cpuuse.h>
23
24unsigned32 CPU_usage_Ticks_at_last_reset;
25
26/*PAGE
27 *
28 *  CPU_usage_Dump
29 */
30
31void CPU_usage_Dump( void )
32{
33  unsigned32           i;
34  unsigned32           class_index;
35  Thread_Control      *the_thread;
36  Objects_Information *information;
37  unsigned32           u32_name;
38  char                 name[5];
39  unsigned32           total_units = 0;
40
41  for ( class_index = OBJECTS_CLASSES_FIRST ;
42        class_index <= OBJECTS_CLASSES_LAST ;
43        class_index++ ) {
44    information = _Objects_Information_table[ class_index ];
45    if ( information && information->is_thread ) {
46      for ( i=1 ; i <= information->maximum ; i++ ) {
47        the_thread = (Thread_Control *)information->local_table[ i ];
48 
49        if ( the_thread )
50          total_units += the_thread->ticks_executed;
51      }
52    }
53  }
54
55  printf("CPU Usage by thread\n");
56#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
57  printf( "   ID        NAME        TICKS    PERCENT\n" );
58#else
59  printf( "   ID        NAME        TICKS\n" );
60#endif
61
62  for ( class_index = OBJECTS_CLASSES_FIRST ;
63        class_index <= OBJECTS_CLASSES_LAST ;
64        class_index++ ) {
65    information = _Objects_Information_table[ class_index ];
66    if ( information && information->is_thread ) {
67      for ( i=1 ; i <= information->maximum ; i++ ) {
68        the_thread = (Thread_Control *)information->local_table[ i ];
69       
70        if ( !the_thread )
71          continue;
72
73        u32_name = *(unsigned32 *)the_thread->Object.name;
74
75        name[ 0 ] = (u32_name >> 24) & 0xff;
76        name[ 1 ] = (u32_name >> 16) & 0xff;
77        name[ 2 ] = (u32_name >>  8) & 0xff;
78        name[ 3 ] = (u32_name >>  0) & 0xff;
79        name[ 4 ] = '\0';
80
81#if defined(unix) || ( CPU_HARDWARE_FP == TRUE )
82        printf( "0x%08x   %4s    %8d     %5.3f\n",
83          the_thread->Object.id,
84          name,
85          the_thread->ticks_executed,
86          (total_units) ?
87            (double)the_thread->ticks_executed / (double)total_units :
88            (double)total_units
89        );
90#else
91        printf( "0x%08x   %4s   %8d\n",
92          the_thread->Object.id,
93          name,
94          the_thread->ticks_executed
95        );
96#endif
97      }
98    }
99  }
100
101  printf(
102    "\nTicks since last reset = %d\n",
103    _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
104  );
105  printf( "\nTotal Units = %d\n", total_units );
106}
107
108/*PAGE
109 *
110 *  CPU_usage_Reset
111 */
112
113void CPU_usage_Reset( void )
114{
115  unsigned32           i;
116  unsigned32           class_index;
117  Thread_Control      *the_thread;
118  Objects_Information *information;
119 
120  CPU_usage_Ticks_at_last_reset = _Watchdog_Ticks_since_boot;
121
122  for ( class_index = OBJECTS_CLASSES_FIRST ;
123        class_index <= OBJECTS_CLASSES_LAST ;
124        class_index++ ) {
125    information = _Objects_Information_table[ class_index ];
126    if ( information && information->is_thread ) {
127      for ( i=1 ; i <= information->maximum ; i++ ) {
128        the_thread = (Thread_Control *)information->local_table[ i ];
129 
130        if ( !the_thread )
131          continue;
132 
133        the_thread->ticks_executed = 0;
134      }
135    }
136  }
137 
138}
139
Note: See TracBrowser for help on using the repository browser.