trace: Add kernel tracepoint support

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-03-03 12:01:02 +08:00 committed by Xiang Xiao
parent 312d6223d3
commit da4e2671f5
2 changed files with 213 additions and 0 deletions

59
Kconfig
View File

@ -2006,6 +2006,65 @@ config FRAME_POINTER
endmenu # Debug Options endmenu # Debug Options
menuconfig TRACE
bool "Enable tracepoints"
default n
depends on SCHED_INSTRUMENTATION
---help---
If this option is enabled, tracepoints at critical code in
the kernel will be enabled.
if TRACE
config TRACE_AUDIO
bool "Enable tracepoints in audio"
default n
config TRACE_ARCH
bool "Enable tracepoints in arch"
default n
config TRACE_BOARDS
bool "Enable tracepoints in boards"
default n
config TRACE_CRYPTO
bool "Enable tracepoints in crypto"
default n
config TRACE_DRIVERS
bool "Enable tracepoints in drivers"
default n
config TRACE_FS
bool "Enable tracepoints in fs"
default n
config TRACE_GRAPHICS
bool "Enable tracepoints in graphics"
default n
config TRACE_LIBS
bool "Enable tracepoints in libs"
default n
config TRACE_NET
bool "Enable tracepoints in net"
default n
config TRACE_SCHED
bool "Enable tracepoints in sched"
default n
config TRACE_VIDEO
bool "Enable tracepoints in video"
default n
config TRACE_WIRELESS
bool "Enable tracepoints in wireless"
default n
endif #TRACE
config ARCH_HAVE_CUSTOMOPT config ARCH_HAVE_CUSTOMOPT
bool bool
default n default n

154
include/nuttx/trace.h Normal file
View File

@ -0,0 +1,154 @@
/****************************************************************************
* include/nuttx/trace.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_TRACE_H
#define __INCLUDE_NUTTX_TRACE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/sched_note.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_TRACE
# define trace_begin(tag) SCHED_NOTE_BEGIN(tag)
# define trace_end(tag) SCHED_NOTE_END(tag)
#else
# define trace_begin(tag)
# define trace_end(tag)
#endif
#ifdef CONFIG_TRACE_APP
# define app_trace_begin() trace_begin(NOTE_TAG_APP)
# define app_trace_end() trace_end(NOTE_TAG_APP)
#else
# define app_trace_begin()
# define app_trace_end()
#endif
#ifdef CONFIG_TRACE_ARCH
# define arch_trace_begin() trace_begin(NOTE_TAG_ARCH)
# define arch_trace_end() trace_end(NOTE_TAG_ARCH)
#else
# define arch_trace_begin()
# define arch_trace_end()
#endif
#ifdef CONFIG_TRACE_AUDIO
# define audio_trace_begin() trace_begin(NOTE_TAG_AUDIO)
# define audio_trace_end() trace_end(NOTE_TAG_AUDIO)
#else
# define audio_trace_begin()
# define audio_trace_end()
#endif
#ifdef CONFIG_TRACE_BOARDS
# define boards_trace_begin() trace_begin(NOTE_TAG_BOARDS)
# define boards_trace_end() trace_end(NOTE_TAG_BOARDS)
#else
# define boards_trace_begin()
# define boards_trace_end()
#endif
#ifdef CONFIG_TRACE_CRYPTO
# define crypto_trace_begin() trace_begin(NOTE_TAG_CRYPTO)
# define crypto_trace_end() trace_end(NOTE_TAG_CRYPTO)
#else
# define crypto_trace_begin()
# define crypto_trace_end()
#endif
#ifdef CONFIG_TRACE_DRIVERS
# define drivers_trace_begin() trace_begin(NOTE_TAG_DRIVERS)
# define drivers_trace_end() trace_end(NOTE_TAG_DRIVERS)
#else
# define drivers_trace_begin()
# define drivers_trace_end()
#endif
#ifdef CONFIG_TRACE_FS
# define fs_trace_begin() trace_begin(NOTE_TAG_FS)
# define fs_trace_end() trace_end(NOTE_TAG_FS)
#else
# define fs_trace_begin()
# define fs_trace_end()
#endif
#ifdef CONFIG_TRACE_GRAPHICS
# define graphics_trace_begin() trace_begin(NOTE_TAG_GRAPHICS)
# define graphics_trace_end() trace_end(NOTE_TAG_GRAPHICS)
#else
# define graphics_trace_begin()
# define graphics_trace_end()
#endif
#ifdef CONFIG_TRACE_LIBS
# define libs_trace_begin() trace_begin(NOTE_TAG_LIBS)
# define libs_trace_end() trace_end(NOTE_TAG_LIBS)
#else
# define libs_trace_begin()
# define libs_trace_end()
#endif
#ifdef CONFIG_TRACE_MM
# define mm_trace_begin() trace_begin(NOTE_TAG_MM)
# define mm_trace_end() trace_end(NOTE_TAG_MM)
#else
# define mm_trace_begin()
# define mm_trace_end()
#endif
#ifdef CONFIG_TRACE_NET
# define net_trace_begin() trace_begin(NOTE_TAG_NET)
# define net_trace_end() trace_end(NOTE_TAG_NET)
#else
# define net_trace_begin()
# define net_trace_end()
#endif
#ifdef CONFIG_TRACE_SCHED
# define sched_trace_begin() trace_begin(NOTE_TAG_SCHED)
# define sched_trace_end() trace_end(NOTE_TAG_SCHED)
#else
# define sched_trace_begin()
# define sched_trace_end()
#endif
#ifdef CONFIG_TRACE_VIDEO
# define video_trace_begin() trace_begin(NOTE_TAG_VIDEO)
# define video_trace_end() trace_end(NOTE_TAG_VIDEO)
#else
# define video_trace_begin()
# define video_trace_end()
#endif
#ifdef CONFIG_TRACE_WIRELESS
# define wireless_trace_begin() trace_begin(NOTE_TAG_WIRLESS)
# define wireless_trace_end() trace_end(NOTE_TAG_WIRLESS)
#else
# define wireless_trace_begin()
# define wireless_trace_end()
#endif
#endif /* __INCLUDE_NUTTX_TRACE_H */