#3 Kernel instrumentation

eCos kernel includes a mean to trace kernel events. Turned off by default, it can be enable with CYGPKG_KERNEL_INSTRUMENT = 1. Source code of the instrumentation is located in the file:

When enable, the application will log in the instrument_buffer array various information which are:
- The event type
- The thread id / core id (for SMP target)
- The timestamp
- arg1
- arg2

The logging is triggered for different type of events. The nature of the events to be logged is configurable at compile time, .e.g. are:

CYGDBG_KERNEL_INSTRUMENT_USER is reserved for application level debugging where user would require to trace code workflow for instance. eCos allows run time control of the events to be logged with:
cyg_instrument_enable(CYGDBG_KERNEL_INSTRUMENT_type, 0);
cyg_instrument_disable(CYGDBG_KERNEL_INSTRUMENT_type, 0);

It is usually a detious work to analyse the content of the instrument_buffer array. To ease the task, CodeConfidence [3] has developed an Eclipse plug-in for visualizing the array content graphically. Visit their web page for more details.
As an alternative, you can dump the instrument_buffer content using GDB / Eclipse into a file (dump.txt) and use the script -/packages/kernel/current/host/instr/dump_instr.c or this compiled version to format the data. To dump the instrument_buffer, use the memory view of Eclipse debugger, enter the address of the array and select export in plain text mode as shown here:

As an example, lets assume this piece of code:

#include <pkgconf/kernel.h>
#include <cyg/kernel/instrmnt.h> // instrumentation

int a = 5, b;
b = a + 100;

The memory dump of the instrument_buffer array from Eclipse could look like the following (timestamp will of course vary from this example):

0F010002 0004E917 00000005 00000000 0F020002
0004E93B 00000069 00000000

The script output would in the case be:

$ ./ecos_instr.exe dump.txt
0 Record type (0x0f01): USER_1 thread 2, time 321815, arg1 0x00000005, arg2 0x00000000
1 Record type (0x0f02): USER_2 thread 2, time 321851, arg1 0x00000069, arg2 0x00000000

Note that the script -/packages/kernel/current/host/instr/dump_instr.c is compiled by selecting the configuration option CYGDBG_KERNEL_INSTRUMENT_BUILD_HOST_DUMP