source: rtems-docs/ada_user/cpu_usage_statistics.rst @ 1a1be7f

4.115
Last change on this file since 1a1be7f was 4783b0d, checked in by Amar Takhar <amar@…>, on 01/17/16 at 16:37:28

Split document into seperate files by section.

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