{"id":16732,"url":"https://patchwork.libcamera.org/api/patches/16732/?format=json","web_url":"https://patchwork.libcamera.org/patch/16732/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220722120028.3155712-2-chenghaoyang@google.com>","date":"2022-07-22T12:00:28","name":"[libcamera-devel,v2,1/1] Use tracing with perfetto in ChromeOS","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2e98368ae0f4730d39540467a4fde9d9cd6df22e","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16732/mbox/","series":[{"id":3318,"url":"https://patchwork.libcamera.org/api/series/3318/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3318","date":"2022-07-22T12:00:27","name":"Use tracing with perfetto in ChromeOS","version":2,"mbox":"https://patchwork.libcamera.org/series/3318/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16732/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16732/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BEF9EBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Jul 2022 12:00:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7931A63315;\n\tFri, 22 Jul 2022 14:00:41 +0200 (CEST)","from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com\n\t[IPv6:2607:f8b0:4864:20::1034])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 892DB603F1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jul 2022 14:00:39 +0200 (CEST)","by mail-pj1-x1034.google.com with SMTP id\n\tl14-20020a17090a72ce00b001f20ed3c55dso4000009pjk.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jul 2022 05:00:39 -0700 (PDT)","from chenghaoyang-low.c.googlers.com.com\n\t(231.137.80.34.bc.googleusercontent.com. [34.80.137.231])\n\tby smtp.gmail.com with ESMTPSA id\n\th5-20020a170902b94500b001635b86a790sm3540021pls.44.2022.07.22.05.00.34\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 22 Jul 2022 05:00:35 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658491241;\n\tbh=2Ej73/dT6LPkfSAuLOV+JxQ31++4UyJHVuB4FsiylrI=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Xxp5mP0KwCKhmnRy+/7u0eKXoi78fLzKvBqIPRRGKN8HF+l0bIWADXdwRMYStXfVf\n\tBJl2D5+ppw/aLsePl/zug/ntaS+T9U2S3aRr+i5gqrheysgYJTVZflQg4mR0z6qO14\n\tTIUCecu/hNuc8O487by2SILDTRGdfGjPpVmQZJ13enpeFrjWJnfhSFY18QlRhSHdDF\n\tKxieBvfMWnnYZPDoYwb25MlNMZJltDkuY0AMEZDeiaCCpvBr819/MKw9iVlirQ0zin\n\tLP1ePaZhNYq0QvRFok/rxtuShoOrTxZgRwtnGDVE4E0/NfjhQ6QkeusSxQcWLZe0OR\n\te1+m8ZlW9KYrg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=FIeV4dbJgTTzu68wRJaprtK/rnlb5YahEtIowiacYJk=;\n\tb=d2djKaKGyXmzZ4PupDqFon7QNJmkuwBMEB2gTI4lQJREBZNuklYigPon3KaaRwPwhC\n\tMZ7ansIP+gDEHP8XW76dQAVOuGRTiPbATikzr0n3G92CvrcgJpDIh6rBT2pbG4ZW+XXN\n\tGUZjHfpLddOWP/TcxXZrAnWoKS9D0NvE9O29U="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"d2djKaKG\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=FIeV4dbJgTTzu68wRJaprtK/rnlb5YahEtIowiacYJk=;\n\tb=NML8pj7ql/m2hqzAM7OqY3ihLQu6Zw1Yn++lsz2M1352ELGJk+Mf4E5Dy3ENPRS5iX\n\tzAS8eeK4bYfFEWwaZ4WDxPhQkQ/IcUgZMS4vtS0vuCIXJyNoeKfzOUiLLbc+7WfNfjqs\n\tbD1rijkvOoIIrFKsMxF5YZkpVZpso1bYlscirzNz8qLeK7j2K8izb+IE7ilyLNC045rK\n\tz/RRNmO8rnI5dr1US1arRLgIqlHFqFMBjlza6oAwuReuJKK76FmjG6mXJbgAgurDGdhL\n\tewfeyYG5BL5+bIk5dHN4Enq8poQnLzM+WQ58Mtj175UyZRJEYAfJ8CkYPbC5qWphIn/X\n\ttTVg==","X-Gm-Message-State":"AJIora91toWuVkjOZlHCOq0iF1HYFlyRFRxlXyPX/4izMd6Gcgl4/2X/\n\t9HsKJgiNa6ENG0WqQyHHvVW0V7mJkE6lAQ==","X-Google-Smtp-Source":"AGRyM1tvYWCM4S9id4hR+nR73FG0fgoVEbZfZAu5aqux9ZE5iHDdNxlaPhnE8yOu9aXUIJHtc4e9lw==","X-Received":"by 2002:a17:902:e5c4:b0:16c:3af6:149e with SMTP id\n\tu4-20020a170902e5c400b0016c3af6149emr3166946plf.69.1658491236309; \n\tFri, 22 Jul 2022 05:00:36 -0700 (PDT)","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 22 Jul 2022 12:00:28 +0000","Message-Id":"<20220722120028.3155712-2-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.37.1.359.gd136c6c3e2-goog","In-Reply-To":"<20220722120028.3155712-1-chenghaoyang@google.com>","References":"<20220722120028.3155712-1-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/1] Use tracing with perfetto in\n\tChromeOS","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Harvey Yang via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Harvey Yang <chenghaoyang@chromium.org>","Cc":"Harvey Yang <chenghaoyang@google.com>,\n\tHarvey Yang <chenghaoyang@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"As ChromeOS is using perfetto (project named as CrOSetto). When ChromeOS\nuses libcamera, it should use perfetto to collect traces instead of\nlttng.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n Documentation/guides/tracing.rst              | 114 ++++++++++++++----\n include/libcamera/internal/tracepoints.h.in   |  37 +++++-\n .../internal/tracepoints/meson.build          |  25 ++--\n .../internal/tracepoints/pipeline.perfetto    |  10 ++\n .../internal/tracepoints/request.perfetto     |  30 +++++\n meson.build                                   |   7 +-\n src/android/cros/camera3_hal.cpp              |   5 +\n src/android/cros/meson.build                  |   1 +\n src/libcamera/meson.build                     |  14 ++-\n src/libcamera/pipeline_perfetto.cpp           |  24 ++++\n src/libcamera/request_perfetto.cpp            |  73 +++++++++++\n src/libcamera/tracepoints.cpp                 |  11 ++\n 12 files changed, 312 insertions(+), 39 deletions(-)\n create mode 100644 include/libcamera/internal/tracepoints/pipeline.perfetto\n create mode 100644 include/libcamera/internal/tracepoints/request.perfetto\n create mode 100644 src/libcamera/pipeline_perfetto.cpp\n create mode 100644 src/libcamera/request_perfetto.cpp","diff":"diff --git a/Documentation/guides/tracing.rst b/Documentation/guides/tracing.rst\nindex ae960d85..53d6232e 100644\n--- a/Documentation/guides/tracing.rst\n+++ b/Documentation/guides/tracing.rst\n@@ -16,33 +16,50 @@ at periodic points in time. This can be done with other tools such as\n callgrind, perf, gprof, etc., without modification to the application,\n and is out of scope for this guide.\n \n+Library: Perfetto vs lttng-ust\n+---------\n+\n+To integrate with CrOS tracing infrastructure, which uses perfetto (or called\n+CrOSetto in CrOS), we implement the tracepoint macros (will be described below)\n+with two different libraries: CrOS with perfetto, and the rest with lttng-ust.\n+\n Compiling\n ---------\n \n-To compile libcamera with tracing support, it must be enabled through the\n-meson ``tracing`` option. It depends on the lttng-ust library (available in the\n-``liblttng-ust-dev`` package for Debian-based distributions).\n-By default the tracing option in meson is set to ``auto``, so if\n-liblttng is detected, it will be enabled by default. Conversely, if the option\n-is set to disabled, then libcamera will be compiled without tracing support.\n+To compile libcamera with perfetto support in CrOS, it must be enabled through\n+the meson ``tracing`` option. In CrOS, it depends on the perfetto library,\n+which is by default available in CrOS; In the rest, it depends on the lttng-ust\n+library (available in the ``liblttng-ust-dev`` package for Debian-based\n+distributions).\n+By default the tracing option in meson is set to ``auto``, so if the library is\n+detected, it will be enabled by default. Conversely, if the option is set to\n+disabled, then libcamera will be compiled without tracing support.\n \n Defining tracepoints\n --------------------\n \n libcamera already contains a set of tracepoints. To define additional\n-tracepoints, create a file\n-``include/libcamera/internal/tracepoints/{file}.tp``, where ``file`` is a\n-reasonable name related to the category of tracepoints that you wish to\n-define. For example, the tracepoints file for the Request object is called\n-``request.tp``. An entry for this file must be added in\n-``include/libcamera/internal/tracepoints/meson.build``.\n-\n-In this tracepoints file, define your tracepoints `as mandated by lttng\n+tracepoints, create two files ``{file}.tp`` and ``{file}.perfetto``, for lttng\n+and perfetto respectively, under ``include/libcamera/internal/tracepoints/``,\n+and the perfetto implementation file ``src/libcamera/{file}_perfetto.cpp``,\n+where ``file`` is a reasonable name related to the category of tracepoints that\n+you wish to define. For example, the tracepoints files for the Request object is\n+called ``request.tp`` and ``request.perfetto``. Entries for the files must be\n+added in ``include/libcamera/internal/tracepoints/meson.build``.\n+\n+In the perfetto tracepoints files, declare the tracepoint functions in\n+``{file}.perfetto``, and define them in ``{file}_perfetto.cpp``, `as mandated\n+by perfetto <https://perfetto.dev/docs/instrumentation/track-events>`_.\n+Currently the only enabled perfetto::Category is ``libcamera``. If you intend to\n+use another category, remember to define it in\n+``include/libcamera/internal/tracepoints.h.in``, and enable it when collecting\n+traces.\n+\n+In the lttng tracepoints file, define your tracepoints `as mandated by lttng\n <https://lttng.org/man/3/lttng-ust>`_. The header boilerplate must *not* be\n included (as it will conflict with the rest of our infrastructure), and\n only the tracepoint definitions (with the ``TRACEPOINT_*`` macros) should be\n included.\n-\n All tracepoint providers shall be ``libcamera``. According to lttng, the\n tracepoint provider should be per-project; this is the rationale for this\n decision. To group tracepoint events, we recommend using\n@@ -68,9 +85,9 @@ Then to use the tracepoint:\n \n ``LIBCAMERA_TRACEPOINT({tracepoint_event}, args...)``\n \n-This macro must be used, as opposed to lttng's macros directly, because\n-lttng is an optional dependency of libcamera, so the code must compile and run\n-even when lttng is not present or when tracing is disabled.\n+This macro must be used, as opposed to perfetto's/lttng's macros directly,\n+because tracing support is optional of libcamera, so the code must compile and\n+run even when perfetto/lttng is not present or when tracing is disabled.\n \n The tracepoint provider name, as declared in the tracepoint definition, is not\n included in the parameters of the tracepoint.\n@@ -86,7 +103,7 @@ and when the pipeline handler receives the corresponding response from the IPA,\n respectively. These are the tracepoints that our sample analysis script\n (see \"Analyzing a trace\") scans for when computing statistics on IPA call time.\n \n-Using tracepoints (from an application)\n+Using lttng tracepoints (from an application)\n ---------------------------------------\n \n As applications are not part of libcamera, but rather users of libcamera,\n@@ -94,13 +111,66 @@ applications should seek their own tracing mechanisms. For ease of tracing\n the application alongside tracing libcamera, it is recommended to also\n `use lttng <https://lttng.org/docs/#doc-tracing-your-own-user-application>`_.\n \n-Using tracepoints (from closed-source IPA)\n+Using lttng tracepoints (from closed-source IPA)\n ------------------------------------------\n \n Similar to applications, closed-source IPAs can simply use lttng on their own,\n or any other tracing mechanism if desired.\n \n-Collecting a trace\n+Collecting a perfetto trace\n+------------------\n+\n+A trace can be collected with the following steps:\n+\n+1. Start `traced` if it hasn't been started.\n+.. code-block:: bash\n+\n+   start traced\n+\n+2. Start a consumer that includes “track_event” data source in the trace\n+   config, and “libcamera” category.\n+.. code-block:: bash\n+\n+   perfetto -c - --txt -o /tmp/perfetto-trace \\\n+   <<EOF\n+\n+   buffers: {\n+       size_kb: 63488\n+       fill_policy: DISCARD\n+   }\n+   buffers: {\n+       size_kb: 2048\n+       fill_policy: DISCARD\n+   }\n+   data_sources: {\n+        config {\n+            name: \"track_event\"\n+            track_event_config {\n+                enabled_categories: \"libcamera\"\n+            }\n+        }\n+   }\n+   duration_ms: 10000\n+\n+   EOF\n+\n+3. Execute the libcamera behavior you intend to trace during the set duration\n+   (10000 ms) in the above example.\n+\n+4. After the consumer (cmd `perfetto`) is done, you can find the trace result\n+   in ``/tmp/perfetto-trace``.\n+\n+Analyzing a perfetto trace\n+-----------------\n+\n+Follow the `guide <https://perfetto.dev/docs/visualization/perfetto-ui>`_ to\n+visualize the trace.\n+\n+In other words, upload the trace to `Perfetto UI <https://ui.perfetto.dev/>`_,\n+where you can check the timeline of tracepoints on each process/thread. You can\n+also run SQL queries to do analysis.\n+\n+Collecting a lttng trace\n ------------------\n \n A trace can be collected fairly simply from lttng:\n@@ -123,7 +193,7 @@ viewed by: ``lttng view -t $PATH_TO_TRACE``, where ``$PATH_TO_TRACE`` is the\n path that was printed when the session was created. This is the same path that\n is used when analyzing traces programatically, as described in the next section.\n \n-Analyzing a trace\n+Analyzing a lttng trace\n -----------------\n \n As mentioned above, while an lttng tracing session exists and the trace is not\ndiff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in\nindex d0fc1365..d91fadd7 100644\n--- a/include/libcamera/internal/tracepoints.h.in\n+++ b/include/libcamera/internal/tracepoints.h.in\n@@ -9,7 +9,24 @@\n #ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n #define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n \n-#if HAVE_TRACING\n+#if HAVE_PERFETTO\n+\n+#include <perfetto/perfetto.h>\n+\n+PERFETTO_DEFINE_CATEGORIES(\n+\tperfetto::Category(\"libcamera\")\n+\t\t.SetDescription(\"Events from libcamera\"));\n+\n+#define LIBCAMERA_TRACEPOINT(t_name, ...) \\\n+LIBCAMERA_TRACE_EVENT_##t_name(__VA_ARGS__)\n+\n+#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n+LIBCAMERA_TRACE_EVENT_ipa_call_begin(#pipe, #func)\n+\n+#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n+LIBCAMERA_TRACE_EVENT_ipa_call_end(#pipe, #func)\n+\n+#elif HAVE_TRACING /* !HAVE_PERFETTO */\n #define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)\n \n #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n@@ -18,7 +35,7 @@ tracepoint(libcamera, ipa_call_begin, #pipe, #func)\n #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n tracepoint(libcamera, ipa_call_end, #pipe, #func)\n \n-#else\n+#else /* HAVE_PERFETTO */\n \n namespace {\n \n@@ -34,12 +51,15 @@ inline void unused([[maybe_unused]] Args&& ...args)\n #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)\n #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)\n \n-#endif /* HAVE_TRACING */\n+#endif /* HAVE_PERFETTO */\n \n #endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */\n \n+#if HAVE_PERFETTO\n+\n+#include <perfetto/perfetto.h>\n \n-#if HAVE_TRACING\n+#elif HAVE_TRACING\n \n #undef TRACEPOINT_PROVIDER\n #define TRACEPOINT_PROVIDER libcamera\n@@ -52,10 +72,15 @@ inline void unused([[maybe_unused]] Args&& ...args)\n \n #include <lttng/tracepoint.h>\n \n-{{source}}\n \n #endif /* INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H */\n \n #include <lttng/tracepoint-event.h>\n \n-#endif /* HAVE_TRACING */\n+#endif /* HAVE_PERFETTO */\n+\n+#if HAVE_PERFETTO || HAVE_TRACING\n+\n+{{source}}\n+\n+#endif /* HAVE_PERFETTO || HAVE_TRACING */\ndiff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build\nindex d9b2fca5..ff5aece6 100644\n--- a/include/libcamera/internal/tracepoints/meson.build\n+++ b/include/libcamera/internal/tracepoints/meson.build\n@@ -1,12 +1,19 @@\n # SPDX-License-Identifier: CC0-1.0\n \n-# enum files must go first\n-tracepoint_files = files([\n-    'buffer_enums.tp',\n-    'request_enums.tp',\n-])\n+if get_option('android').enabled() and get_option('android_platform') == 'cros'\n+  tracepoint_files = files([\n+      'pipeline.perfetto',\n+      'request.perfetto',\n+  ])\n+else\n+  # enum files must go first\n+  tracepoint_files = files([\n+      'buffer_enums.tp',\n+      'request_enums.tp',\n+  ])\n \n-tracepoint_files += files([\n-    'pipeline.tp',\n-    'request.tp',\n-])\n+  tracepoint_files += files([\n+      'pipeline.tp',\n+      'request.tp',\n+  ])\n+endif\ndiff --git a/include/libcamera/internal/tracepoints/pipeline.perfetto b/include/libcamera/internal/tracepoints/pipeline.perfetto\nnew file mode 100644\nindex 00000000..5f45295e\n--- /dev/null\n+++ b/include/libcamera/internal/tracepoints/pipeline.perfetto\n@@ -0,0 +1,10 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * pipeline.tp - Tracepoints for pipelines\n+ */\n+\n+void LIBCAMERA_TRACE_EVENT_ipa_call_begin(const char *pipe, const char *func);\n+\n+void LIBCAMERA_TRACE_EVENT_ipa_call_end(const char *pipe, const char *func);\ndiff --git a/include/libcamera/internal/tracepoints/request.perfetto b/include/libcamera/internal/tracepoints/request.perfetto\nnew file mode 100644\nindex 00000000..fd6a42a4\n--- /dev/null\n+++ b/include/libcamera/internal/tracepoints/request.perfetto\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * request.tp - Tracepoints for the request object\n+ */\n+\n+#include <libcamera/internal/request.h>\n+\n+#include <libcamera/framebuffer.h>\n+\n+void LIBCAMERA_TRACE_EVENT_request(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_construct(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_destroy(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_reuse(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_queue(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_device_queue(libcamera::Request *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_complete(libcamera::Request::Private *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_cancel(libcamera::Request::Private *req);\n+\n+void LIBCAMERA_TRACE_EVENT_request_complete_buffer(\n+\t\tlibcamera::Request::Private *req,\n+\t\tlibcamera::FrameBuffer * buf);\ndiff --git a/meson.build b/meson.build\nindex 29d8542d..434540e1 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -125,7 +125,11 @@ libcamera_includes = include_directories('include')\n py_modules = []\n \n # Libraries used by multiple components\n-liblttng = cc.find_library('lttng-ust', required : get_option('tracing'))\n+libperfetto = dependency('perfetto', required : get_option('tracing').enabled()\n+    and get_option('android').enabled()\n+    and get_option('android_platform') == 'cros')\n+liblttng = cc.find_library('lttng-ust', required : get_option('tracing').enabled()\n+    and not libperfetto.found())\n \n # Pipeline handlers\n #\n@@ -176,6 +180,7 @@ py_mod.find_installation('python3', modules: py_modules)\n summary({\n             'Enabled pipelines': pipelines,\n             'Enabled IPA modules': ipa_modules,\n+            'Perfetto support': perfetto_enabled,\n             'Tracing support': tracing_enabled,\n             'Android support': android_enabled,\n             'GStreamer support': gst_enabled,\ndiff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp\nindex fb863b5f..2fbd7f14 100644\n--- a/src/android/cros/camera3_hal.cpp\n+++ b/src/android/cros/camera3_hal.cpp\n@@ -7,10 +7,15 @@\n \n #include <cros-camera/cros_camera_hal.h>\n \n+#include \"libcamera/internal/tracepoints.h\"\n #include \"../camera_hal_manager.h\"\n \n static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token)\n {\n+\tperfetto::TracingInitArgs args;\n+\targs.backends |= perfetto::kSystemBackend;\n+\tperfetto::Tracing::Initialize(args);\n+\tperfetto::TrackEvent::Register();\n }\n \n static void tear_down()\ndiff --git a/src/android/cros/meson.build b/src/android/cros/meson.build\nindex 35995dd8..68f2bd9e 100644\n--- a/src/android/cros/meson.build\n+++ b/src/android/cros/meson.build\n@@ -9,5 +9,6 @@ android_hal_sources += files([\n ])\n \n android_deps += dependency('libcros_camera')\n+android_deps += dependency('perfetto')\n \n android_cpp_args += ['-DOS_CHROMEOS']\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 26912ca1..39a55a17 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -71,11 +71,22 @@ if libgnutls.found()\n     config_h.set('HAVE_GNUTLS', 1)\n endif\n \n-if liblttng.found()\n+if libperfetto.found()\n+    perfetto_enabled = true\n+    tracing_enabled = false\n+    config_h.set('HAVE_PERFETTO', 1)\n+    libcamera_sources += [\n+        'pipeline_perfetto.cpp',\n+        'request_perfetto.cpp',\n+        'tracepoints.cpp',\n+    ]\n+elif liblttng.found()\n+    perfetto_enabled = false\n     tracing_enabled = true\n     config_h.set('HAVE_TRACING', 1)\n     libcamera_sources += files(['tracepoints.cpp'])\n else\n+    perfetto_enabled = false\n     tracing_enabled = false\n endif\n \n@@ -125,6 +136,7 @@ libcamera_deps = [\n     libdl,\n     libgnutls,\n     liblttng,\n+    libperfetto,\n     libudev,\n ]\n \ndiff --git a/src/libcamera/pipeline_perfetto.cpp b/src/libcamera/pipeline_perfetto.cpp\nnew file mode 100644\nindex 00000000..07b82ffd\n--- /dev/null\n+++ b/src/libcamera/pipeline_perfetto.cpp\n@@ -0,0 +1,24 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * pipeline.tp - Tracepoints for pipelines\n+ */\n+\n+#include \"libcamera/internal/tracepoints.h\"\n+\n+void LIBCAMERA_TRACE_EVENT_ipa_call_begin(const char *pipe, const char *func)\n+{\n+\t// TODO: Consider TRACE_EVENT_BEGIN\n+\tTRACE_EVENT(\"libcamera\", \"ipa_call_begin\",\n+\t\t    \"pipeline_name\", pipe,\n+\t\t    \"function_name\", func);\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_ipa_call_end(const char *pipe, const char *func)\n+{\n+\t// TODO: Consider TRACE_EVENT_END\n+\tTRACE_EVENT(\"libcamera\", \"ipa_call_end\",\n+\t\t    \"pipeline_name\", pipe,\n+\t\t    \"function_name\", func);\n+}\ndiff --git a/src/libcamera/request_perfetto.cpp b/src/libcamera/request_perfetto.cpp\nnew file mode 100644\nindex 00000000..2cfff28e\n--- /dev/null\n+++ b/src/libcamera/request_perfetto.cpp\n@@ -0,0 +1,73 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * request.tp - Tracepoints for the request object\n+ */\n+\n+#include <libcamera/framebuffer.h>\n+\n+#include \"libcamera/internal/request.h\"\n+#include \"libcamera/internal/tracepoints.h\"\n+\n+void LIBCAMERA_TRACE_EVENT_request(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req),\n+\t\t    \"cookie\", req->cookie(),\n+\t\t    \"status\", req->status()); // TODO\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_construct(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_construct\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_destroy(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_destroy\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_reuse(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_reuse\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_queue(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_queue\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_device_queue(libcamera::Request *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_device_queue\",\n+\t\t    \"request_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_complete(libcamera::Request::Private *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_complete\",\n+\t\t    \"request_private_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_cancel(libcamera::Request::Private *req)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_cancel\",\n+\t\t    \"request_private_ptr\", reinterpret_cast<uintptr_t>(req));\n+}\n+\n+void LIBCAMERA_TRACE_EVENT_request_complete_buffer(\n+\tlibcamera::Request::Private *req,\n+\tlibcamera::FrameBuffer *buf)\n+{\n+\tTRACE_EVENT(\"libcamera\", \"request_complete_buffer\",\n+\t\t    \"request_private_ptr\", reinterpret_cast<uintptr_t>(req),\n+\t\t    \"cookie\", req->_o<libcamera::Request>()->cookie(),\n+\t\t    \"status\", req->_o<libcamera::Request>()->status(), // TODO\n+\t\t    \"buffer_ptr\", reinterpret_cast<uintptr_t>(buf),\n+\t\t    \"buffer_status\", buf->metadata().status); // TODO\n+}\ndiff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp\nindex 0173b75a..a07ea531 100644\n--- a/src/libcamera/tracepoints.cpp\n+++ b/src/libcamera/tracepoints.cpp\n@@ -4,7 +4,18 @@\n  *\n  * tracepoints.cpp - Tracepoints with lttng\n  */\n+\n+#if HAVE_PERFETTO\n+\n+#include \"libcamera/internal/tracepoints.h\"\n+\n+PERFETTO_TRACK_EVENT_STATIC_STORAGE();\n+\n+#else\n+\n #define TRACEPOINT_CREATE_PROBES\n #define TRACEPOINT_DEFINE\n \n #include \"libcamera/internal/tracepoints.h\"\n+\n+#endif /* HAVE_PERFETTO */\n","prefixes":["libcamera-devel","v2","1/1"]}