itrace
Instrumented Trace
Multipass extension

These macros add multipass capabilities to itrace for CPU code only. They are expected to be used in combination with the existing itrace APIs. More...

Macros

#define ITRACE_MULTI_PASS_START_LOOP(logger_handle, profiler_handle)
 
#define ITRACE_MULTI_PASS_END_LOOP(logger_handle, profiler_handle)
 

Detailed Description

These macros add multipass capabilities to itrace for CPU code only. They are expected to be used in combination with the existing itrace APIs.

Multipass functionality is useful for a user who needs to monitor more events that can be registered at a given time.

For example, all existing DSPs can only monitor up to 8 PMU events at a time. If a user needs to monitor 32 PMU events, the same code needs to run 4 times to capture 8 sets of events at a time. The multipass APIs automate this process.

Here is an example on how to use these macros to add multipass support:

Original single-pass code:

// 1. Initialize logger and profiler(s)
itrace_logger_handle_t logger_handle;
itrace_set_root_filename(logger_handle, "myprofile");
itrace_profiler_handle_t profiler_handle;
itrace_open_profiler(logger_handle, CDSP_DOMAIN_ID, 0, &profiler_handle);
// 2. Define which events to monitor
...
itrace_add_event_by_id(profiler_handle, ITRACE_DSP_EVENT_PMU_HVX_ACTIVE); // PMU event 9
// 3. Register events
int num_attempted_to_register_dsp_events=0;
itrace_register_events(dsp_profiler_handle, NULL, &num_attempted_to_register_dsp_events);
printf("itrace attempted to register %d events\n",num_attempted_to_register_dsp_events);
// 4. Monitor the code
itrace_start_section(profiler_handle, "foo", NULL);
remote_call_to_foo();
itrace_end_section(profiler_handle, NULL);
// 5. Deinitialize logger and profiler(s)
itrace_close_profiler(profiler_handle);
itrace_close_logger(logger_handle);

The code above will execute properly, generating myprofile.json and myprofile.csv files. However, only the first 8 added events will be monitored while executing the code. This will be visible from the files being generated by itrace, and from the printf message that will indicate that itrace tried to register only 8 events.

In order to monitor all 10 events, the monitoring code will need to execute twice. This process is automated by simply adding two macros around the monitored section(s) of interest to indicate the start and end of the monitoring loop.

Code extended for multi-pass support

// Initialization code and definition for events remain the same (1-2 unchanged)
ITRACE_MULTI_PASS_START_LOOP(logger_handle, dsp_profiler_handle); // <---- This line marks the start of the monitoring loop
// Registration and monitoring remain the same (3-4 unchanged)
ITRACE_MULTI_PASS_END_LOOP(logger_handle, dsp_profiler_handle); // <---- This line marks the end of the monitoring loop
// Deinitialization code remain the same (5 unchanged)

The revised code will now generate more files:

In order to obtain this information, remote_call_to_foo() will be executed twice.

Macro Definition Documentation

◆ ITRACE_MULTI_PASS_END_LOOP

#define ITRACE_MULTI_PASS_END_LOOP (   logger_handle,
  profiler_handle 
)
Value:
itrace_flush_logs(logger_handle); \
} \
itrace_set_root_filename(logger_handle, itracemp_root_filename); \
itrace_merge_csv_files(itracemp_root_filename,itracemp_file_index);
itrace_return_t itrace_flush_logs(itrace_logger_handle_t logger_handle)
Flush the logs of all opened profilers.

Indicate the end of the code block that needs monitoring

Parameters
[in]logger_handleHandle to the logger instance to use.
[in]profiler_handleHandle to the profiler instance to use.

◆ ITRACE_MULTI_PASS_START_LOOP

#define ITRACE_MULTI_PASS_START_LOOP (   logger_handle,
  profiler_handle 
)
Value:
char itracemp_root_filename[64]; \
itrace_get_root_filename(logger_handle, itracemp_root_filename); \
int itracemp_file_index=0; \
while(1) { /* event loop */ \
int num_events_left_to_register=0; \
itrace_get_num_events_left_to_register(profiler_handle, &num_events_left_to_register); \
if (num_events_left_to_register==0) { \
break; \
} \
char itracemp_root_filename_loop[64]; \
snprintf(itracemp_root_filename_loop,64,"%s_%d",itracemp_root_filename,itracemp_file_index++); \
itrace_set_root_filename(logger_handle, itracemp_root_filename_loop); \
printf("Processing new set into root filename %s. %d events and set separators left to process.\n", itracemp_root_filename_loop, num_events_left_to_register);

Indicate the start of the code block that needs monitoring with more events than supported in a single pass.

The code block identified between ITRACE_MULTI_PASS_START_LOOP and ITRACE_MULTI_PASS_END_LOOP will be executed as many times as is required to monitor all the events that have been added.

Parameters
[in]logger_handleHandle to the logger instance to use.
[in]profiler_handleHandle to the profiler instance to use.