noteram_driver.c:noteram_dump_printf function replaced with lib_bsprintf.

open CONFIG_DRIVERS_NOTE_STRIP_FORMAT:
OUT:

NuttShell (NSH) NuttX-12.3.0
nsh> hello
nsh> trace dump
loop_task-1   [0]   0.001728177: sched_wakeup_new: comm=loop_task pid=1 target_cpu=0
Idle_Task-0   [0]   0.001745633: sched_wakeup_new: comm=Idle_Task pid=0 target_cpu=0
  hpwork-2   [0]   0.001791495: sched_wakeup_new: comm=hpwork pid=2 target_cpu=0
nsh_main-3   [0]   0.001814164: sched_wakeup_new: comm=nsh_main pid=3 target_cpu=0
   hello-4   [0]   2.583795447: sched_wakeup_new: comm=hello pid=4 target_cpu=0
   hello-4   [0]   2.583843399: tracing_mark_write:
 ###### start long args test!!!
   hello-4   [0]   2.583844088: tracing_mark_write: 0x48ebe0 97 19299 22155 4294967217 4294957304 4294945141 92.999900 9299.929993 92999299929992 18446743074409621624 61 254 429495799   hello-4   [0]   2.583845991: tracing_mark_write: 0x48ec20 qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvb>�/�L�p�J   hello-4   [0]   2.583847105: tracing_mark_write:
 ###### start long args test!!!
   trace-5   [0]   2.928625413: sched_wakeup_new: comm=trace pid=5 target_cpu=0
nsh>

close CONFIG_DRIVERS_NOTE_STRIP_FORMAT:

NuttShell (NSH) NuttX-12.3.0
nsh> hello
nsh> trace dump
loop_task-1   [0]   0.001607506: sched_wakeup_new: comm=loop_task pid=1 target_cpu=0
Idle_Task-0   [0]   0.001624549: sched_wakeup_new: comm=Idle_Task pid=0 target_cpu=0
  hpwork-2   [0]   0.001666256: sched_wakeup_new: comm=hpwork pid=2 target_cpu=0
nsh_main-3   [0]   0.001688556: sched_wakeup_new: comm=nsh_main pid=3 target_cpu=0
   hello-4   [0]   3.812630763: sched_wakeup_new: comm=hello pid=4 target_cpu=0
   hello-4   [0]   0.370899272: tracing_mark_write:
 ###### start NOTE_STRIP_FORMAT test!!!
   hello-4   [0]   0.370900260: tracing_mark_write:            uint8_t[97]:[97]
   hello-4   [0]   0.370900735: tracing_mark_write:           uint16_t[19299]:[19299]
   hello-4   [0]   0.370901155: tracing_mark_write:           uint32_t[22155]:[22155]
   hello-4   [0]   0.370901715: tracing_mark_write:              float[92.9999]:[92.999900]
   hello-4   [0]   0.370902196: tracing_mark_write:             double[9299.929992999299]:[9299.929993]
   hello-4   [0]   0.370902978: tracing_mark_write:             char[][qweretyuiopasdfghjklzxcvbnm]:[qweretyuiopasdfghjklzxcvbnm]
   hello-4   [0]   0.370904061: tracing_mark_write:           uint64_t[92999299929992]:[92999299929992]
   hello-4   [0]   0.370904554: tracing_mark_write:      unsigned char[254]:[254]
   hello-4   [0]   0.370904999: tracing_mark_write: unsigned short int[9299]:[9299]
   hello-4   [0]   0.370905435: tracing_mark_write:       unsigned int[9299992]:[9299992]
   hello-4   [0]   0.370905876: tracing_mark_write:      unsigned long[929992992]:[929992992]
   hello-4   [0]   0.370906402: tracing_mark_write: unsigned long long[9299929924]:[9299929924]
   hello-4   [0]   0.370906822: tracing_mark_write:
 ###### end test!!!
   hello-4   [0]   0.370908999: tracing_mark_write:
 ###### start long args test!!!
   hello-4   [0]   0.370909770: tracing_mark_write: 97 19299 22155 97 19299 22155 92.999900 9299.929993 92999299929992 92999299929992 254 254 9299 9299
   hello-4   [0]   0.370927340: tracing_mark_write: qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweretyuiopasdfghjklzxcvbnm qweret>��+�c�   hello-4   [0]   0.370928037: tracing_mark_write:
 ###### start long args test!!!
   trace-5   [0]   4.173395106: sched_wakeup_new: comm=trace pid=5 target_cpu=0
nsh>

test SRC:

\#include <nuttx/config.h>
\#include <nuttx/streams.h>
\#include <stdio.h>
\#include <syslog.h>
\#define TOSTR(str)   #str
\#define TONNAME(name) TOSTR(name)

