[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250722202551.1614f59a@gandalf.local.home>
Date: Tue, 22 Jul 2025 20:25:51 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: WangYuli <wangyuli@...ontech.com>
Cc: dmitry.torokhov@...il.com, guanwentao@...ontech.com,
linux-input@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org, mathieu.desnoyers@...icios.com,
mhiramat@...nel.org, niecheng1@...ontech.com, wangyuli@...pin.org,
zhanjun@...ontech.com, Winston Wen <wentao@...ontech.com>
Subject: Re: [PATCH 1/2] input: Add tracepoint support
On Thu, 10 Jul 2025 15:31:38 +0800
WangYuli <wangyuli@...ontech.com> wrote:
> diff --git a/include/trace/events/input.h b/include/trace/events/input.h
> new file mode 100644
> index 000000000000..3c5ffcfb7c8d
> --- /dev/null
> +++ b/include/trace/events/input.h
> @@ -0,0 +1,251 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* input tracepoints
> + *
> + * Copyright (C) 2025 WangYuli <wangyuli@...ontech.com>
> + */
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM input
> +
> +#if !defined(_TRACE_INPUT_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_INPUT_H
> +
> +#include <linux/tracepoint.h>
> +#include <linux/input.h>
> +
> +/**
> + * input_event - called when an input event is processed
> + * @dev: input device that generated the event
> + * @type: event type (EV_KEY, EV_REL, EV_ABS, etc.)
> + * @code: event code within the type
> + * @value: event value
> + *
> + * This tracepoint fires for every input event processed by the input core.
> + * It can be used to monitor input device activity and debug input issues.
> + */
> +TRACE_EVENT(
> + input_event,
> +
> + TP_PROTO(struct input_dev *dev, unsigned int type, unsigned int code,
> + int value),
> +
> + TP_ARGS(dev, type, code, value),
> +
> + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __field(
> + unsigned int, type) __field(unsigned int, code)
> + __field(int, value) __field(u16, bustype)
> + __field(u16, vendor)
> + __field(u16, product)),
> +
The contents of the tracepoints in the subsystems are determined by the
subsystem maintainers, but please follow the tracepoint formatting. The
above is horrible. It should look like a structure layout. One wouldn't
write:
struct entry { char *name;
unsigned int type; unsigned int code;
int value; u16 bustype;
u16 vendor;
u16 product; };
That's what the above looks like. It should be instead:
TP_STRUCT__entry(
__string( name, dev->name ?: "unknown" )
__field( unsigned int, type )
__field( unsigned int, code )
__field( int, value )
__field( u16, bustype )
__field( u16, vendor )
__field( u16, product )
),
So the fields can be easily visible and easily reviewed.
> + TP_fast_assign(__assign_str(name); __entry->type = type;
> + __entry->code = code; __entry->value = value;
> + __entry->bustype = dev->id.bustype;
> + __entry->vendor = dev->id.vendor;
> + __entry->product = dev->id.product;),
> +
> + TP_printk(
> + "dev=%s type=%u code=%u value=%d bus=%04x vendor=%04x product=%04x",
> + __get_str(name), __entry->type, __entry->code, __entry->value,
> + __entry->bustype, __entry->vendor, __entry->product));
> +
> +/**
> + * input_device_register - called when an input device is registered
> + * @dev: input device being registered
> + *
> + * This tracepoint fires when a new input device is registered with the
> + * input subsystem. Useful for monitoring device hotplug events.
> + */
> +TRACE_EVENT(
> + input_device_register,
> +
> + TP_PROTO(struct input_dev *dev),
> +
> + TP_ARGS(dev),
> +
> + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __string(
> + phys, dev->phys ?: "") __field(u16, bustype)
> + __field(u16, vendor) __field(u16, product)
> + __field(u16, version)),
Same here.
> +
> + TP_fast_assign(__assign_str(name); __assign_str(phys);
> + __entry->bustype = dev->id.bustype;
> + __entry->vendor = dev->id.vendor;
> + __entry->product = dev->id.product;
> + __entry->version = dev->id.version;),
> +
> + TP_printk(
> + "dev=%s phys=%s bus=%04x vendor=%04x product=%04x version=%04x",
> + __get_str(name), __get_str(phys), __entry->bustype,
> + __entry->vendor, __entry->product, __entry->version));
> +
> +/**
> + * input_device_unregister - called when an input device is unregistered
> + * @dev: input device being unregistered
> + *
> + * This tracepoint fires when an input device is unregistered from the
> + * input subsystem. Useful for monitoring device hotplug events.
> + */
> +TRACE_EVENT(input_device_unregister,
> +
> + TP_PROTO(struct input_dev *dev),
> +
> + TP_ARGS(dev),
> +
> + TP_STRUCT__entry(__string(name, dev->name ?: "unknown") __string(
> + phys, dev->phys ?: "") __field(u16, bustype)
> + __field(u16, vendor)
> + __field(u16, product)),
ditto.
> +
> + TP_fast_assign(__assign_str(name); __assign_str(phys);
> + __entry->bustype = dev->id.bustype;
> + __entry->vendor = dev->id.vendor;
> + __entry->product = dev->id.product;),
> +
> + TP_printk("dev=%s phys=%s bus=%04x vendor=%04x product=%04x",
> + __get_str(name), __get_str(phys), __entry->bustype,
> + __entry->vendor, __entry->product));
> +
> +/**
> + * input_handler_connect - called when an input handler connects to a device
> + * @handler: input handler
> + * @dev: input device
> + * @minor: assigned minor number (if applicable)
> + *
> + * This tracepoint fires when an input handler (like evdev, mousedev) connects
> + * to an input device, creating a new input handle.
> + */
> +TRACE_EVENT(input_handler_connect,
> +
> + TP_PROTO(struct input_handler *handler, struct input_dev *dev,
> + int minor),
> +
> + TP_ARGS(handler, dev, minor),
> +
> + TP_STRUCT__entry(__string(handler_name, handler->name)
> + __string(dev_name, dev->name ?: "unknown")
> + __field(int, minor)),
ditto.
> +
> + TP_fast_assign(__assign_str(handler_name); __assign_str(dev_name);
> + __entry->minor = minor;),
> +
> + TP_printk("handler=%s dev=%s minor=%d", __get_str(handler_name),
> + __get_str(dev_name), __entry->minor));
> +
> +/**
> + * input_grab_device - called when a device is grabbed by a handler
> + * @dev: input device being grabbed
> + * @handle: input handle doing the grab
> + *
> + * This tracepoint fires when an input device is grabbed exclusively
> + * by an input handler, typically for security or special processing.
> + */
> +TRACE_EVENT(input_grab_device,
> +
> + TP_PROTO(struct input_dev *dev, struct input_handle *handle),
> +
> + TP_ARGS(dev, handle),
> +
> + TP_STRUCT__entry(__string(dev_name, dev->name ?: "unknown")
> + __string(handler_name,
> + handle->handler->name)),
ditto.
> +
> + TP_fast_assign(__assign_str(dev_name); __assign_str(handler_name);),
> +
> + TP_printk("dev=%s grabbed_by=%s", __get_str(dev_name),
> + __get_str(handler_name)));
> +
> +/**
> + * input_release_device - called when a grabbed device is released
> + * @dev: input device being released
> + * @handle: input handle releasing the grab
> + *
> + * This tracepoint fires when an input device grab is released.
> + */
> +TRACE_EVENT(input_release_device,
> +
> + TP_PROTO(struct input_dev *dev, struct input_handle *handle),
> +
> + TP_ARGS(dev, handle),
> +
> + TP_STRUCT__entry(__string(dev_name, dev->name ?: "unknown")
> + __string(handler_name,
> + handle->handler->name)),
ditto.
> +
> + TP_fast_assign(__assign_str(dev_name); __assign_str(handler_name);),
> +
> + TP_printk("dev=%s released_by=%s", __get_str(dev_name),
> + __get_str(handler_name)));
> +
> +DECLARE_EVENT_CLASS(input_device_state,
> +
> + TP_PROTO(struct input_dev *dev),
> +
> + TP_ARGS(dev),
> +
> + TP_STRUCT__entry(__string(name, dev->name ?: "unknown")
> + __field(unsigned int, users)
> + __field(bool, inhibited)),
ditto.
-- Steve
> +
> + TP_fast_assign(__assign_str(name);
> + __entry->users = dev->users;
> + __entry->inhibited = dev->inhibited;),
> +
> + TP_printk("dev=%s users=%u inhibited=%s", __get_str(name),
> + __entry->users,
> + __entry->inhibited ? "true" : "false"));
> +
Powered by blists - more mailing lists