mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
drivers/note: simplify notesnap_dump logic
RTOSXMDPYX-969 Crash at startup, index is 0 will cause loop printing Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
@@ -368,40 +368,28 @@ int notesnap_register(void)
|
|||||||
|
|
||||||
void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
|
void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
|
||||||
{
|
{
|
||||||
|
size_t index = g_notesnap.index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t index = atomic_load(&g_notesnap.index) %
|
|
||||||
CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
|
|
||||||
clock_t lastcount = g_notesnap.buffer[index].count;
|
|
||||||
struct timespec lasttime =
|
|
||||||
{
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Stop recording while dumping */
|
/* Stop recording while dumping */
|
||||||
|
|
||||||
atomic_store(&g_notesnap.dumping, true);
|
atomic_store(&g_notesnap.dumping, true);
|
||||||
|
|
||||||
for (i = index; i != index - 1;
|
for (i = 0; i < CONFIG_DRIVERS_NOTESNAP_NBUFFERS; i++)
|
||||||
i == CONFIG_DRIVERS_NOTESNAP_NBUFFERS - 1 ? i = 0 : i++)
|
|
||||||
{
|
{
|
||||||
FAR struct notesnap_chunk_s *note = &g_notesnap.buffer[i];
|
FAR struct notesnap_chunk_s *note = &g_notesnap.buffer
|
||||||
|
[(index + i) % CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
clock_t elapsed = note->count < lastcount ?
|
|
||||||
note->count + CLOCK_MAX - lastcount :
|
|
||||||
note->count - lastcount;
|
|
||||||
perf_convert(elapsed, &time);
|
|
||||||
clock_timespec_add(&lasttime, &time, &lasttime);
|
|
||||||
lastcount = note->count;
|
|
||||||
|
|
||||||
|
perf_convert(note->count, &time);
|
||||||
lib_sprintf(stream,
|
lib_sprintf(stream,
|
||||||
"snapshoot: [%u.%09u] "
|
"snapshoot: [%u.%09u] "
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
"[CPU%d] "
|
"[CPU%d] "
|
||||||
#endif
|
#endif
|
||||||
"[%d] %-16s %#" PRIxPTR "\n",
|
"[%d] %-16s %#" PRIxPTR "\n",
|
||||||
(unsigned)lasttime.tv_sec,
|
(unsigned)time.tv_sec,
|
||||||
(unsigned)lasttime.tv_nsec,
|
(unsigned)time.tv_nsec,
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
note->cpu,
|
note->cpu,
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user