\#define v_uint8_t    97
\#define v_uint16_t   19299
\#define v_uint32_t   22155
\#define v_int8_t     -79
\#define v_int16_t    -9992
\#define v_int32_t    -22155
\#define v_float      92.9999
\#define v_double     9299.929992999299
\#define v_char_arr   qweretyuiopasdfghjklzxcvbnm
\#define v_uint64_t   92999299929992
\#define v_int64_t    -999299929992
\#define v_char       61
\#define v_u_char     254
\#define v_s_int      -9299
\#define v_u_s_int    9299
\#define v_int        -9299991
\#define v_u_int      9299992
\#define v_long       -929992991
\#define v_u_long     929992992
\#define v_l_l        -929992993
\#define v_u_l_l      9299929924
\#define v_size_t     29299
\#define v_l_double   -9299.9299929912122464755474

int main(int argc, FAR char *argv[])
{
\#ifdef CONFIG_DRIVERS_NOTE_STRIP_FORMAT
  sched_note_printf(0, "\n ###### start long args test!!! \n");
  sched_note_printf(0, "%u %u %u %d %d %d %f %f %lu %ld %d %u %d %u",
                    v_uint8_t, v_uint16_t, v_uint32_t, v_int8_t, v_int16_t,
                    v_int32_t, v_float, v_double, v_uint64_t, v_int64_t,
                    v_char, v_u_char, v_s_int, v_u_s_int);

  sched_note_printf(0, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s",
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr));
  sched_note_printf(0, "\n ###### start long args test!!! \n");

\#else

  sched_note_printf(0, "\n ###### start NOTE_STRIP_FORMAT test!!! \n");
  sched_note_printf(0, "           uint8_t["TONNAME(v_uint8_t)"]:[%u]", v_uint8_t);
  sched_note_printf(0, "          uint16_t["TONNAME(v_uint16_t)"]:[%u]", v_uint16_t);
  sched_note_printf(0, "          uint32_t["TONNAME(v_uint32_t)"]:[%u]", v_uint32_t);
  sched_note_printf(0, "             float["TONNAME(v_float)"]:[%f]", v_float);
  sched_note_printf(0, "            double["TONNAME(v_double)"]:[%f]", v_double);
  sched_note_printf(0, "            char[]["TONNAME(v_char_arr)"]:[%.32s]", TONNAME(v_char_arr));
  sched_note_printf(0, "          uint64_t["TONNAME(v_uint64_t)"]:[%lu]", v_uint64_t);
  sched_note_printf(0, "     unsigned char["TONNAME(v_u_char)"]:[%u]", v_u_char);
  sched_note_printf(0, "unsigned short int["TONNAME(v_u_s_int)"]:[%u]", v_u_s_int);
  sched_note_printf(0, "      unsigned int["TONNAME(v_u_int)"]:[%u]", v_u_int);
  sched_note_printf(0, "     unsigned long["TONNAME(v_u_long)"]:[%lu]", (unsigned long)v_u_long);
  sched_note_printf(0, "unsigned long long["TONNAME(v_u_l_l)"]:[%llu]", (unsigned long long)v_u_l_l);
  sched_note_printf(0, "\n ###### end test!!! \n");

  sched_note_printf(0, "\n ###### start long args test!!! \n");
  sched_note_printf(0, "%u %u %u %d %d %d %f %f %lu %ld %d %u %d %u",
                    v_uint8_t, v_uint16_t, v_uint32_t, v_uint8_t, v_uint16_t,
                    v_uint32_t, v_float, v_double, v_uint64_t, v_uint64_t,
                    v_u_char, v_u_char, v_u_s_int, v_u_s_int);

  sched_note_printf(0, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s",
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr),
                    TONNAME(v_char_arr), TONNAME(v_char_arr));
  sched_note_printf(0, "\n ###### start long args test!!! \n");
\#endif // !CONFIG_DRIVERS_NOTE_STRIP_FORMAT
  return 0;
}

drivers/note/noteram_driver.c

Signed-off-by: likun17 <likun17@xiaomi.com>
This commit is contained in:
likun17 2024-01-21 17:53:30 +08:00 committed by Xiang Xiao
parent 1b3f3d19e9
commit 1fde78ddc6

View file

