OCEOS/oceos profiling
OCEOS Profiling
Introduction
Each time a context switch or interrupt occurs, four 32-bit words are added to the context switch log if enabled.
The first of these describes the type of switch and also gives the current window pointer (CWP) and the low 8 bits of the high 32 bits of the 64-bit system time when the switch occurred. The second gives the 32-bit system time in microseconds at which the switch occurred.
The third gives the start delay if a task is being started, otherwise a signed int giving the remaining time until the deadline or INT_MAX if the task has no deadline, a negative value gives by how much the deadline has been missed. The fourth gives the current system stack pointer.
The user specifies the number of entries in the context switch log in the application configuration. This size is given as a number in the range 3 to 12, resulting in from 2^3 to 2^12 entries. If a size outside this range is specified no context switch log is present (no header and no entries).
If valid the size is stored in sysMetaPtr->CS_log_entries_base2. If invalid this holds 0, CS logging is off.
CS Log Structure:
CS Header followed by circular buffer, each buffer entry four 32-bit words.
Switch information (first word):
8 bits high time bits (31 to 24) 5 bits CWP (23 to 19) 1 bit (18) switch type, 0=> starting, 1 => interrupt or ending 1 bit (17) ‘from’ ID type, 0=> from task, 1 => from interrupt 1 bit (16) ‘to’ ID type, 0 => to task, 1 => to interrupt 8 bits (15 to 8) ID of task/interrupt from which switching 8 bits (7 to 0) ID of task/interrupt to which switching TASK_ID_INVALID (0xff) is used to indicate switching to or from the scheduler itself. The interrupt ID 0 is not expected to occur, used as TO when CPU put to sleep Initialised by oceos_start() to 0x0000ffff (invalid as scheduler doesn’t switch to itself). Context switch time word (second word):
Low 32 bits of the time at which switch happened. The next 8 bits of the 64-bit system time are given in the switch information word, giving an overall 40-bit time value. Initialised to 0. Start wait time / deadline time margin word (third word):
When first starting a task, the delay between the start request and execution beginning. Otherwise a signed int giving remaining time until deadline or 0x7fffffff if no deadline. Initialised to 0. System stack pointer (fourth word):
System stack pointer when switch was made. Initialized to 0.
Stored in log area immediately after last system log entry and before END_SENTINEL for log area.
Space needed for CS log is included in log area size recorded at the start of the log area.
Number of CS log entries is 2^size unless size is invalid, in which case no storage is used.
If sysMetaPtr->CS_log_entries_base2 is outside the allowed range (typically 0) no context switch logging is done. The CS header is not present, END_SENTINEL is at that position instead.
Configuration
DMON Commands
oceos profile <status|enable|disable>
- oceos profile displays context switch logging information. This functionality can be enabled/disabled or show current status of the command. Context switch logging should be enabled in OCEOS before this command can be used. More information about context switch logging can be found here.
This command can be used only when DMON starts with -gui switch and executable with OCEOS loaded to the target. This view can be displayed in separate window.
The table below shows all the entries read from the target (system log messages, user log messages, context switching from context to context). DMON reads log area and context switch log area and presents in readable form. Available information for each log entry depends on log type. Log types:
- System log entry
- Displays log error type and extra log information
- User log entry
- Displays user defined value and extra log information
- Switch from task to task
- Starting new task
- Displays delay between request to start the task and actual time when task was started
- Ending task
- Displays remaining time until deadline if was specified by user, when task was created
- Switch from task to scheduler
- Switch from task to sleep
- Also DMON displays stack pointer at the time of context switch, CWP(current window pointer) and system state variable.
The table allows browsing through the list of log entries, moving from one context to another. Double click on any entry in the table sets the marker on the time line. Zoom in and out can be used only then to have a closer look at selected time frame. Time Line and Stack view are synchronized to match the currently selected entry.
The Stack Graph below displays stack for the last minute. Stack displays between MIN and MAX values if specified by user in app_config.c
The Time Line view below displays system interaction by context over time. Each row presents the context. Tasks are ordered by its priorities, from higher to lower. The first row presents the overall context switch activities. The real time update of Time Line is possible only at 10ms scale by moving the scroll bar to the max on the right.
Task run time is shown as rectangle filled with task specific color.
Context switches marked with vertical lines.
Grey rectangle before task indicates the time from start request to actual task start.
DMON can detect buffer overrun. The message is printed to the console and red vertical line displayed on the Time Line View. If this happened, context switch log buffer size has to be increased.
Setting the marker by double clicking on the entry in the table
Zoom in to 1 micro second
Time Line view has some basic controls:
- Status (running/paused)
- Button to enable/disable command
- Save button (please see below)
- Slider to change time scale. It is disabled and defaults to 10ms while updating in real time.
Limitations:
- If Context switch buffer is too big it puts constrains on the link to the target. This can happen if the rate, at which the tasks are started, is very frequent. If this is the case then this feature cannot be used and cpuload command is the only choice, as it does not depend on buffer size.
oceos profile save <fileName>
- oceos profile save saves context switch logging to the csv file. This command activates saving to the file. After all content is saved, it continues appending to the file. This command cannot be disabled. Every time when new image is loaded to the target, new csv file is created.
If fileName parameter is not specified, the file is created in DMON User directory: c:\Users\UserName\DMON\UserData