source: rtems-docs/c_user/cpu_usage_statistics.rst @ 0d86b71

4.115
Last change on this file since 0d86b71 was 0d86b71, checked in by Chris Johns <chrisj@…>, on 02/18/16 at 04:29:28

Clean up.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1.. COMMENT: COPYRIGHT (c) 1988-2008.
2.. COMMENT: On-Line Applications Research Corporation (OAR).
3.. COMMENT: All rights reserved.
4
5CPU Usage Statistics
6####################
7
8Introduction
9============
10
11The CPU usage statistics manager is an RTEMS support component that provides a
12convenient way to manipulate the CPU usage information associated with each
13task The routines provided by the CPU usage statistics manager are:
14
15- rtems_cpu_usage_report_ - Report CPU Usage Statistics
16
17- rtems_cpu_usage_reset_ - Reset CPU Usage Statistics
18
19Background
20==========
21
22When analyzing and debugging real-time applications, it is important to be able
23to know how much CPU time each task in the system consumes.  This support
24component provides a mechanism to easily obtain this information with little
25burden placed on the target.
26
27The raw data is gathered as part of performing a context switch.  RTEMS keeps
28track of how many clock ticks have occurred which the task being switched out
29has been executing.  If the task has been running less than 1 clock tick, then
30for the purposes of the statistics, it is assumed to have executed 1 clock
31tick.  This results in some inaccuracy but the alternative is for the task to
32have appeared to execute 0 clock ticks.
33
34RTEMS versions newer than the 4.7 release series, support the ability to obtain
35timestamps with nanosecond granularity if the BSP provides support.  It is a
36desirable enhancement to change the way the usage data is gathered to take
37advantage of this recently added capability.  Please consider sponsoring the
38core RTEMS development team to add this capability.
39
40Operations
41==========
42
43Report CPU Usage Statistics
44---------------------------
45
46The application may dynamically report the CPU usage for every task in the
47system by calling the ``rtems_cpu_usage_report`` routine.  This routine prints
48a table with the following information per task:
49
50- task id
51
52- task name
53
54- number of clock ticks executed
55
56- percentage of time consumed by this task
57
58The following is an example of the report generated:
59
60.. code:: c
61
62 +------------------------------------------------------------------------------+
63 |CPU USAGE BY THREAD                                                           |
64 +-----------+----------------------------------------+-------------------------+
65 |ID         | NAME                                   | SECONDS       | PERCENT |
66 +-----------+----------------------------------------+---------------+---------+
67 |0x04010001 | IDLE                                   |             0 |   0.000 |
68 +-----------+----------------------------------------+---------------+---------+
69 |0x08010002 | TA1                                    |          1203 |   0.748 |
70 +-----------+----------------------------------------+---------------+---------+
71 |0x08010003 | TA2                                    |           203 |   0.126 |
72 +-----------+----------------------------------------+---------------+---------+
73 |0x08010004 | TA3                                    |           202 |   0.126 |
74 +-----------+----------------------------------------+---------------+---------+
75 |TICKS SINCE LAST SYSTEM RESET:                                           1600 |
76 |TOTAL UNITS:                                                             1608 |
77 +------------------------------------------------------------------------------+
78
79Notice that the ``TOTAL UNITS`` is greater than the ticks per reset.  This is
80an artifact of the way in which RTEMS keeps track of CPU usage.  When a task is
81context switched into the CPU, the number of clock ticks it has executed is
82incremented.  While the task is executing, this number is incremented on each
83clock tick.  Otherwise, if a task begins and completes execution between
84successive clock ticks, there would be no way to tell that it executed at all.
85
86Another thing to keep in mind when looking at idle time, is that many systems -
87especially during debug - have a task providing some type of debug interface.
88It is usually fine to think of the total idle time as being the sum of the
89``IDLE`` task and a debug task that will not be included in a production build
90of an application.
91
92Reset CPU Usage Statistics
93--------------------------
94
95Invoking the ``rtems_cpu_usage_reset`` routine resets the CPU usage statistics
96for all tasks in the system.
97
98Directives
99==========
100
101This section details the CPU usage statistics manager's directives.  A
102subsection is dedicated to each of this manager's directives and describes the
103calling sequence, related constants, usage, and status codes.
104
105.. _rtems_cpu_usage_report:
106
107cpu_usage_report - Report CPU Usage Statistics
108----------------------------------------------
109
110**CALLING SEQUENCE:**
111
112.. code:: c
113
114    void rtems_cpu_usage_report( void );
115
116**STATUS CODES:**
117
118NONE
119
120**DESCRIPTION:**
121
122This routine prints out a table detailing the CPU usage statistics for all
123tasks in the system.
124
125**NOTES:**
126
127The table is printed using the ``printk`` routine.
128
129.. _rtems_cpu_usage_reset:
130
131cpu_usage_reset - Reset CPU Usage Statistics
132--------------------------------------------
133
134**CALLING SEQUENCE:**
135
136.. code:: c
137
138    void rtems_cpu_usage_reset( void );
139
140**STATUS CODES:**
141
142NONE
143
144**DESCRIPTION:**
145
146This routine re-initializes the CPU usage statistics for all tasks in the
147system to their initial state.  The initial state is that a task has not
148executed and thus has consumed no CPU time.  default state which is when zero
149period executions have occurred.
150
151**NOTES:**
152
153NONE
Note: See TracBrowser for help on using the repository browser.