From patchwork Wed Jun 15 14:20:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16221 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3925DC3273 for ; Wed, 15 Jun 2022 14:21:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B19A965631; Wed, 15 Jun 2022 16:21:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655302866; bh=nMAc1j8FJs0JjYhAp4E87/F6jWd21tyVB9y7m1p01eI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wGjUIuxx/BBPklqPl68Hh0Y0hL0KgoENaAVR3B9W/YkZqnyGlIs2hFC0Nv4eeM5QQ qcb18ABveV9nyMZ4pwAnUBbXWzmonqC/RbAucILkkhPCH+pRAHH594Lv4Prb/7gLZj GklXZKeGRdY7V18VkomXwwcOmcHTl2LbhZpNa8RFaB/LMKOmO4XcJXP9xRvBO0Q/IM T/5I/85crIue1hf3yPe06d0BH4rNmDfk3lDg5cr0tKoCfiDX40IYkTdsmmb0TDXIpk 1fZUzoAtldfulqnwcq4vTcdZVxlNBgB6ROixzeeW6/IrfS3yST9Yz6+2ZjOFyf5Vy5 zEYQWYfjUNctw== Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D2BD865633 for ; Wed, 15 Jun 2022 16:21:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PqVeCXxT"; dkim-atps=neutral Received: by mail-pf1-x42d.google.com with SMTP id y196so11587959pfb.6 for ; Wed, 15 Jun 2022 07:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9OLAcsVCzHt8jCzrhRnAiGvEAXSX5xpHVInwaeywD3g=; b=PqVeCXxTB8I8JaICnVAMIq/QYsR5r3vViC2KNLID/M2u4QTu+EmeDqdymRjTGko4Pk TLqmvNQLH6b1QuxtX1GrVqcC7NIxKZMh+L/vjJUIDlI93FBJYBhc69pxafCaO+uWUicA OrLl6qf55Qu8RPZ+9QC/97IUgVZNSJ5en+y90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9OLAcsVCzHt8jCzrhRnAiGvEAXSX5xpHVInwaeywD3g=; b=XJj3ugH5pTwHqsLTw0qXR9RaVHalHll8AtoIQFVgGg/KhH+07IVDRWDAKVLH9l2KqH kyJdkG4UxXFCrxZTsG7Mi3BntS8XPSOdC3xxYUDKl+W/0bIOWE/Bs0N8OSpXByt+FkO0 GWf0fnxBUiD6HnfesD6Z6qTb2B+8E8dbT8E0RMhsRT1atLRxKI65THWMDwLijH82UI9J QldnrHGCKoyHs0e61pmaFP5ihz2zjq/0PDmoYseoWAJKzrXw32C0XP5WbOsk/XqYDChd k543Ruo7L3jH1ZziNYcWq3+g9yzO33Rdx61oBy7xav2ZUvmUSe+akyAzSs5DNKLlEObd gFZQ== X-Gm-Message-State: AJIora9+h91jos+mZvNLu2hpN1JxCqaN5WWCnVgJIkO0b70VcKBEmGEd SbdUj+P81wbW23smvchTn8sJKwRPCX0rZw== X-Google-Smtp-Source: AGRyM1tzdYi0R8Os9kXFpNidb1tEqsCgmhSbux8S/FrZMbfoZV6dfAHSbd3qSPkpjeuwpMS9CKkxEg== X-Received: by 2002:a63:5703:0:b0:408:b2c3:8df9 with SMTP id l3-20020a635703000000b00408b2c38df9mr36067pgb.247.1655302861753; Wed, 15 Jun 2022 07:21:01 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (21.160.199.104.bc.googleusercontent.com. [104.199.160.21]) by smtp.gmail.com with ESMTPSA id g1-20020a17090adac100b001e67e01158fsm1840882pjx.30.2022.06.15.07.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 07:21:01 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Jun 2022 14:20:51 +0000 Message-Id: <20220615142051.450396-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615142051.450396-1-chenghaoyang@google.com> References: <20220615142051.450396-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/1] Use tracing with perfetto in ChromeOS X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As ChromeOS is using perfetto (project named as CrOSetto). When ChromeOS uses libcamera, it should use perfetto to collect traces instead of lttng. Signed-off-by: Harvey Yang --- include/libcamera/internal/tracepoints.h.in | 37 +++++++++-- .../internal/tracepoints/meson.build | 25 ++++--- .../internal/tracepoints/pipeline.perfetto | 10 +++ .../internal/tracepoints/request.perfetto | 30 +++++++++ meson.build | 1 + src/android/cros/camera3_hal.cpp | 5 ++ src/android/cros/meson.build | 1 + src/libcamera/meson.build | 18 ++++- src/libcamera/pipeline_perfetto.cpp | 22 +++++++ src/libcamera/request_perfetto.cpp | 65 +++++++++++++++++++ src/libcamera/tracepoints.cpp | 11 ++++ 11 files changed, 209 insertions(+), 16 deletions(-) create mode 100644 include/libcamera/internal/tracepoints/pipeline.perfetto create mode 100644 include/libcamera/internal/tracepoints/request.perfetto create mode 100644 src/libcamera/pipeline_perfetto.cpp create mode 100644 src/libcamera/request_perfetto.cpp diff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in index d0fc1365..d91fadd7 100644 --- a/include/libcamera/internal/tracepoints.h.in +++ b/include/libcamera/internal/tracepoints.h.in @@ -9,7 +9,24 @@ #ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ #define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ -#if HAVE_TRACING +#if HAVE_PERFETTO + +#include + +PERFETTO_DEFINE_CATEGORIES( + perfetto::Category("libcamera") + .SetDescription("Events from libcamera")); + +#define LIBCAMERA_TRACEPOINT(t_name, ...) \ +LIBCAMERA_TRACE_EVENT_##t_name(__VA_ARGS__) + +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \ +LIBCAMERA_TRACE_EVENT_ipa_call_begin(#pipe, #func) + +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \ +LIBCAMERA_TRACE_EVENT_ipa_call_end(#pipe, #func) + +#elif HAVE_TRACING /* !HAVE_PERFETTO */ #define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__) #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \ @@ -18,7 +35,7 @@ tracepoint(libcamera, ipa_call_begin, #pipe, #func) #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \ tracepoint(libcamera, ipa_call_end, #pipe, #func) -#else +#else /* HAVE_PERFETTO */ namespace { @@ -34,12 +51,15 @@ inline void unused([[maybe_unused]] Args&& ...args) #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) -#endif /* HAVE_TRACING */ +#endif /* HAVE_PERFETTO */ #endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */ +#if HAVE_PERFETTO + +#include -#if HAVE_TRACING +#elif HAVE_TRACING #undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER libcamera @@ -52,10 +72,15 @@ inline void unused([[maybe_unused]] Args&& ...args) #include -{{source}} #endif /* INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H */ #include -#endif /* HAVE_TRACING */ +#endif /* HAVE_PERFETTO */ + +#if HAVE_PERFETTO || HAVE_TRACING + +{{source}} + +#endif /* HAVE_PERFETTO || HAVE_TRACING */ diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build index d9b2fca5..ff5aece6 100644 --- a/include/libcamera/internal/tracepoints/meson.build +++ b/include/libcamera/internal/tracepoints/meson.build @@ -1,12 +1,19 @@ # SPDX-License-Identifier: CC0-1.0 -# enum files must go first -tracepoint_files = files([ - 'buffer_enums.tp', - 'request_enums.tp', -]) +if get_option('android').enabled() and get_option('android_platform') == 'cros' + tracepoint_files = files([ + 'pipeline.perfetto', + 'request.perfetto', + ]) +else + # enum files must go first + tracepoint_files = files([ + 'buffer_enums.tp', + 'request_enums.tp', + ]) -tracepoint_files += files([ - 'pipeline.tp', - 'request.tp', -]) + tracepoint_files += files([ + 'pipeline.tp', + 'request.tp', + ]) +endif diff --git a/include/libcamera/internal/tracepoints/pipeline.perfetto b/include/libcamera/internal/tracepoints/pipeline.perfetto new file mode 100644 index 00000000..5f45295e --- /dev/null +++ b/include/libcamera/internal/tracepoints/pipeline.perfetto @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * pipeline.tp - Tracepoints for pipelines + */ + +void LIBCAMERA_TRACE_EVENT_ipa_call_begin(const char *pipe, const char *func); + +void LIBCAMERA_TRACE_EVENT_ipa_call_end(const char *pipe, const char *func); diff --git a/include/libcamera/internal/tracepoints/request.perfetto b/include/libcamera/internal/tracepoints/request.perfetto new file mode 100644 index 00000000..fd6a42a4 --- /dev/null +++ b/include/libcamera/internal/tracepoints/request.perfetto @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * request.tp - Tracepoints for the request object + */ + +#include + +#include + +void LIBCAMERA_TRACE_EVENT_request(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_construct(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_destroy(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_reuse(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_queue(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_device_queue(libcamera::Request *req); + +void LIBCAMERA_TRACE_EVENT_request_complete(libcamera::Request::Private *req); + +void LIBCAMERA_TRACE_EVENT_request_cancel(libcamera::Request::Private *req); + +void LIBCAMERA_TRACE_EVENT_request_complete_buffer( + libcamera::Request::Private *req, + libcamera::FrameBuffer * buf); diff --git a/meson.build b/meson.build index 29d8542d..053bb831 100644 --- a/meson.build +++ b/meson.build @@ -176,6 +176,7 @@ py_mod.find_installation('python3', modules: py_modules) summary({ 'Enabled pipelines': pipelines, 'Enabled IPA modules': ipa_modules, + 'Perfetto support': perfetto_enabled, 'Tracing support': tracing_enabled, 'Android support': android_enabled, 'GStreamer support': gst_enabled, diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp index fb863b5f..2fbd7f14 100644 --- a/src/android/cros/camera3_hal.cpp +++ b/src/android/cros/camera3_hal.cpp @@ -7,10 +7,15 @@ #include +#include "libcamera/internal/tracepoints.h" #include "../camera_hal_manager.h" static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token) { + perfetto::TracingInitArgs args; + args.backends |= perfetto::kSystemBackend; + perfetto::Tracing::Initialize(args); + perfetto::TrackEvent::Register(); } static void tear_down() diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build index 35995dd8..68f2bd9e 100644 --- a/src/android/cros/meson.build +++ b/src/android/cros/meson.build @@ -9,5 +9,6 @@ android_hal_sources += files([ ]) android_deps += dependency('libcros_camera') +android_deps += dependency('perfetto') android_cpp_args += ['-DOS_CHROMEOS'] diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 26912ca1..3332cc05 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -71,11 +71,22 @@ if libgnutls.found() config_h.set('HAVE_GNUTLS', 1) endif -if liblttng.found() +if get_option('android').enabled() and get_option('android_platform') == 'cros' + perfetto_enabled = true + tracing_enabled = false + config_h.set('HAVE_PERFETTO', 1) + libcamera_sources += [ + 'pipeline_perfetto.cpp', + 'request_perfetto.cpp', + 'tracepoints.cpp', + ] +elif liblttng.found() + perfetto_enabled = false tracing_enabled = true config_h.set('HAVE_TRACING', 1) libcamera_sources += files(['tracepoints.cpp']) else + perfetto_enabled = false tracing_enabled = false endif @@ -128,6 +139,11 @@ libcamera_deps = [ libudev, ] +if perfetto_enabled + perfetto = dependency('perfetto', required : true) + libcamera_deps += [ perfetto ] +endif + # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag. # The build_rpath is stripped at install time by meson, so we determine at # runtime if the library is running from an installed location by checking diff --git a/src/libcamera/pipeline_perfetto.cpp b/src/libcamera/pipeline_perfetto.cpp new file mode 100644 index 00000000..d0ddc17d --- /dev/null +++ b/src/libcamera/pipeline_perfetto.cpp @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * pipeline.tp - Tracepoints for pipelines + */ + +#include "libcamera/internal/tracepoints.h" + +void LIBCAMERA_TRACE_EVENT_ipa_call_begin(const char *pipe, const char *func) { + // TODO: Consider TRACE_EVENT_BEGIN + TRACE_EVENT("libcamera", "ipa_call_begin", + "pipeline_name", pipe, + "function_name", func); +} + +void LIBCAMERA_TRACE_EVENT_ipa_call_end(const char *pipe, const char *func) { + // TODO: Consider TRACE_EVENT_END + TRACE_EVENT("libcamera", "ipa_call_end", + "pipeline_name", pipe, + "function_name", func); +} diff --git a/src/libcamera/request_perfetto.cpp b/src/libcamera/request_perfetto.cpp new file mode 100644 index 00000000..c82cce33 --- /dev/null +++ b/src/libcamera/request_perfetto.cpp @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * request.tp - Tracepoints for the request object + */ + + +#include + +#include "libcamera/internal/request.h" +#include "libcamera/internal/tracepoints.h" + +void LIBCAMERA_TRACE_EVENT_request(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request", + "request_ptr", reinterpret_cast(req), + "cookie", req->cookie(), + "status", req->status()); // TODO +} + +void LIBCAMERA_TRACE_EVENT_request_construct(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request_construct", + "request_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_destroy(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request_destroy", + "request_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_reuse(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request_reuse", + "request_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_queue(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request_queue", + "request_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_device_queue(libcamera::Request *req) { + TRACE_EVENT("libcamera", "request_device_queue", + "request_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_complete(libcamera::Request::Private *req) { + TRACE_EVENT("libcamera", "request_complete", + "request_private_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_cancel(libcamera::Request::Private *req) { + TRACE_EVENT("libcamera", "request_cancel", + "request_private_ptr", reinterpret_cast(req)); +} + +void LIBCAMERA_TRACE_EVENT_request_complete_buffer( + libcamera::Request::Private *req, + libcamera::FrameBuffer * buf) { + TRACE_EVENT("libcamera", "request_complete_buffer", + "request_private_ptr", reinterpret_cast(req), + "cookie", req->_o()->cookie(), + "status", req->_o()->status(), // TODO + "buffer_ptr", reinterpret_cast(buf), + "buffer_status", buf->metadata().status); // TODO +} diff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp index 0173b75a..a07ea531 100644 --- a/src/libcamera/tracepoints.cpp +++ b/src/libcamera/tracepoints.cpp @@ -4,7 +4,18 @@ * * tracepoints.cpp - Tracepoints with lttng */ + +#if HAVE_PERFETTO + +#include "libcamera/internal/tracepoints.h" + +PERFETTO_TRACK_EVENT_STATIC_STORAGE(); + +#else + #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE #include "libcamera/internal/tracepoints.h" + +#endif /* HAVE_PERFETTO */