{"id":21248,"url":"https://patchwork.libcamera.org/api/1.1/patches/21248/?format=json","web_url":"https://patchwork.libcamera.org/patch/21248/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20240912233240.3306148-1-paul.elder@ideasonboard.com>","date":"2024-09-12T23:32:40","name":"guides: tracing: Elaborate on function tracing and tracecompass","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"49072850313ee14c4bc93187246bf541ca71329f","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21248/mbox/","series":[{"id":4586,"url":"https://patchwork.libcamera.org/api/1.1/series/4586/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4586","date":"2024-09-12T23:32:40","name":"guides: tracing: Elaborate on function tracing and tracecompass","version":1,"mbox":"https://patchwork.libcamera.org/series/4586/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21248/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21248/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 51011C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Sep 2024 23:33:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D4F11634FC;\n\tFri, 13 Sep 2024 01:33:01 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE342618F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Sep 2024 01:32:59 +0200 (CEST)","from pyrite.hamster-moth.ts.net\n\t(213-229-8-243.static.upcbusiness.at [213.229.8.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 42CF21011;\n\tFri, 13 Sep 2024 01:31:40 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GFasKlng\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726183901;\n\tbh=2hSHW4Ma7jDK8OnGJie8+NFcjwSQj3g2g4EuCd8g3T0=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=GFasKlngIi3WjlgDQYCeLn4L0ki8F1TDwEe0Dn+19F9Nxb0dwsvFWSgCZLpdiP3H+\n\tk6XuTDUSbfhS5PSEU/Om4W+8g6IQnmirqKyj3hBJ0TXNHdUJ3JGameBZfm3EB2Q4Ko\n\tlbSSC/3OsyAgXsvcdQITypgczEHm9OusG2qgVhsM=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Paul Elder <paul.elder@ideasonboard.com>","Subject":"[PATCH] guides: tracing: Elaborate on function tracing and\n\ttracecompass","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","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Expand the tracing guide to explain how to set up function tracing, and\na simple starter on how to get tracecompass to open the trace.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nThis patch depends on \"meson: Add -finstrument-functions to debug\nbuilds\"\n---\n Documentation/guides/tracing.rst | 100 +++++++++++++++++++++++++++----\n 1 file changed, 90 insertions(+), 10 deletions(-)","diff":"diff --git a/Documentation/guides/tracing.rst b/Documentation/guides/tracing.rst\nindex 537dce500..4b05cd5db 100644\n--- a/Documentation/guides/tracing.rst\n+++ b/Documentation/guides/tracing.rst\n@@ -105,19 +105,65 @@ or any other tracing mechanism if desired.\n Collecting a trace\n ------------------\n \n-A trace can be collected fairly simply from lttng:\n+To collect a trace from lttng, we first start by creating a session:\n \n-.. code-block:: bash\n+``lttng create $SESSION_NAME``\n \n-   lttng create $SESSION_NAME\n-   lttng enable-event -u libcamera:\\*\n-   lttng start\n-   # run libcamera application\n-   lttng stop\n-   lttng view\n-   lttng destroy $SESSION_NAME\n+Next we enable events that we want to listen to. To enable the libcamera\n+events:\n \n-See the `lttng documentation <https://lttng.org/docs/>`_ for further details.\n+``lttng enable-event -u libcamera:\\*``\n+\n+We can also enable the events for\n+`function tracing <https://lttng.org/man/3/lttng-ust-cyg-profile>`_:\n+\n+``lttng enable-event -u lttng_ust_cyg_profile:\\*``\n+\n+Or for the fast version:\n+\n+``lttng enable-event -u lttng_ust_cyg_profile_fast:\\*``\n+\n+Note that function tracing requires libcamera to be built in either the\n+``debug`` or ``debugoptimized`` build types (which can be specified in\n+``meson`` with the ``--buildtype`` option).\n+\n+Lastly, we can\n+`add context fields <https://lttng.org/man/1/lttng-add-context>`_\n+that allow the flame graph to work in tracecompass:\n+\n+``lttng add-context -u -t vpid -t vtid -t procname``\n+\n+Now we can start lttng:\n+\n+``lttng start``\n+\n+And run the libcamera application. For example:\n+\n+``cam -c 1 --capture=10``\n+\n+We also have the option to LD_PRELOAD the function tracer:\n+\n+``LD_PRELOAD=/usr/lib/liblttng-ust-cyg-profile.so cam -c 1 --capture=10``\n+\n+For for the fast function tracer:\n+\n+``LD_PRELOAD=/usr/lib/liblttng-ust-cyg-profile-fast.so cam -c 1 --capture=10``\n+\n+After running the application, we probably want to stop the tracing capture:\n+\n+``lttng stop``\n+\n+Optionally we can view the trace in text form:\n+\n+``lttng view``\n+\n+And finally we can destroy the session:\n+\n+``lttng destroy $SESSION_NAME``\n+\n+Tracing capture can be restarted without destruction, but it will end up in the\n+same log. The session can also be saved by ``lttng save`` before destruction,\n+and then loaded again by ``lttng load $SESSION_NAME``.\n \n The location of the trace file is printed when running\n ``lttng create $SESSION_NAME``. After destroying the session, it can still be\n@@ -125,6 +171,8 @@ 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+See the `lttng documentation <https://lttng.org/docs/>`_ for further details.\n+\n Analyzing a trace\n -----------------\n \n@@ -147,3 +195,35 @@ As an example, there is a script ``utils/tracepoints/analyze-ipa-trace.py``\n that gathers statistics for the time taken for an IPA function call, by\n measuring the time difference between pairs of events\n ``libcamera:ipa_call_start`` and ``libcamera:ipa_call_finish``.\n+\n+Tracecompass\n+------------\n+\n+`Tracecompass <https://eclipse.dev/tracecompass>`_\n+is an easy way to visualize and explore traces without having to first write a\n+script with babeltrace.\n+\n+To open the trace, go through File -> \"Open Trace...\", then navigate into the\n+``lttng-traces`` directory and go into the directory of ``$SESSION_NAME`` from\n+above. Keep going down through ``ust`` and ``uid`` and keep going down until\n+you get to the channel files, and opening any of them should load the full\n+trace into tracecompass. It will take some time to load, especially the flame\n+graph (if applicable).\n+\n+The flame graph loads symbol names from the current system's root directory,\n+and thus if the trace was generated on the same system as the system running\n+tracecompass, the symbol names should load fine. This will not be the case if\n+the trace is from another system.\n+\n+In this case the easiest solution is the mount the root filesystem of the\n+system that the trace was gathered on, and the path to that system needs to be\n+configured. Click on the \"Configure how addresses are mapped to function names\"\n+in the flame graph view, and under the \"LTTng\" tab, select \"Use custom target\n+root directory\", and then \"Browse\" for the root filesystem of the target\n+system. For example, if the root filesystem of the device is mounted at\n+``/mnt/arm64``, then that would be the directory to open. Then the symbol names\n+in the flame graph should load correctly.\n+\n+See the\n+`tracecompass lttng documentation <https://archive.eclipse.org/tracecompass/doc/stable/org.eclipse.tracecompass.doc.user/LTTng-UST-Analyses.html>`_\n+for further details.\n","prefixes":[]}