Skip to content

Commit 93537bf

Browse files
author
yukangzhi
committed
apps/system/trace: support binary dump of noteram
This patch adds support for dumping binary contents from noteram via the `trace dump -b <file>` command. Changes include: - Add a `binary` parameter to `trace_dump()` and the public header `system/trace/trace.h` to indicate binary output mode. - Update `trace_dump()` to set the noteram read mode to binary using `NOTERAM_SETREADMODE` when requested. - Update `trace dump` CLI parsing in `system/trace/trace.c` to accept the `-b` flag and pass it through to `trace_dump()`. - Update usage/help text to include the new `-b` option. Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
1 parent b72f799 commit 93537bf

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

system/trace/trace.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,20 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc,
147147
{
148148
FAR FILE *out = stdout;
149149
bool changed = false;
150+
bool binary = false;
150151
bool cont = false;
151152
int ret;
152153

153-
/* Usage: trace dump [-c][<filename>] */
154+
/* Usage: trace dump [-b][-c][<filename>] */
155+
156+
if (index < argc)
157+
{
158+
if (strcmp(argv[index], "-b") == 0)
159+
{
160+
binary = true;
161+
index++;
162+
}
163+
}
154164

155165
if (index < argc)
156166
{
@@ -192,11 +202,14 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc,
192202

193203
/* Dump the trace header */
194204

195-
fputs("# tracer: nop\n#\n", out);
205+
if (!binary)
206+
{
207+
fputs("# tracer: nop\n#\n", out);
208+
}
196209

197210
/* Dump the trace data */
198211

199-
ret = trace_dump(out);
212+
ret = trace_dump(out, binary);
200213

201214
if (changed)
202215
{
@@ -803,9 +816,8 @@ static void show_usage(void)
803816
" Get the trace while running <command>\n"
804817
#endif
805818
#ifdef CONFIG_DRIVERS_NOTERAM
806-
" dump [-a][-c][<filename>] :"
819+
" dump [-b][-c][<filename>] :"
807820
" Output the trace result\n"
808-
" [-a] <Android SysTrace>\n"
809821
#endif
810822
" mode [{+|-}{o|w|s|a|i|d}...] :"
811823
" Set task trace options\n"

system/trace/trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern "C"
5757
*
5858
****************************************************************************/
5959

60-
int trace_dump(FAR FILE *out);
60+
int trace_dump(FAR FILE *out, bool binary);
6161

6262
/****************************************************************************
6363
* Name: trace_dump_clear

system/trace/trace_dump.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void note_ioctl(int cmd, unsigned long arg)
6767
*
6868
****************************************************************************/
6969

70-
int trace_dump(FAR FILE *out)
70+
int trace_dump(FAR FILE *out, bool binary)
7171
{
7272
uint8_t tracedata[1024];
7373
int ret;
@@ -82,6 +82,18 @@ int trace_dump(FAR FILE *out)
8282
return ERROR;
8383
}
8484

85+
if (binary)
86+
{
87+
unsigned int mode = NOTERAM_MODE_READ_BINARY;
88+
ret = ioctl(fd, NOTERAM_SETREADMODE, &mode);
89+
if (ret < 0)
90+
{
91+
fprintf(stderr, "trace: cannot set read mode\n");
92+
close(fd);
93+
return ERROR;
94+
}
95+
}
96+
8597
/* Read and output all notes */
8698

8799
while (1)

0 commit comments

Comments
 (0)