Skip to content

Commit

Permalink
tracing: make API tracing configurable
Browse files Browse the repository at this point in the history
So far only object tracing/tracking could be individually disabled (e.g.
CONFIG_TRACING_SEMAPHORE=n). Now tracing of any API may be disabled
(e.g. CONFIG_TRACING_PM=n).

(cherry picked from commit d218b20)

Original-Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
GitOrigin-RevId: d218b20
Change-Id: I092bb0ca7f0549dbff7b826896fd0f20d4da960b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4853668
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Keith Short <keithshort@chromium.org>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Keith Short <keithshort@chromium.org>
  • Loading branch information
fgrandel authored and Chromeos LUCI committed Sep 8, 2023
1 parent 79b2c4b commit acfb7a0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
51 changes: 35 additions & 16 deletions include/zephyr/tracing/tracing_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef ZEPHYR_INCLUDE_TRACING_TRACING_MACROS_H_
#define ZEPHYR_INCLUDE_TRACING_TRACING_MACROS_H_

#include <zephyr/sys/util_macro.h>

#if !defined(CONFIG_TRACING) && !defined(__DOXYGEN__)

#define SYS_PORT_TRACING_FUNC(type, func, ...) do { } while (false)
Expand Down Expand Up @@ -73,6 +75,7 @@
#define sys_port_trace_type_mask_k_thread(trace_call) trace_call
#else
#define sys_port_trace_type_mask_k_thread(trace_call)
#define sys_port_trace_k_thread_is_disabled 1
#endif

#if defined(CONFIG_TRACING_WORK)
Expand Down Expand Up @@ -173,6 +176,29 @@
#define sys_port_trace_type_mask_k_event(trace_call)
#endif

#ifndef CONFIG_TRACING_POLLING
#define sys_port_trace_k_poll_api_is_disabled 1
#define sys_port_trace_k_work_poll_is_disabled 1
#endif

#ifndef CONFIG_TRACING_PM
#define sys_port_trace_pm_is_disabled 1
#endif

/*
* We cannot positively enumerate all traced APIs, as applications may trace
* arbitrary custom APIs we know nothing about. Therefore we demand that tracing
* of an API must be actively disabled.
*
* This contrasts with object tracing/tracking as all traceable objects are well
* known, see the SYS_PORT_TRACING_TYPE_MASK approach below.
*/
#define _SYS_PORT_TRACE_IS_DISABLED(type) sys_port_trace_##type##_is_disabled
#define _SYS_PORT_TRACE_WRAP(func, ...) do { func(__VA_ARGS__); } while (false)
#define _SYS_PORT_TRACE_IF_NOT_DISABLED(type, func, ...) \
COND_CODE_1(_SYS_PORT_TRACE_IS_DISABLED(type), (), \
(_SYS_PORT_TRACE_WRAP(func, __VA_ARGS__)))

/** @endcond */

/**
Expand All @@ -194,10 +220,8 @@
* system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name.
* @param ... Additional parameters relevant to the tracing call
*/
#define SYS_PORT_TRACING_FUNC(type, func, ...) \
do { \
_SYS_PORT_TRACING_FUNC(type, func)(__VA_ARGS__); \
} while (false)
#define SYS_PORT_TRACING_FUNC(type, func, ...) \
_SYS_PORT_TRACE_IF_NOT_DISABLED(type, _SYS_PORT_TRACING_FUNC(type, func), __VA_ARGS__)

/**
* @brief Tracing macro for the entry into a function that might or might not return
Expand All @@ -209,10 +233,8 @@
* system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name.
* @param ... Additional parameters relevant to the tracing call
*/
#define SYS_PORT_TRACING_FUNC_ENTER(type, func, ...) \
do { \
_SYS_PORT_TRACING_FUNC_ENTER(type, func)(__VA_ARGS__); \
} while (false)
#define SYS_PORT_TRACING_FUNC_ENTER(type, func, ...) \
_SYS_PORT_TRACE_IF_NOT_DISABLED(type, _SYS_PORT_TRACING_FUNC_ENTER(type, func), __VA_ARGS__)

/**
* @brief Tracing macro for when a function blocks during its execution.
Expand All @@ -223,10 +245,9 @@
* system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name.
* @param ... Additional parameters relevant to the tracing call
*/
#define SYS_PORT_TRACING_FUNC_BLOCKING(type, func, ...) \
do { \
_SYS_PORT_TRACING_FUNC_BLOCKING(type, func)(__VA_ARGS__); \
} while (false)
#define SYS_PORT_TRACING_FUNC_BLOCKING(type, func, ...) \
_SYS_PORT_TRACE_IF_NOT_DISABLED(type, _SYS_PORT_TRACING_FUNC_BLOCKING(type, func), \
__VA_ARGS__)

/**
* @brief Tracing macro for when a function ends its execution. Potential return values
Expand All @@ -238,10 +259,8 @@
* system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name.
* @param ... Additional parameters relevant to the tracing call
*/
#define SYS_PORT_TRACING_FUNC_EXIT(type, func, ...) \
do { \
_SYS_PORT_TRACING_FUNC_EXIT(type, func)(__VA_ARGS__); \
} while (false)
#define SYS_PORT_TRACING_FUNC_EXIT(type, func, ...) \
_SYS_PORT_TRACE_IF_NOT_DISABLED(type, _SYS_PORT_TRACING_FUNC_EXIT(type, func), __VA_ARGS__)

/**
* @brief Tracing macro for the initialization of an object.
Expand Down
12 changes: 12 additions & 0 deletions subsys/tracing/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ config TRACING_EVENT
help
Enable tracing Events.

config TRACING_POLLING
bool "Tracing Polling"
default y
help
Enable tracing Work Polling and Polling API.

config TRACING_PM
bool "Tracing Power Management"
default y
help
Enable tracing Power Management.

endmenu # Tracing Configuration

endif
Expand Down

0 comments on commit acfb7a0

Please sign in to comment.