in system/trace/trace_dump.c [359:686]
static int trace_dump_one(trace_dump_t type, FAR FILE *out, FAR uint8_t *p,
FAR struct trace_dump_context_s *ctx)
{
FAR struct note_common_s *note = (FAR struct note_common_s *)p;
FAR struct trace_dump_cpu_context_s *cctx;
pid_t pid;
#ifdef CONFIG_SMP
int cpu = note->nc_cpu;
#else
int cpu = 0;
#endif
cctx = &ctx->cpu[cpu];
trace_dump_unflatten(&pid, note->nc_pid, sizeof(pid));
if (cctx->current_pid < 0)
{
cctx->current_pid = pid;
}
/* Output one note */
switch (note->nc_type)
{
case NOTE_START:
{
#if CONFIG_TASK_NAME_SIZE > 0
FAR struct note_start_s *nst = (FAR struct note_start_s *)p;
FAR struct trace_dump_task_context_s *tctx;
tctx = get_task_context(pid, ctx);
if (tctx != NULL)
{
copy_task_name(tctx->name, nst->nst_name);
}
#endif
trace_dump_header(out, note, ctx);
fprintf(out, "sched_wakeup_new: comm=%s pid=%d target_cpu=%d\n",
get_task_name(pid, ctx), get_pid(pid), cpu);
}
break;
case NOTE_STOP:
{
/* This note informs the task to be stopped.
* Change current task state for the succeeding NOTE_RESUME.
*/
cctx->current_state = 0;
}
break;
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
case NOTE_SUSPEND:
{
FAR struct note_suspend_s *nsu = (FAR struct note_suspend_s *)p;
/* This note informs the task to be suspended.
* Preserve the information for the succeeding NOTE_RESUME.
*/
cctx->current_state = nsu->nsu_state;
}
break;
case NOTE_RESUME:
{
/* This note informs the task to be resumed.
* The task switch timing depends on the running context.
*/
cctx->next_pid = pid;
cctx->next_priority = note->nc_priority;
if (cctx->intr_nest == 0)
{
/* If not in the interrupt context, the task switch is
* executed immediately.
*/
trace_dump_header(out, note, ctx);
trace_dump_sched_switch(out, note, ctx);
}
else
{
/* If in the interrupt context, the task switch is postponed
* until leaving the interrupt handler.
*/
trace_dump_header(out, note, ctx);
fprintf(out, "sched_waking: comm=%s pid=%d target_cpu=%d\n",
get_task_name(cctx->next_pid, ctx),
get_pid(cctx->next_pid), cpu);
cctx->pendingswitch = true;
}
}
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
case NOTE_SYSCALL_ENTER:
{
FAR struct note_syscall_enter_s *nsc;
FAR struct trace_dump_task_context_s *tctx;
int i;
int j;
uintptr_t arg;
/* Exclude the case of syscall issued by an interrupt handler and
* nested syscalls to correct tracecompass display.
*/
if (cctx->intr_nest > 0)
{
break;
}
tctx = get_task_context(pid, ctx);
if (tctx == NULL)
{
break;
}
tctx->syscall_nest++;
if (tctx->syscall_nest > 1)
{
break;
}
nsc = (FAR struct note_syscall_enter_s *)p;
if (nsc->nsc_nr < CONFIG_SYS_RESERVED ||
nsc->nsc_nr >= SYS_maxsyscall)
{
break;
}
trace_dump_header(out, note, ctx);
if (type == TRACE_TYPE_ANDROID)
{
fprintf(out, "tracing_mark_write: B|%d|sys_%s(",
pid, g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED]);
}
else
{
fprintf(out, "sys_%s(",
g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED]);
}
for (i = j = 0; i < nsc->nsc_argc; i++)
{
trace_dump_unflatten(&arg, nsc->nsc_args, sizeof(arg));
if (i == 0)
{
fprintf(out, "arg%d: 0x%" PRIxPTR, i, arg);
}
else
{
fprintf(out, ", arg%d: 0x%" PRIxPTR, i, arg);
}
}
fprintf(out, ")\n");
}
break;
case NOTE_SYSCALL_LEAVE:
{
FAR struct note_syscall_leave_s *nsc;
FAR struct trace_dump_task_context_s *tctx;
uintptr_t result;
/* Exclude the case of syscall issued by an interrupt handler and
* nested syscalls to correct tracecompass display.
*/
if (cctx->intr_nest > 0)
{
break;
}
tctx = get_task_context(pid, ctx);
if (tctx == NULL)
{
break;
}
tctx->syscall_nest--;
if (tctx->syscall_nest > 0)
{
break;
}
tctx->syscall_nest = 0;
nsc = (FAR struct note_syscall_leave_s *)p;
if (nsc->nsc_nr < CONFIG_SYS_RESERVED ||
nsc->nsc_nr >= SYS_maxsyscall)
{
break;
}
trace_dump_header(out, note, ctx);
trace_dump_unflatten(&result, nsc->nsc_result, sizeof(result));
if (type == TRACE_TYPE_ANDROID)
{
fprintf(out, "tracing_mark_write: E|%d|"
"sys_%s -> 0x%" PRIxPTR "\n", pid,
g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED],
result);
}
else
{
fprintf(out, "sys_%s -> 0x%" PRIxPTR "\n",
g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED],
result);
}
}
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
case NOTE_IRQ_ENTER:
{
FAR struct note_irqhandler_s *nih;
nih = (FAR struct note_irqhandler_s *)p;
trace_dump_header(out, note, ctx);
fprintf(out, "irq_handler_entry: irq=%u name=%d\n",
nih->nih_irq, nih->nih_irq);
cctx->intr_nest++;
}
break;
case NOTE_IRQ_LEAVE:
{
FAR struct note_irqhandler_s *nih;
nih = (FAR struct note_irqhandler_s *)p;
trace_dump_header(out, note, ctx);
fprintf(out, "irq_handler_exit: irq=%u ret=handled\n",
nih->nih_irq);
cctx->intr_nest--;
if (cctx->intr_nest <= 0)
{
cctx->intr_nest = 0;
if (cctx->pendingswitch)
{
/* If the pending task switch exists, it is executed here */
trace_dump_header(out, note, ctx);
trace_dump_sched_switch(out, note, ctx);
}
}
}
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
case NOTE_DUMP_STRING:
{
FAR struct note_string_s *nst;
uintptr_t ip;
nst = (FAR struct note_string_s *)p;
trace_dump_header(out, note, ctx);
trace_dump_unflatten(&ip, nst->nst_ip, sizeof(ip));
if (type == TRACE_TYPE_ANDROID &&
nst->nst_data[1] == '\0' &&
(nst->nst_data[0] == 'B' ||
nst->nst_data[0] == 'E'))
{
fprintf(out, "tracing_mark_write: %c|%d|%pS\n",
nst->nst_data[0], pid, (FAR void *)ip);
}
else if (type == TRACE_TYPE_ANDROID &&
nst->nst_data[1] == '|' &&
(nst->nst_data[0] == 'B' ||
nst->nst_data[0] == 'E'))
{
fprintf(out, "tracing_mark_write: %s\n",
nst->nst_data);
}
else
{
fprintf(out, "%pS: %s\n", (FAR void *)ip, nst->nst_data);
}
}
break;
case NOTE_DUMP_BINARY:
{
FAR struct note_binary_s *nbi;
uint8_t count;
uintptr_t ip;
int i;
nbi = (FAR struct note_binary_s *)p;
trace_dump_header(out, note, ctx);
count = note->nc_length - sizeof(struct note_binary_s) + 1;
trace_dump_unflatten(&ip, nbi->nbi_ip, sizeof(ip));
fprintf(out, "0x%" PRIdPTR ": event=%u count=%u",
ip, nbi->nbi_event, count);
for (i = 0; i < count; i++)
{
fprintf(out, " 0x%x", nbi->nbi_data[i]);
}
fprintf(out, "\n");
}
break;
#endif
default:
break;
}
fflush(out);
/* Return the length of the processed note */
return note->nc_length;
}