source: rtems-docs/c_user/cpu_usage_statistics.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

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