Skip to content

Commit 464d284

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
drivers/note: simplify notesnap_dump logic
RTOSXMDPYX-969 Crash at startup, index is 0 will cause loop printing Signed-off-by: yinshengkai <[email protected]>
1 parent 6ad06ba commit 464d284

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

drivers/note/notesnap_driver.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -368,40 +368,28 @@ int notesnap_register(void)
368368

369369
void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
370370
{
371+
size_t index = g_notesnap.index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
371372
size_t i;
372-
size_t index = atomic_load(&g_notesnap.index) %
373-
CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
374-
clock_t lastcount = g_notesnap.buffer[index].count;
375-
struct timespec lasttime =
376-
{
377-
0
378-
};
379373

380374
/* Stop recording while dumping */
381375

382376
atomic_store(&g_notesnap.dumping, true);
383377

384-
for (i = index; i != index - 1;
385-
i == CONFIG_DRIVERS_NOTESNAP_NBUFFERS - 1 ? i = 0 : i++)
378+
for (i = 0; i < CONFIG_DRIVERS_NOTESNAP_NBUFFERS; i++)
386379
{
387-
FAR struct notesnap_chunk_s *note = &g_notesnap.buffer[i];
388-
380+
FAR struct notesnap_chunk_s *note = &g_notesnap.buffer
381+
[(index + i) % CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
389382
struct timespec time;
390-
clock_t elapsed = note->count < lastcount ?
391-
note->count + CLOCK_MAX - lastcount :
392-
note->count - lastcount;
393-
perf_convert(elapsed, &time);
394-
clock_timespec_add(&lasttime, &time, &lasttime);
395-
lastcount = note->count;
396383

384+
perf_convert(note->count, &time);
397385
lib_sprintf(stream,
398386
"snapshoot: [%u.%09u] "
399387
#ifdef CONFIG_SMP
400388
"[CPU%d] "
401389
#endif
402390
"[%d] %-16s %#" PRIxPTR "\n",
403-
(unsigned)lasttime.tv_sec,
404-
(unsigned)lasttime.tv_nsec,
391+
(unsigned)time.tv_sec,
392+
(unsigned)time.tv_nsec,
405393
#ifdef CONFIG_SMP
406394
note->cpu,
407395
#endif

0 commit comments

Comments
 (0)