apps/trace: add switch and dump instrumentation

usage:
    trace switch switch [+|-]
                             Configure switch trace filter

    trace print [+|-]
                             Configure dump trace filter

Signed-off-by: zhanghu6 <zhanghu6@xiaomi.com>
This commit is contained in:
zhanghu6 2022-02-18 17:13:25 +08:00 committed by Alan Carvalho de Assis
parent 4680a25a8c
commit 18b5902a3e

View File

@ -325,6 +325,19 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
case 'w': /* Switch trace */
if (enable)
{
mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH;
}
else
{
mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH;
}
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
case 's': /* Syscall trace */
if (enable)
@ -362,6 +375,19 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
break;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
case 'd': /* Dump trace */
if (enable)
{
mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP;
}
else
{
mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP;
}
break;
#endif
default:
fprintf(stderr,
"trace mode: invalid option '%s'\n", argv[index]);
@ -440,6 +466,54 @@ static int trace_cmd_mode(int index, int argc, FAR char **argv,
return index;
}
/****************************************************************************
* Name: trace_cmd_switch
****************************************************************************/
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
static int trace_cmd_switch(int index, int argc, FAR char **argv,
int notectlfd)
{
bool enable;
struct note_filter_mode_s mode;
/* Usage: trace switch [+|-] */
/* Get current filter setting */
ioctl(notectlfd, NOTECTL_GETMODE, (unsigned long)&mode);
/* Parse the setting parameters */
if (argv[index][0] == '-' || argv[index][0] == '+')
{
enable = (argv[index][0] == '+');
if (enable ==
((mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) != 0))
{
/* Already set */
return false;
}
if (enable)
{
mode.flag |= NOTE_FILTER_MODE_FLAG_SWITCH;
}
else
{
mode.flag &= ~NOTE_FILTER_MODE_FLAG_SWITCH;
}
ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode);
index++;
}
return index;
}
#endif
/****************************************************************************
* Name: trace_cmd_syscall
****************************************************************************/
@ -642,6 +716,54 @@ static int trace_cmd_irq(int index, int argc, FAR char **argv, int notectlfd)
}
#endif
/****************************************************************************
* Name: trace_cmd_print
****************************************************************************/
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
static int trace_cmd_print(int index, int argc, FAR char **argv,
int notectlfd)
{
bool enable;
struct note_filter_mode_s mode;
/* Usage: trace print [+|-] */
/* Get current filter setting */
ioctl(notectlfd, NOTECTL_GETMODE, (unsigned long)&mode);
/* Parse the setting parameters */
if (argv[index][0] == '-' || argv[index][0] == '+')
{
enable = (argv[index][0] == '+');
if (enable ==
((mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) != 0))
{
/* Already set */
return false;
}
if (enable)
{
mode.flag |= NOTE_FILTER_MODE_FLAG_DUMP;
}
else
{
mode.flag &= ~NOTE_FILTER_MODE_FLAG_DUMP;
}
ioctl(notectlfd, NOTECTL_SETMODE, (unsigned long)&mode);
index++;
}
return index;
}
#endif
/****************************************************************************
* Name: show_usage
****************************************************************************/
@ -663,8 +785,12 @@ static void show_usage(void)
" dump [-c][<filename>] :"
" Output the trace result\n"
#endif
" mode [{+|-}{o|s|a|i}...] :"
" mode [{+|-}{o|w|s|a|i|d}...] :"
" Set task trace options\n"
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
" switch [+|-] :"
" Configure switch trace filter\n"
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
" syscall [{+|-}<syscallname>...] :"
" Configure syscall trace filter\n"
@ -672,6 +798,10 @@ static void show_usage(void)
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
" irq [{+|-}<irqnum>...] :"
" Configure IRQ trace filter\n"
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
" print [+|-] :"
" Configure dump trace filter\n"
#endif
);
}
@ -734,6 +864,12 @@ int main(int argc, FAR char *argv[])
{
i = trace_cmd_mode(i + 1, argc, argv, notectlfd);
}
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
else if (strcmp(argv[i], "switch") == 0)
{
i = trace_cmd_switch(i + 1, argc, argv, notectlfd);
}
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
else if (strcmp(argv[i], "syscall") == 0)
{
@ -745,6 +881,12 @@ int main(int argc, FAR char *argv[])
{
i = trace_cmd_irq(i + 1, argc, argv, notectlfd);
}
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
else if (strcmp(argv[i], "print") == 0)
{
i = trace_cmd_print(i + 1, argc, argv, notectlfd);
}
#endif
else
{