[libcamera-devel,v2,5/7] tracepoints: v4l2: Add tracepoints for tracking buffer lifetime
diff mbox series

Message ID 20221213091558.621950-6-paul.elder@ideasonboard.com
State New
Headers show
Series
  • tracepoints: request: Improve request tracepoints
Related show

Commit Message

Paul Elder Dec. 13, 2022, 9:15 a.m. UTC
Add tracepoints in V4L2VideoDevice for tracing the lifetime of
libcamera FrameBuffers.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
New in v2
---
 .../internal/tracepoints/meson.build          |  2 +
 .../libcamera/internal/tracepoints/v4l2.tp    | 77 +++++++++++++++++++
 .../internal/tracepoints/v4l2_enums.tp        | 16 ++++
 src/libcamera/v4l2_videodevice.cpp            |  9 +++
 4 files changed, 104 insertions(+)
 create mode 100644 include/libcamera/internal/tracepoints/v4l2.tp
 create mode 100644 include/libcamera/internal/tracepoints/v4l2_enums.tp

Patch
diff mbox series

diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build
index d9b2fca5..83f1144b 100644
--- a/include/libcamera/internal/tracepoints/meson.build
+++ b/include/libcamera/internal/tracepoints/meson.build
@@ -4,9 +4,11 @@ 
 tracepoint_files = files([
     'buffer_enums.tp',
     'request_enums.tp',
+    'v4l2_enums.tp',
 ])
 
 tracepoint_files += files([
     'pipeline.tp',
     'request.tp',
+    'v4l2.tp',
 ])
diff --git a/include/libcamera/internal/tracepoints/v4l2.tp b/include/libcamera/internal/tracepoints/v4l2.tp
new file mode 100644
index 00000000..f80eeb30
--- /dev/null
+++ b/include/libcamera/internal/tracepoints/v4l2.tp
@@ -0,0 +1,77 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>
+ *
+ * v4l2.tp - Tracepoints for V4L2 devices
+ */
+
+#include <libcamera/framebuffer.h>
+#include <libcamera/request.h>
+
+#include "libcamera/internal/v4l2_device.h"
+#include "libcamera/internal/v4l2_videodevice.h"
+
+TRACEPOINT_EVENT_CLASS(
+	libcamera,
+	v4l2_with_buffer,
+	TP_ARGS(
+		libcamera::V4L2VideoDevice *, vdev,
+		libcamera::FrameBuffer *, buf
+	),
+	TP_FIELDS(
+		ctf_string(devnode, vdev->deviceNode().c_str())
+		ctf_integer_hex(uintptr_t, buffer, reinterpret_cast<uintptr_t>(buf))
+		ctf_enum(libcamera, buffer_status, uint32_t, buf_status, buf->metadata().status)
+	)
+)
+
+TRACEPOINT_EVENT(
+	libcamera,
+	v4l2_videodev_streamoff,
+	TP_ARGS(
+		libcamera::V4L2VideoDevice *, vdev,
+		uint32_t, stream_state,
+		uint32_t, queued_buffers_size
+	),
+	TP_FIELDS(
+		ctf_string(devnode, vdev->deviceNode().c_str())
+		ctf_enum(libcamera, v4l2_streaming_state, uint32_t, state, stream_state)
+		ctf_integer(uint32_t, queued_buffers, queued_buffers_size)
+	)
+)
+
+TRACEPOINT_EVENT(
+	libcamera,
+	v4l2_videodev_send_back_buffer,
+	TP_ARGS(
+		libcamera::V4L2VideoDevice *, vdev,
+		libcamera::FrameBuffer *, buf,
+		libcamera::Request *, req
+	),
+	TP_FIELDS(
+		ctf_string(devnode, vdev->deviceNode().c_str())
+		ctf_integer_hex(uintptr_t, buffer, reinterpret_cast<uintptr_t>(buf))
+		ctf_enum(libcamera, buffer_status, uint32_t, buf_status, buf->metadata().status)
+		ctf_integer_hex(uintptr_t, request, reinterpret_cast<uintptr_t>(req))
+	)
+)
+
+TRACEPOINT_EVENT_INSTANCE(
+	libcamera,
+	v4l2_with_buffer,
+	v4l2_videodev_add_buffer_to_queue,
+	TP_ARGS(
+		libcamera::V4L2VideoDevice *, vdev,
+		libcamera::FrameBuffer *, buf
+	)
+)
+
+TRACEPOINT_EVENT_INSTANCE(
+	libcamera,
+	v4l2_with_buffer,
+	v4l2_videodev_remove_buffer_from_queue,
+	TP_ARGS(
+		libcamera::V4L2VideoDevice *, vdev,
+		libcamera::FrameBuffer *, buf
+	)
+)
diff --git a/include/libcamera/internal/tracepoints/v4l2_enums.tp b/include/libcamera/internal/tracepoints/v4l2_enums.tp
new file mode 100644
index 00000000..38506e17
--- /dev/null
+++ b/include/libcamera/internal/tracepoints/v4l2_enums.tp
@@ -0,0 +1,16 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>
+ *
+ * v4l2_enums.tp - Tracepoint definition for enums in V4L2
+ */
+
+TRACEPOINT_ENUM(
+	libcamera,
+	v4l2_streaming_state,
+	TP_ENUM_VALUES(
+		ctf_enum_value("Streaming", 0)
+		ctf_enum_value("Stopping", 1)
+		ctf_enum_value("Stopped", 2)
+	)
+)
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 1051997e..b134b0d4 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -31,6 +31,7 @@ 
 #include "libcamera/internal/framebuffer.h"
 #include "libcamera/internal/media_device.h"
 #include "libcamera/internal/media_object.h"
+#include "libcamera/internal/tracepoints.h"
 
 /**
  * \file v4l2_videodevice.h
@@ -1706,6 +1707,7 @@  int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
 			watchdog_.start(std::chrono::duration_cast<std::chrono::milliseconds>(watchdogDuration_));
 	}
 
+	LIBCAMERA_TRACEPOINT(v4l2_videodev_add_buffer_to_queue, this, buffer);
 	queuedBuffers_[buf.index] = buffer;
 
 	return 0;
@@ -1786,6 +1788,7 @@  FrameBuffer *V4L2VideoDevice::dequeueBuffer()
 	cache_->put(buf.index);
 
 	FrameBuffer *buffer = it->second;
+	LIBCAMERA_TRACEPOINT(v4l2_videodev_remove_buffer_from_queue, this, buffer);
 	queuedBuffers_.erase(it);
 
 	if (queuedBuffers_.empty()) {
@@ -1930,6 +1933,9 @@  int V4L2VideoDevice::streamOn()
  */
 int V4L2VideoDevice::streamOff()
 {
+	LIBCAMERA_TRACEPOINT(v4l2_videodev_streamoff, this,
+			     static_cast<uint32_t>(state_), queuedBuffers_.size());
+
 	int ret;
 
 	if (state_ != State::Streaming && queuedBuffers_.empty())
@@ -1954,6 +1960,9 @@  int V4L2VideoDevice::streamOff()
 
 		cache_->put(it.first);
 		metadata.status = FrameMetadata::FrameCancelled;
+
+		LIBCAMERA_TRACEPOINT(v4l2_videodev_send_back_buffer, this, buffer, buffer->request());
+
 		bufferReady.emit(buffer);
 	}