@ -737,188 +737,49 @@ static int noteram_dump_sched_switch(FAR struct lib_outstream_s *s,
static int noteram_dump_printf(FAR struct lib_outstream_s *s,
FAR struct note_printf_s *note)
{
begin_packed_struct union
{
int i;
long l;
#ifdef CONFIG_HAVE_LONG_LONG
long long ll;
#endif
intmax_t im;
size_t sz;
ptrdiff_t pd;
FAR void *p;
FAR const char *s;
#ifdef CONFIG_HAVE_DOUBLE
double d;
# ifdef CONFIG_HAVE_LONG_DOUBLE
long double ld;
# endif
#endif
}
end_packed_struct *var;
size_t offset = 0;
size_t ret = 0;
size_t len = 0;
if (note->npt_type == 0)
{
FAR const char *p = note->npt_fmt;
bool infmt = false;
char fmtstr[64];
char c;
while ((c = *p++) != '\0')
{
if (c != '%' && !infmt)
{
lib_stream_putc(s, c);
ret++;
continue;
}
if (!infmt)
{
len = 0;
infmt = true;
memset(fmtstr, 0, sizeof(fmtstr));
}
var = (FAR void *)(note->npt_data + offset);
fmtstr[len++] = c;
if (c == 'c' || c == 'd' || c == 'i' || c == 'u' ||
c == 'o' || c == 'x' || c == 'X')
{
if (*(p - 2) == 'j')
{
offset += sizeof(var->im);
ret += lib_sprintf(s, fmtstr, var->im);
}
#ifdef CONFIG_HAVE_LONG_LONG
else if (*(p - 2) == 'l' && *(p - 3) == 'l')
{
offset += sizeof(var->ll);
ret += lib_sprintf(s, fmtstr, var->ll);
}
#endif
else if (*(p - 2) == 'l')
{
offset += sizeof(var->l);
ret += lib_sprintf(s, fmtstr, var->l);
}
else if (*(p - 2) == 'z')
{
offset += sizeof(var->sz);
ret += lib_sprintf(s, fmtstr, var->sz);
}
else if (*(p - 2) == 't')
{
offset += sizeof(var->pd);
ret += lib_sprintf(s, fmtstr, var->pd);
}
else
{
offset += sizeof(var->i);
ret += lib_sprintf(s, fmtstr, var->i);
}
infmt = false;
}
else if (c == 'e' || c == 'f' || c == 'g' || c == 'a' ||
c == 'A' || c == 'E' || c == 'F' || c == 'G')
{
#ifdef CONFIG_HAVE_DOUBLE
# ifdef CONFIG_HAVE_LONG_DOUBLE
if (*(p - 2) == 'L')
{
offset += sizeof(var->ld);
ret += lib_sprintf(s, fmtstr, var->ld);
}
else
# endif
{
offset += sizeof(var->d);
ret += lib_sprintf(s, fmtstr, var->d);
}
infmt = false;
}
#endif
else if (c == '*')
{
itoa(var->i, fmtstr + len - 1, 10);
len = strlen(fmtstr);
offset += sizeof(var->i);
}
else if (c == 's')
{
const char *str = note->npt_data + offset;
offset += strlen(str) + 1;
ret += lib_sprintf(s, fmtstr, str);
infmt = false;
}
else if (c == 'p')
{
offset += sizeof(var->p);
ret += lib_sprintf(s, fmtstr, var->p);
infmt = false;
}
}
if (*(p - 2) != '\n')
{
lib_stream_putc(s, '\n');
ret++;
}
ret = lib_bsprintf(s, note->npt_fmt, note->npt_data);
}
else
{
size_t count = NOTE_PRINTF_GET_COUNT(note->npt_type);
char fmt[128];
size_t i;
len = strlen(note->npt_fmt);
if (note->npt_fmt[len - 1] == '\n')
{
len--;
}
fmt[0] = '\0';
ret += lib_sprintf(s, "%p", note->npt_fmt);
for (i = 0; i < count; i++)
{
int type = NOTE_PRINTF_GET_TYPE(note->npt_type, i);
var = (FAR void *)(note->npt_data + offset);
switch (type)
{
case NOTE_PRINTF_UINT32:
{
offset += sizeof(var->i);
ret += lib_sprintf(s, " %u", var->i);
strcat(fmt, " %u");
}
break;
case NOTE_PRINTF_UINT64:
{
offset += sizeof(var->ll);
ret += lib_sprintf(s, " %llu", var->ll);
strcat(fmt, " %llu");
}
break;
case NOTE_PRINTF_STRING:
{
const char *str = note->npt_data + offset;
offset += strlen(str) + 1;
ret += lib_sprintf(s, " %s", str);
strcat(fmt, " %s");
}
break;
case NOTE_PRINTF_DOUBLE:
{
offset += sizeof(var->d);
ret += lib_sprintf(s, " %f", var->d);
strcat(fmt, " %f");
}
}
}
ret += lib_bsprintf(s, fmt, note->npt_data);
lib_stream_putc(s, '\n');
ret++;
}