OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libmisc/] [cpuuse/] [cpuuse.c] - Blame information for rev 232

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: cpuuse.c,v 1.2 2001-09-27 12:01:42 chris Exp $
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
 
24
unsigned32 CPU_usage_Ticks_at_last_reset;
25
 
26
/*PAGE
27
 *
28
 *  CPU_usage_Dump
29
 */
30
 
31
void 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
 
113
void 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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.