From patchwork Thu Sep 12 23:32:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 21248 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 51011C324C for ; Thu, 12 Sep 2024 23:33:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D4F11634FC; Fri, 13 Sep 2024 01:33:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GFasKlng"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE342618F2 for ; Fri, 13 Sep 2024 01:32:59 +0200 (CEST) Received: from pyrite.hamster-moth.ts.net (213-229-8-243.static.upcbusiness.at [213.229.8.243]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 42CF21011; Fri, 13 Sep 2024 01:31:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1726183901; bh=2hSHW4Ma7jDK8OnGJie8+NFcjwSQj3g2g4EuCd8g3T0=; h=From:To:Cc:Subject:Date:From; b=GFasKlngIi3WjlgDQYCeLn4L0ki8F1TDwEe0Dn+19F9Nxb0dwsvFWSgCZLpdiP3H+ k6XuTDUSbfhS5PSEU/Om4W+8g6IQnmirqKyj3hBJ0TXNHdUJ3JGameBZfm3EB2Q4Ko lbSSC/3OsyAgXsvcdQITypgczEHm9OusG2qgVhsM= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH] guides: tracing: Elaborate on function tracing and tracecompass Date: Fri, 13 Sep 2024 01:32:40 +0200 Message-Id: <20240912233240.3306148-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Expand the tracing guide to explain how to set up function tracing, and a simple starter on how to get tracecompass to open the trace. Signed-off-by: Paul Elder --- This patch depends on "meson: Add -finstrument-functions to debug builds" --- Documentation/guides/tracing.rst | 100 +++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/Documentation/guides/tracing.rst b/Documentation/guides/tracing.rst index 537dce500..4b05cd5db 100644 --- a/Documentation/guides/tracing.rst +++ b/Documentation/guides/tracing.rst @@ -105,19 +105,65 @@ or any other tracing mechanism if desired. Collecting a trace ------------------ -A trace can be collected fairly simply from lttng: +To collect a trace from lttng, we first start by creating a session: -.. code-block:: bash +``lttng create $SESSION_NAME`` - lttng create $SESSION_NAME - lttng enable-event -u libcamera:\* - lttng start - # run libcamera application - lttng stop - lttng view - lttng destroy $SESSION_NAME +Next we enable events that we want to listen to. To enable the libcamera +events: -See the `lttng documentation `_ for further details. +``lttng enable-event -u libcamera:\*`` + +We can also enable the events for +`function tracing `_: + +``lttng enable-event -u lttng_ust_cyg_profile:\*`` + +Or for the fast version: + +``lttng enable-event -u lttng_ust_cyg_profile_fast:\*`` + +Note that function tracing requires libcamera to be built in either the +``debug`` or ``debugoptimized`` build types (which can be specified in +``meson`` with the ``--buildtype`` option). + +Lastly, we can +`add context fields `_ +that allow the flame graph to work in tracecompass: + +``lttng add-context -u -t vpid -t vtid -t procname`` + +Now we can start lttng: + +``lttng start`` + +And run the libcamera application. For example: + +``cam -c 1 --capture=10`` + +We also have the option to LD_PRELOAD the function tracer: + +``LD_PRELOAD=/usr/lib/liblttng-ust-cyg-profile.so cam -c 1 --capture=10`` + +For for the fast function tracer: + +``LD_PRELOAD=/usr/lib/liblttng-ust-cyg-profile-fast.so cam -c 1 --capture=10`` + +After running the application, we probably want to stop the tracing capture: + +``lttng stop`` + +Optionally we can view the trace in text form: + +``lttng view`` + +And finally we can destroy the session: + +``lttng destroy $SESSION_NAME`` + +Tracing capture can be restarted without destruction, but it will end up in the +same log. The session can also be saved by ``lttng save`` before destruction, +and then loaded again by ``lttng load $SESSION_NAME``. The location of the trace file is printed when running ``lttng create $SESSION_NAME``. After destroying the session, it can still be @@ -125,6 +171,8 @@ viewed by: ``lttng view -t $PATH_TO_TRACE``, where ``$PATH_TO_TRACE`` is the path that was printed when the session was created. This is the same path that is used when analyzing traces programatically, as described in the next section. +See the `lttng documentation `_ for further details. + Analyzing a trace ----------------- @@ -147,3 +195,35 @@ As an example, there is a script ``utils/tracepoints/analyze-ipa-trace.py`` that gathers statistics for the time taken for an IPA function call, by measuring the time difference between pairs of events ``libcamera:ipa_call_start`` and ``libcamera:ipa_call_finish``. + +Tracecompass +------------ + +`Tracecompass `_ +is an easy way to visualize and explore traces without having to first write a +script with babeltrace. + +To open the trace, go through File -> "Open Trace...", then navigate into the +``lttng-traces`` directory and go into the directory of ``$SESSION_NAME`` from +above. Keep going down through ``ust`` and ``uid`` and keep going down until +you get to the channel files, and opening any of them should load the full +trace into tracecompass. It will take some time to load, especially the flame +graph (if applicable). + +The flame graph loads symbol names from the current system's root directory, +and thus if the trace was generated on the same system as the system running +tracecompass, the symbol names should load fine. This will not be the case if +the trace is from another system. + +In this case the easiest solution is the mount the root filesystem of the +system that the trace was gathered on, and the path to that system needs to be +configured. Click on the "Configure how addresses are mapped to function names" +in the flame graph view, and under the "LTTng" tab, select "Use custom target +root directory", and then "Browse" for the root filesystem of the target +system. For example, if the root filesystem of the device is mounted at +``/mnt/arm64``, then that would be the directory to open. Then the symbol names +in the flame graph should load correctly. + +See the +`tracecompass lttng documentation `_ +for further details.