source: rtems/c/src/libmisc/cpuuse/cpuuse.c @ 20f54e9

4.104.114.84.95
Last change on this file since 20f54e9 was 458bd34, checked in by Joel Sherrill <joel.sherrill@…>, on 11/05/99 at 16:44:02

This is another pass at making sure that nothing outside the BSP
unnecessarily uses any variables defined by the BSP. On this
sweep, use of BSP_Configuration and Cpu_table was eliminated.

A significant part of this modification was the addition of
macros to access fields in the RTEMS configuration structures.

This is necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.

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