[{"id":13549,"web_url":"https://patchwork.libcamera.org/comment/13549/","msgid":"<d5df601b-a988-59c6-2a9d-ca2caeb8f786@ideasonboard.com>","date":"2020-10-29T10:30:51","subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Paul,\n\nOn 29/10/2020 10:16, Paul Elder wrote:\n> Implement tracing infrastructure in libcamera. It takes .tp files, as\n> required by lttng, and generates a tracepoint header and C file, as lttng\n> requires. meson is updated accordingly to get it to compile with the\n> rest of libcamera. Update the documentation accordingly.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> Changes in v3:\n> - rename the tracepoints header generateor in meson\n> - add protection against accidental unused variables when tracing is\n>   disabled\n> - make gen-tp-header.py read files as utf-8\n> - add macros LIBCAMERA_TRACEPOINT_IPA_{BEGIN,END}\n> \n> Changes in v2:\n> - move header.tmpl to tracepoints.h.in\n> - rename meson option 'tracepoints' to 'tracing'\n> - make sure C++ objects work in tracepoint arguments\n> - rename generate_header.py to gen-tp-header.py\n> ---\n>  Documentation/Doxyfile.in                     |  2 +\n>  README.rst                                    |  3 +\n>  include/libcamera/internal/meson.build        |  9 +++\n>  include/libcamera/internal/tracepoints.h.in   | 62 +++++++++++++++++++\n>  .../internal/tracepoints/meson.build          |  4 ++\n>  meson.build                                   |  3 +\n>  meson_options.txt                             |  5 ++\n>  src/libcamera/meson.build                     |  7 +++\n>  src/libcamera/tracepoints.cpp                 | 10 +++\n>  utils/meson.build                             |  1 +\n>  utils/tracepoints/gen-tp-header.py            | 38 ++++++++++++\n>  utils/tracepoints/meson.build                 |  5 ++\n>  12 files changed, 149 insertions(+)\n>  create mode 100644 include/libcamera/internal/tracepoints.h.in\n>  create mode 100644 include/libcamera/internal/tracepoints/meson.build\n>  create mode 100644 src/libcamera/tracepoints.cpp\n>  create mode 100644 utils/tracepoints/gen-tp-header.py\n>  create mode 100644 utils/tracepoints/meson.build\n> \n> diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\n> index 5ccd0d05..9a7a3fb4 100644\n> --- a/Documentation/Doxyfile.in\n> +++ b/Documentation/Doxyfile.in\n> @@ -842,6 +842,8 @@ EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/ipa_ipc_unixsocket.cpp \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n> +\t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\n> +\t\t\t @TOP_BUILDDIR@/include/libcamera/internal/tracepoints.h \\\n>  \t\t\t @TOP_BUILDDIR@/include/libcamera/ipa/ \\\n>  \t\t\t @TOP_BUILDDIR@/src/libcamera/proxy/\n>  \n> diff --git a/README.rst b/README.rst\n> index fc8f4948..5c4b6989 100644\n> --- a/README.rst\n> +++ b/README.rst\n> @@ -81,6 +81,9 @@ for gstreamer: [optional]\n>  for qcam: [optional]\n>  \tqtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\n>  \n> +for tracing with lttng: [optional]\n> +        lttng-ust-dev python3-jinja2\n> +\n>  Using GStreamer plugin\n>  ~~~~~~~~~~~~~~~~~~~~~~\n>  \n> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\n> index 8dd744fd..592635a9 100644\n> --- a/include/libcamera/internal/meson.build\n> +++ b/include/libcamera/internal/meson.build\n> @@ -1,5 +1,14 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n> +subdir('tracepoints')\n> +\n> +libcamera_tracepoint_header = custom_target(\n> +    'tp_header',\n> +    input: [ 'tracepoints.h.in', tracepoint_files ],\n> +    output: 'tracepoints.h',\n> +    command: [ gen_tracepoints_header, '@OUTPUT@', '@INPUT@' ],\n> +)\n> +\n>  libcamera_internal_headers = files([\n>      'byte_stream_buffer.h',\n>      'camera_controls.h',\n> diff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in\n> new file mode 100644\n> index 00000000..830c61d7\n> --- /dev/null\n> +++ b/include/libcamera/internal/tracepoints.h.in\n> @@ -0,0 +1,62 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) {{year}}, Google Inc.\n> + *\n> + * tracepoints.h - Tracepoints with lttng\n> + *\n> + * This file is auto-generated. Do not edit.\n> + */\n> +#ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> +#define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> +\n> +#if HAVE_TRACING\n> +#define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n> +tracepoint(libcamera, ipa_call_begin, #pipe, #func)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n> +tracepoint(libcamera, ipa_call_end, #pipe, #func)\n> +\n> +#else\n> +\n> +namespace {\n> +\n> +template <typename ...Args>\n> +inline void unused([[maybe_unused]] Args&& ...args)\n> +{\n> +}\n\nDo you need this ununsed()?\n\n> +\n> +} /* namespace */\n> +\n> +#define LIBCAMERA_TRACEPOINT(category, ...) unused(__VA_ARGS__)\n\nYou could just define the following to declare that they don't do anything:\n\n#define LIBCAMERA_TRACEPOINT(category, ...) do { } while (0)\n#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)  do { } while (0)\n#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)  do { } while (0)\n\nBut perhaps that's the C developer approach.\n\nThere's no requirement to change this by the way, I'm only wondering if\nremoving the template would be faster at build time.\n\nOtherwise, at least simplifying the function to\ninline void unused(void)\n{\n}\n\nand not passing the arguments, would remove the need for any templating\nalso.\n\nBut that's fairly minor, and the rest looks reasonable to me.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) unused(#pipe, #func)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) unused(#pipe, #func)\n> +\n> +#endif /* HAVE_TRACING */\n> +\n> +#endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */\n> +\n> +\n> +#if HAVE_TRACING\n> +\n> +#undef TRACEPOINT_PROVIDER\n> +#define TRACEPOINT_PROVIDER libcamera\n> +\n> +#undef TRACEPOINT_INCLUDE\n> +#define TRACEPOINT_INCLUDE \"{{path}}\"\n> +\n> +#if !defined(INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)\n> +#define INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H\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> diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build\n> new file mode 100644\n> index 00000000..2dd6733e\n> --- /dev/null\n> +++ b/include/libcamera/internal/tracepoints/meson.build\n> @@ -0,0 +1,4 @@\n> +# SPDX-License-Identifier: CC0-1.0\n> +\n> +tracepoint_files = files([\n> +])\n> diff --git a/meson.build b/meson.build\n> index e6f6c84a..55cf36e1 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -108,6 +108,9 @@ libcamera_includes = include_directories('include')\n>  # Sub-directories fill py_modules with their dependencies.\n>  py_modules = []\n>  \n> +# Libraries used by multiple components\n> +liblttng = cc.find_library('lttng-ust', required : get_option('tracing'))\n> +\n>  # Utilities are parsed first to provide support for other components.\n>  subdir('utils')\n>  \n> diff --git a/meson_options.txt b/meson_options.txt\n> index 7f7b3e59..53f2675e 100644\n> --- a/meson_options.txt\n> +++ b/meson_options.txt\n> @@ -28,6 +28,11 @@ option('test',\n>          type : 'boolean',\n>          description: 'Compile and include the tests')\n>  \n> +option('tracing',\n> +        type : 'feature',\n> +        value : 'auto',\n> +        description: 'Enable tracing (based on lttng)')\n> +\n>  option('v4l2',\n>          type : 'boolean',\n>          value : false,\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 24f7ea3d..51925bd6 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -58,6 +58,7 @@ libcamera_sources = files([\n>  \n>  libcamera_sources += libcamera_public_headers\n>  libcamera_sources += libcamera_generated_ipa_headers\n> +libcamera_sources += libcamera_tracepoint_header\n>  \n>  includes = [\n>      libcamera_includes,\n> @@ -75,6 +76,11 @@ if libgnutls.found()\n>      config_h.set('HAVE_GNUTLS', 1)\n>  endif\n>  \n> +if liblttng.found()\n> +    config_h.set('HAVE_TRACING', 1)\n> +    libcamera_sources += files(['tracepoints.cpp'])\n> +endif\n> +\n>  if libudev.found()\n>      config_h.set('HAVE_LIBUDEV', 1)\n>      libcamera_sources += files([\n> @@ -117,6 +123,7 @@ libcamera_deps = [\n>      libatomic,\n>      libdl,\n>      libgnutls,\n> +    liblttng,\n>      libudev,\n>      dependency('threads'),\n>  ]\n> diff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp\n> new file mode 100644\n> index 00000000..0173b75a\n> --- /dev/null\n> +++ b/src/libcamera/tracepoints.cpp\n> @@ -0,0 +1,10 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2020, Google Inc.\n> + *\n> + * tracepoints.cpp - Tracepoints with lttng\n> + */\n> +#define TRACEPOINT_CREATE_PROBES\n> +#define TRACEPOINT_DEFINE\n> +\n> +#include \"libcamera/internal/tracepoints.h\"\n> diff --git a/utils/meson.build b/utils/meson.build\n> index 383d5285..8e28ada7 100644\n> --- a/utils/meson.build\n> +++ b/utils/meson.build\n> @@ -2,6 +2,7 @@\n>  \n>  subdir('ipc')\n>  subdir('ipu3')\n> +subdir('tracepoints')\n>  \n>  ## Code generation\n>  py_modules += ['yaml']\n> diff --git a/utils/tracepoints/gen-tp-header.py b/utils/tracepoints/gen-tp-header.py\n> new file mode 100644\n> index 00000000..9500e474\n> --- /dev/null\n> +++ b/utils/tracepoints/gen-tp-header.py\n> @@ -0,0 +1,38 @@\n> +#!/usr/bin/env python3\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +# Copyright (C) 2020, Google Inc.\n> +#\n> +# Author: Paul Elder <paul.elder@ideasonboard.com>\n> +#\n> +# gen-tp-header.py - Generate header file to contain lttng tracepoints\n> +\n> +import datetime\n> +import jinja2\n> +import os\n> +import sys\n> +\n> +def main(argv):\n> +    if len(argv) < 3:\n> +        print(f'Usage: {argv[0]} output template tp_files...')\n> +        return 1\n> +\n> +    output = argv[1]\n> +    template = argv[2]\n> +\n> +    year = datetime.datetime.now().year\n> +    path = output.replace('include/', '', 1)\n> +\n> +    source = ''\n> +    for fname in argv[3:]:\n> +        source += open(fname, 'r', encoding='utf-8').read() + '\\n\\n'\n> +\n> +    template = jinja2.Template(open(template, 'r').read())\n> +    string = template.render(year=year, path=path, source=source)\n> +\n> +    f = open(output, 'w').write(string)\n> +\n> +    return 0\n> +\n> +\n> +if __name__ == '__main__':\n> +    sys.exit(main(sys.argv))\n> diff --git a/utils/tracepoints/meson.build b/utils/tracepoints/meson.build\n> new file mode 100644\n> index 00000000..807230fc\n> --- /dev/null\n> +++ b/utils/tracepoints/meson.build\n> @@ -0,0 +1,5 @@\n> +# SPDX-License-Identifier: CC0-1.0\n> +\n> +py_modules += ['jinja2']\n> +\n> +gen_tracepoints_header = find_program('./gen-tp-header.py')\n>","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 50403BDB9B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 29 Oct 2020 10:30:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C85B76289D;\n\tThu, 29 Oct 2020 11:30:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B923627D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Oct 2020 11:30:55 +0100 (CET)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 93E3350E;\n\tThu, 29 Oct 2020 11:30:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tkWApvvX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1603967454;\n\tbh=nsC4ho4E6XXSWeiZnrAOQxnTuhV2xWIlPtbJQ2Xpi8s=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=tkWApvvXeixRvxNfVwD+mE4GynKAPe2ahR0byoQUvq3Zqb9tIQUNSGau667cCh1Bi\n\tA0P+KnsexOUW9lleSvNOEEbcdW8syAh5EK1Uj/8wpd7m5d6OfLchhfT4V3ybqA2ruB\n\tnEnz50l8D703GI37aeyXaOmVuLps9b6VKrmYYq3A=","To":"Paul Elder <paul.elder@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20201029101629.61798-1-paul.elder@ideasonboard.com>\n\t<20201029101629.61798-2-paul.elder@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36\n\tOe9X9dXB8YSNt7VjOcO7BTmFn/Z8r92mSAfHXpb07YJWJosQOQARAQABtDBLaWVyYW4gQmlu\n\tZ2hhbSA8a2llcmFuLmJpbmdoYW1AaWRlYXNvbmJvYXJkLmNvbT6JAlcEEwEKAEECGwMFCwkI\n\tBwIGFQgJCgsCBBYCAwECHgECF4ACGQEWIQSQLdeYP70o/eN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\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<d5df601b-a988-59c6-2a9d-ca2caeb8f786@ideasonboard.com>","Date":"Thu, 29 Oct 2020 10:30:51 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<20201029101629.61798-2-paul.elder@ideasonboard.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","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>","Reply-To":"kieran.bingham@ideasonboard.com","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":13550,"web_url":"https://patchwork.libcamera.org/comment/13550/","msgid":"<20201029103431.GA3974@pendragon.ideasonboard.com>","date":"2020-10-29T10:34:31","subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Thu, Oct 29, 2020 at 10:30:51AM +0000, Kieran Bingham wrote:\n> On 29/10/2020 10:16, Paul Elder wrote:\n> > Implement tracing infrastructure in libcamera. It takes .tp files, as\n> > required by lttng, and generates a tracepoint header and C file, as lttng\n> > requires. meson is updated accordingly to get it to compile with the\n> > rest of libcamera. Update the documentation accordingly.\n> > \n> > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > \n> > ---\n> > Changes in v3:\n> > - rename the tracepoints header generateor in meson\n> > - add protection against accidental unused variables when tracing is\n> >   disabled\n> > - make gen-tp-header.py read files as utf-8\n> > - add macros LIBCAMERA_TRACEPOINT_IPA_{BEGIN,END}\n> > \n> > Changes in v2:\n> > - move header.tmpl to tracepoints.h.in\n> > - rename meson option 'tracepoints' to 'tracing'\n> > - make sure C++ objects work in tracepoint arguments\n> > - rename generate_header.py to gen-tp-header.py\n> > ---\n> >  Documentation/Doxyfile.in                     |  2 +\n> >  README.rst                                    |  3 +\n> >  include/libcamera/internal/meson.build        |  9 +++\n> >  include/libcamera/internal/tracepoints.h.in   | 62 +++++++++++++++++++\n> >  .../internal/tracepoints/meson.build          |  4 ++\n> >  meson.build                                   |  3 +\n> >  meson_options.txt                             |  5 ++\n> >  src/libcamera/meson.build                     |  7 +++\n> >  src/libcamera/tracepoints.cpp                 | 10 +++\n> >  utils/meson.build                             |  1 +\n> >  utils/tracepoints/gen-tp-header.py            | 38 ++++++++++++\n> >  utils/tracepoints/meson.build                 |  5 ++\n> >  12 files changed, 149 insertions(+)\n> >  create mode 100644 include/libcamera/internal/tracepoints.h.in\n> >  create mode 100644 include/libcamera/internal/tracepoints/meson.build\n> >  create mode 100644 src/libcamera/tracepoints.cpp\n> >  create mode 100644 utils/tracepoints/gen-tp-header.py\n> >  create mode 100644 utils/tracepoints/meson.build\n> > \n> > diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\n> > index 5ccd0d05..9a7a3fb4 100644\n> > --- a/Documentation/Doxyfile.in\n> > +++ b/Documentation/Doxyfile.in\n> > @@ -842,6 +842,8 @@ EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n> >  \t\t\t @TOP_SRCDIR@/src/libcamera/ipa_ipc_unixsocket.cpp \\\n> >  \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n> >  \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n> > +\t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\n> > +\t\t\t @TOP_BUILDDIR@/include/libcamera/internal/tracepoints.h \\\n> >  \t\t\t @TOP_BUILDDIR@/include/libcamera/ipa/ \\\n> >  \t\t\t @TOP_BUILDDIR@/src/libcamera/proxy/\n> >  \n> > diff --git a/README.rst b/README.rst\n> > index fc8f4948..5c4b6989 100644\n> > --- a/README.rst\n> > +++ b/README.rst\n> > @@ -81,6 +81,9 @@ for gstreamer: [optional]\n> >  for qcam: [optional]\n> >  \tqtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\n> >  \n> > +for tracing with lttng: [optional]\n> > +        lttng-ust-dev python3-jinja2\n> > +\n> >  Using GStreamer plugin\n> >  ~~~~~~~~~~~~~~~~~~~~~~\n> >  \n> > diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\n> > index 8dd744fd..592635a9 100644\n> > --- a/include/libcamera/internal/meson.build\n> > +++ b/include/libcamera/internal/meson.build\n> > @@ -1,5 +1,14 @@\n> >  # SPDX-License-Identifier: CC0-1.0\n> >  \n> > +subdir('tracepoints')\n> > +\n> > +libcamera_tracepoint_header = custom_target(\n> > +    'tp_header',\n> > +    input: [ 'tracepoints.h.in', tracepoint_files ],\n> > +    output: 'tracepoints.h',\n> > +    command: [ gen_tracepoints_header, '@OUTPUT@', '@INPUT@' ],\n> > +)\n> > +\n> >  libcamera_internal_headers = files([\n> >      'byte_stream_buffer.h',\n> >      'camera_controls.h',\n> > diff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in\n> > new file mode 100644\n> > index 00000000..830c61d7\n> > --- /dev/null\n> > +++ b/include/libcamera/internal/tracepoints.h.in\n> > @@ -0,0 +1,62 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) {{year}}, Google Inc.\n> > + *\n> > + * tracepoints.h - Tracepoints with lttng\n> > + *\n> > + * This file is auto-generated. Do not edit.\n> > + */\n> > +#ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> > +#define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> > +\n> > +#if HAVE_TRACING\n> > +#define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)\n> > +\n> > +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n> > +tracepoint(libcamera, ipa_call_begin, #pipe, #func)\n> > +\n> > +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n> > +tracepoint(libcamera, ipa_call_end, #pipe, #func)\n> > +\n> > +#else\n> > +\n> > +namespace {\n> > +\n> > +template <typename ...Args>\n> > +inline void unused([[maybe_unused]] Args&& ...args)\n> > +{\n> > +}\n> \n> Do you need this ununsed()?\n> \n> > +\n> > +} /* namespace */\n> > +\n> > +#define LIBCAMERA_TRACEPOINT(category, ...) unused(__VA_ARGS__)\n> \n> You could just define the following to declare that they don't do anything:\n> \n> #define LIBCAMERA_TRACEPOINT(category, ...) do { } while (0)\n> #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)  do { } while (0)\n> #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)  do { } while (0)\n> \n> But perhaps that's the C developer approach.\n\nThat's Paul had in the previous version, but it causes unused variable\nwarnings if arguments to the tracepoints are stored in variables that\nare otherwise unused.\n\n> There's no requirement to change this by the way, I'm only wondering if\n> removing the template would be faster at build time.\n> \n> Otherwise, at least simplifying the function to\n> inline void unused(void)\n> {\n> }\n> \n> and not passing the arguments, would remove the need for any templating\n> also.\n> \n> But that's fairly minor, and the rest looks reasonable to me.\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\n> > +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) unused(#pipe, #func)\n> > +\n> > +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) unused(#pipe, #func)\n\nThese two are however not needed, as they're just identifiers treated as\nstrings, not variables.\n\n#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)\n#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)\n\nis good enough.\n\n> > +\n> > +#endif /* HAVE_TRACING */\n> > +\n> > +#endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */\n> > +\n> > +\n> > +#if HAVE_TRACING\n> > +\n> > +#undef TRACEPOINT_PROVIDER\n> > +#define TRACEPOINT_PROVIDER libcamera\n> > +\n> > +#undef TRACEPOINT_INCLUDE\n> > +#define TRACEPOINT_INCLUDE \"{{path}}\"\n> > +\n> > +#if !defined(INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)\n> > +#define INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H\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> > diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build\n> > new file mode 100644\n> > index 00000000..2dd6733e\n> > --- /dev/null\n> > +++ b/include/libcamera/internal/tracepoints/meson.build\n> > @@ -0,0 +1,4 @@\n> > +# SPDX-License-Identifier: CC0-1.0\n> > +\n> > +tracepoint_files = files([\n> > +])\n> > diff --git a/meson.build b/meson.build\n> > index e6f6c84a..55cf36e1 100644\n> > --- a/meson.build\n> > +++ b/meson.build\n> > @@ -108,6 +108,9 @@ libcamera_includes = include_directories('include')\n> >  # Sub-directories fill py_modules with their dependencies.\n> >  py_modules = []\n> >  \n> > +# Libraries used by multiple components\n> > +liblttng = cc.find_library('lttng-ust', required : get_option('tracing'))\n> > +\n> >  # Utilities are parsed first to provide support for other components.\n> >  subdir('utils')\n> >  \n> > diff --git a/meson_options.txt b/meson_options.txt\n> > index 7f7b3e59..53f2675e 100644\n> > --- a/meson_options.txt\n> > +++ b/meson_options.txt\n> > @@ -28,6 +28,11 @@ option('test',\n> >          type : 'boolean',\n> >          description: 'Compile and include the tests')\n> >  \n> > +option('tracing',\n> > +        type : 'feature',\n> > +        value : 'auto',\n> > +        description: 'Enable tracing (based on lttng)')\n> > +\n> >  option('v4l2',\n> >          type : 'boolean',\n> >          value : false,\n> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> > index 24f7ea3d..51925bd6 100644\n> > --- a/src/libcamera/meson.build\n> > +++ b/src/libcamera/meson.build\n> > @@ -58,6 +58,7 @@ libcamera_sources = files([\n> >  \n> >  libcamera_sources += libcamera_public_headers\n> >  libcamera_sources += libcamera_generated_ipa_headers\n> > +libcamera_sources += libcamera_tracepoint_header\n> >  \n> >  includes = [\n> >      libcamera_includes,\n> > @@ -75,6 +76,11 @@ if libgnutls.found()\n> >      config_h.set('HAVE_GNUTLS', 1)\n> >  endif\n> >  \n> > +if liblttng.found()\n> > +    config_h.set('HAVE_TRACING', 1)\n> > +    libcamera_sources += files(['tracepoints.cpp'])\n> > +endif\n> > +\n> >  if libudev.found()\n> >      config_h.set('HAVE_LIBUDEV', 1)\n> >      libcamera_sources += files([\n> > @@ -117,6 +123,7 @@ libcamera_deps = [\n> >      libatomic,\n> >      libdl,\n> >      libgnutls,\n> > +    liblttng,\n> >      libudev,\n> >      dependency('threads'),\n> >  ]\n> > diff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp\n> > new file mode 100644\n> > index 00000000..0173b75a\n> > --- /dev/null\n> > +++ b/src/libcamera/tracepoints.cpp\n> > @@ -0,0 +1,10 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2020, Google Inc.\n> > + *\n> > + * tracepoints.cpp - Tracepoints with lttng\n> > + */\n> > +#define TRACEPOINT_CREATE_PROBES\n> > +#define TRACEPOINT_DEFINE\n> > +\n> > +#include \"libcamera/internal/tracepoints.h\"\n> > diff --git a/utils/meson.build b/utils/meson.build\n> > index 383d5285..8e28ada7 100644\n> > --- a/utils/meson.build\n> > +++ b/utils/meson.build\n> > @@ -2,6 +2,7 @@\n> >  \n> >  subdir('ipc')\n> >  subdir('ipu3')\n> > +subdir('tracepoints')\n> >  \n> >  ## Code generation\n> >  py_modules += ['yaml']\n> > diff --git a/utils/tracepoints/gen-tp-header.py b/utils/tracepoints/gen-tp-header.py\n> > new file mode 100644\n> > index 00000000..9500e474\n> > --- /dev/null\n> > +++ b/utils/tracepoints/gen-tp-header.py\n> > @@ -0,0 +1,38 @@\n> > +#!/usr/bin/env python3\n> > +# SPDX-License-Identifier: GPL-2.0-or-later\n> > +# Copyright (C) 2020, Google Inc.\n> > +#\n> > +# Author: Paul Elder <paul.elder@ideasonboard.com>\n> > +#\n> > +# gen-tp-header.py - Generate header file to contain lttng tracepoints\n> > +\n> > +import datetime\n> > +import jinja2\n> > +import os\n> > +import sys\n> > +\n> > +def main(argv):\n> > +    if len(argv) < 3:\n> > +        print(f'Usage: {argv[0]} output template tp_files...')\n> > +        return 1\n> > +\n> > +    output = argv[1]\n> > +    template = argv[2]\n> > +\n> > +    year = datetime.datetime.now().year\n> > +    path = output.replace('include/', '', 1)\n> > +\n> > +    source = ''\n> > +    for fname in argv[3:]:\n> > +        source += open(fname, 'r', encoding='utf-8').read() + '\\n\\n'\n> > +\n> > +    template = jinja2.Template(open(template, 'r').read())\n> > +    string = template.render(year=year, path=path, source=source)\n> > +\n> > +    f = open(output, 'w').write(string)\n> > +\n> > +    return 0\n> > +\n> > +\n> > +if __name__ == '__main__':\n> > +    sys.exit(main(sys.argv))\n> > diff --git a/utils/tracepoints/meson.build b/utils/tracepoints/meson.build\n> > new file mode 100644\n> > index 00000000..807230fc\n> > --- /dev/null\n> > +++ b/utils/tracepoints/meson.build\n> > @@ -0,0 +1,5 @@\n> > +# SPDX-License-Identifier: CC0-1.0\n> > +\n> > +py_modules += ['jinja2']\n> > +\n> > +gen_tracepoints_header = find_program('./gen-tp-header.py')","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 6444BBDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 29 Oct 2020 10:35:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CE1B4628C6;\n\tThu, 29 Oct 2020 11:35:21 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF6FC627D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Oct 2020 11:35:20 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 088C950E;\n\tThu, 29 Oct 2020 11:35:19 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lEA/C6UY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1603967720;\n\tbh=pulf05zzc/h1mVj7HME8fWFSnsxkLryBKUlc9dzQpJ4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lEA/C6UYdCmV53Wf7lVdyu4wCc91bv9PoTS/Cb8t5DMccIR8q8UjkrIagq3iLMkDa\n\tFO2/5ew4wEs0u6l6mxyLZXwVwZQoqz4NUpUrzrVmppMEr+ZyBfOyTu1Lquaj+qOBop\n\twJq9TqvW62Nfxy0N2tXuwWI8jli/iZrUNMw51/eQ=","Date":"Thu, 29 Oct 2020 12:34:31 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20201029103431.GA3974@pendragon.ideasonboard.com>","References":"<20201029101629.61798-1-paul.elder@ideasonboard.com>\n\t<20201029101629.61798-2-paul.elder@ideasonboard.com>\n\t<d5df601b-a988-59c6-2a9d-ca2caeb8f786@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<d5df601b-a988-59c6-2a9d-ca2caeb8f786@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":13551,"web_url":"https://patchwork.libcamera.org/comment/13551/","msgid":"<1f984666-eb63-c622-4dfa-7722da9e553c@ideasonboard.com>","date":"2020-10-29T10:37:18","subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 29/10/2020 10:34, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> On Thu, Oct 29, 2020 at 10:30:51AM +0000, Kieran Bingham wrote:\n>> On 29/10/2020 10:16, Paul Elder wrote:\n>>> Implement tracing infrastructure in libcamera. It takes .tp files, as\n>>> required by lttng, and generates a tracepoint header and C file, as lttng\n>>> requires. meson is updated accordingly to get it to compile with the\n>>> rest of libcamera. Update the documentation accordingly.\n>>>\n>>> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>>>\n>>> ---\n>>> Changes in v3:\n>>> - rename the tracepoints header generateor in meson\n>>> - add protection against accidental unused variables when tracing is\n>>>   disabled\n>>> - make gen-tp-header.py read files as utf-8\n>>> - add macros LIBCAMERA_TRACEPOINT_IPA_{BEGIN,END}\n>>>\n>>> Changes in v2:\n>>> - move header.tmpl to tracepoints.h.in\n>>> - rename meson option 'tracepoints' to 'tracing'\n>>> - make sure C++ objects work in tracepoint arguments\n>>> - rename generate_header.py to gen-tp-header.py\n>>> ---\n>>>  Documentation/Doxyfile.in                     |  2 +\n>>>  README.rst                                    |  3 +\n>>>  include/libcamera/internal/meson.build        |  9 +++\n>>>  include/libcamera/internal/tracepoints.h.in   | 62 +++++++++++++++++++\n>>>  .../internal/tracepoints/meson.build          |  4 ++\n>>>  meson.build                                   |  3 +\n>>>  meson_options.txt                             |  5 ++\n>>>  src/libcamera/meson.build                     |  7 +++\n>>>  src/libcamera/tracepoints.cpp                 | 10 +++\n>>>  utils/meson.build                             |  1 +\n>>>  utils/tracepoints/gen-tp-header.py            | 38 ++++++++++++\n>>>  utils/tracepoints/meson.build                 |  5 ++\n>>>  12 files changed, 149 insertions(+)\n>>>  create mode 100644 include/libcamera/internal/tracepoints.h.in\n>>>  create mode 100644 include/libcamera/internal/tracepoints/meson.build\n>>>  create mode 100644 src/libcamera/tracepoints.cpp\n>>>  create mode 100644 utils/tracepoints/gen-tp-header.py\n>>>  create mode 100644 utils/tracepoints/meson.build\n>>>\n>>> diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\n>>> index 5ccd0d05..9a7a3fb4 100644\n>>> --- a/Documentation/Doxyfile.in\n>>> +++ b/Documentation/Doxyfile.in\n>>> @@ -842,6 +842,8 @@ EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n>>>  \t\t\t @TOP_SRCDIR@/src/libcamera/ipa_ipc_unixsocket.cpp \\\n>>>  \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n>>>  \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n>>> +\t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\n>>> +\t\t\t @TOP_BUILDDIR@/include/libcamera/internal/tracepoints.h \\\n>>>  \t\t\t @TOP_BUILDDIR@/include/libcamera/ipa/ \\\n>>>  \t\t\t @TOP_BUILDDIR@/src/libcamera/proxy/\n>>>  \n>>> diff --git a/README.rst b/README.rst\n>>> index fc8f4948..5c4b6989 100644\n>>> --- a/README.rst\n>>> +++ b/README.rst\n>>> @@ -81,6 +81,9 @@ for gstreamer: [optional]\n>>>  for qcam: [optional]\n>>>  \tqtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\n>>>  \n>>> +for tracing with lttng: [optional]\n>>> +        lttng-ust-dev python3-jinja2\n>>> +\n>>>  Using GStreamer plugin\n>>>  ~~~~~~~~~~~~~~~~~~~~~~\n>>>  \n>>> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\n>>> index 8dd744fd..592635a9 100644\n>>> --- a/include/libcamera/internal/meson.build\n>>> +++ b/include/libcamera/internal/meson.build\n>>> @@ -1,5 +1,14 @@\n>>>  # SPDX-License-Identifier: CC0-1.0\n>>>  \n>>> +subdir('tracepoints')\n>>> +\n>>> +libcamera_tracepoint_header = custom_target(\n>>> +    'tp_header',\n>>> +    input: [ 'tracepoints.h.in', tracepoint_files ],\n>>> +    output: 'tracepoints.h',\n>>> +    command: [ gen_tracepoints_header, '@OUTPUT@', '@INPUT@' ],\n>>> +)\n>>> +\n>>>  libcamera_internal_headers = files([\n>>>      'byte_stream_buffer.h',\n>>>      'camera_controls.h',\n>>> diff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in\n>>> new file mode 100644\n>>> index 00000000..830c61d7\n>>> --- /dev/null\n>>> +++ b/include/libcamera/internal/tracepoints.h.in\n>>> @@ -0,0 +1,62 @@\n>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n>>> +/*\n>>> + * Copyright (C) {{year}}, Google Inc.\n>>> + *\n>>> + * tracepoints.h - Tracepoints with lttng\n>>> + *\n>>> + * This file is auto-generated. Do not edit.\n>>> + */\n>>> +#ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n>>> +#define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n>>> +\n>>> +#if HAVE_TRACING\n>>> +#define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)\n>>> +\n>>> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n>>> +tracepoint(libcamera, ipa_call_begin, #pipe, #func)\n>>> +\n>>> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n>>> +tracepoint(libcamera, ipa_call_end, #pipe, #func)\n>>> +\n>>> +#else\n>>> +\n>>> +namespace {\n>>> +\n>>> +template <typename ...Args>\n>>> +inline void unused([[maybe_unused]] Args&& ...args)\n>>> +{\n>>> +}\n>>\n>> Do you need this ununsed()?\n>>\n>>> +\n>>> +} /* namespace */\n>>> +\n>>> +#define LIBCAMERA_TRACEPOINT(category, ...) unused(__VA_ARGS__)\n>>\n>> You could just define the following to declare that they don't do anything:\n>>\n>> #define LIBCAMERA_TRACEPOINT(category, ...) do { } while (0)\n>> #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)  do { } while (0)\n>> #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)  do { } while (0)\n>>\n>> But perhaps that's the C developer approach.\n> \n> That's Paul had in the previous version, but it causes unused variable\n> warnings if arguments to the tracepoints are stored in variables that\n> are otherwise unused.\n\nAha - that's clear indeed, it is the effect on the location that matters\nof course.\n\nFine by me either way.\n\n>> There's no requirement to change this by the way, I'm only wondering if\n>> removing the template would be faster at build time.\n>>\n>> Otherwise, at least simplifying the function to\n>> inline void unused(void)\n>> {\n>> }\n>>\n>> and not passing the arguments, would remove the need for any templating\n>> also.\n\nWell, clearly we need the arguments, so that doesn't work ;-)\n\n>>\n>> But that's fairly minor, and the rest looks reasonable to me.\n>>\n>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nStill stands.\n\nThanks\n\nKieran\n\n\n>>\n>>> +\n>>> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) unused(#pipe, #func)\n>>> +\n>>> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) unused(#pipe, #func)\n> \n> These two are however not needed, as they're just identifiers treated as\n> strings, not variables.\n> \n> #define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)\n> #define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)\n> \n> is good enough.\n> \n>>> +\n>>> +#endif /* HAVE_TRACING */\n>>> +\n>>> +#endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */\n>>> +\n>>> +\n>>> +#if HAVE_TRACING\n>>> +\n>>> +#undef TRACEPOINT_PROVIDER\n>>> +#define TRACEPOINT_PROVIDER libcamera\n>>> +\n>>> +#undef TRACEPOINT_INCLUDE\n>>> +#define TRACEPOINT_INCLUDE \"{{path}}\"\n>>> +\n>>> +#if !defined(INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)\n>>> +#define INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H\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>>> diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build\n>>> new file mode 100644\n>>> index 00000000..2dd6733e\n>>> --- /dev/null\n>>> +++ b/include/libcamera/internal/tracepoints/meson.build\n>>> @@ -0,0 +1,4 @@\n>>> +# SPDX-License-Identifier: CC0-1.0\n>>> +\n>>> +tracepoint_files = files([\n>>> +])\n>>> diff --git a/meson.build b/meson.build\n>>> index e6f6c84a..55cf36e1 100644\n>>> --- a/meson.build\n>>> +++ b/meson.build\n>>> @@ -108,6 +108,9 @@ libcamera_includes = include_directories('include')\n>>>  # Sub-directories fill py_modules with their dependencies.\n>>>  py_modules = []\n>>>  \n>>> +# Libraries used by multiple components\n>>> +liblttng = cc.find_library('lttng-ust', required : get_option('tracing'))\n>>> +\n>>>  # Utilities are parsed first to provide support for other components.\n>>>  subdir('utils')\n>>>  \n>>> diff --git a/meson_options.txt b/meson_options.txt\n>>> index 7f7b3e59..53f2675e 100644\n>>> --- a/meson_options.txt\n>>> +++ b/meson_options.txt\n>>> @@ -28,6 +28,11 @@ option('test',\n>>>          type : 'boolean',\n>>>          description: 'Compile and include the tests')\n>>>  \n>>> +option('tracing',\n>>> +        type : 'feature',\n>>> +        value : 'auto',\n>>> +        description: 'Enable tracing (based on lttng)')\n>>> +\n>>>  option('v4l2',\n>>>          type : 'boolean',\n>>>          value : false,\n>>> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n>>> index 24f7ea3d..51925bd6 100644\n>>> --- a/src/libcamera/meson.build\n>>> +++ b/src/libcamera/meson.build\n>>> @@ -58,6 +58,7 @@ libcamera_sources = files([\n>>>  \n>>>  libcamera_sources += libcamera_public_headers\n>>>  libcamera_sources += libcamera_generated_ipa_headers\n>>> +libcamera_sources += libcamera_tracepoint_header\n>>>  \n>>>  includes = [\n>>>      libcamera_includes,\n>>> @@ -75,6 +76,11 @@ if libgnutls.found()\n>>>      config_h.set('HAVE_GNUTLS', 1)\n>>>  endif\n>>>  \n>>> +if liblttng.found()\n>>> +    config_h.set('HAVE_TRACING', 1)\n>>> +    libcamera_sources += files(['tracepoints.cpp'])\n>>> +endif\n>>> +\n>>>  if libudev.found()\n>>>      config_h.set('HAVE_LIBUDEV', 1)\n>>>      libcamera_sources += files([\n>>> @@ -117,6 +123,7 @@ libcamera_deps = [\n>>>      libatomic,\n>>>      libdl,\n>>>      libgnutls,\n>>> +    liblttng,\n>>>      libudev,\n>>>      dependency('threads'),\n>>>  ]\n>>> diff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp\n>>> new file mode 100644\n>>> index 00000000..0173b75a\n>>> --- /dev/null\n>>> +++ b/src/libcamera/tracepoints.cpp\n>>> @@ -0,0 +1,10 @@\n>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n>>> +/*\n>>> + * Copyright (C) 2020, Google Inc.\n>>> + *\n>>> + * tracepoints.cpp - Tracepoints with lttng\n>>> + */\n>>> +#define TRACEPOINT_CREATE_PROBES\n>>> +#define TRACEPOINT_DEFINE\n>>> +\n>>> +#include \"libcamera/internal/tracepoints.h\"\n>>> diff --git a/utils/meson.build b/utils/meson.build\n>>> index 383d5285..8e28ada7 100644\n>>> --- a/utils/meson.build\n>>> +++ b/utils/meson.build\n>>> @@ -2,6 +2,7 @@\n>>>  \n>>>  subdir('ipc')\n>>>  subdir('ipu3')\n>>> +subdir('tracepoints')\n>>>  \n>>>  ## Code generation\n>>>  py_modules += ['yaml']\n>>> diff --git a/utils/tracepoints/gen-tp-header.py b/utils/tracepoints/gen-tp-header.py\n>>> new file mode 100644\n>>> index 00000000..9500e474\n>>> --- /dev/null\n>>> +++ b/utils/tracepoints/gen-tp-header.py\n>>> @@ -0,0 +1,38 @@\n>>> +#!/usr/bin/env python3\n>>> +# SPDX-License-Identifier: GPL-2.0-or-later\n>>> +# Copyright (C) 2020, Google Inc.\n>>> +#\n>>> +# Author: Paul Elder <paul.elder@ideasonboard.com>\n>>> +#\n>>> +# gen-tp-header.py - Generate header file to contain lttng tracepoints\n>>> +\n>>> +import datetime\n>>> +import jinja2\n>>> +import os\n>>> +import sys\n>>> +\n>>> +def main(argv):\n>>> +    if len(argv) < 3:\n>>> +        print(f'Usage: {argv[0]} output template tp_files...')\n>>> +        return 1\n>>> +\n>>> +    output = argv[1]\n>>> +    template = argv[2]\n>>> +\n>>> +    year = datetime.datetime.now().year\n>>> +    path = output.replace('include/', '', 1)\n>>> +\n>>> +    source = ''\n>>> +    for fname in argv[3:]:\n>>> +        source += open(fname, 'r', encoding='utf-8').read() + '\\n\\n'\n>>> +\n>>> +    template = jinja2.Template(open(template, 'r').read())\n>>> +    string = template.render(year=year, path=path, source=source)\n>>> +\n>>> +    f = open(output, 'w').write(string)\n>>> +\n>>> +    return 0\n>>> +\n>>> +\n>>> +if __name__ == '__main__':\n>>> +    sys.exit(main(sys.argv))\n>>> diff --git a/utils/tracepoints/meson.build b/utils/tracepoints/meson.build\n>>> new file mode 100644\n>>> index 00000000..807230fc\n>>> --- /dev/null\n>>> +++ b/utils/tracepoints/meson.build\n>>> @@ -0,0 +1,5 @@\n>>> +# SPDX-License-Identifier: CC0-1.0\n>>> +\n>>> +py_modules += ['jinja2']\n>>> +\n>>> +gen_tracepoints_header = find_program('./gen-tp-header.py')\n>","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 4C7E4BDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 29 Oct 2020 10:37:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D2EA16288A;\n\tThu, 29 Oct 2020 11:37:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E72D62882\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Oct 2020 11:37:21 +0100 (CET)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 04DFA50E;\n\tThu, 29 Oct 2020 11:37:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NCBR3j8Z\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1603967841;\n\tbh=8tfePe8xF1FbHbF6452UZgdCI2xb96yShJuq1KfqlvI=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=NCBR3j8ZpM7dRuwGaWKF+iY4pP6d3+Y1AqFxQLCcsvxRRyC/wIDILhLl0xoKr4myb\n\tihG/SVD3wpbuw/sl+GT74Getu+WWH/hwQ370apEQpusmQnRI6H97BuEDyN4OTEYJYQ\n\t2N6hzh2ant+1l5PCs5elbItDh7KPMU5FuWNfLFfc=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20201029101629.61798-1-paul.elder@ideasonboard.com>\n\t<20201029101629.61798-2-paul.elder@ideasonboard.com>\n\t<d5df601b-a988-59c6-2a9d-ca2caeb8f786@ideasonboard.com>\n\t<20201029103431.GA3974@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8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HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<1f984666-eb63-c622-4dfa-7722da9e553c@ideasonboard.com>","Date":"Thu, 29 Oct 2020 10:37:18 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<20201029103431.GA3974@pendragon.ideasonboard.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","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>","Reply-To":"kieran.bingham@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":13558,"web_url":"https://patchwork.libcamera.org/comment/13558/","msgid":"<20201029233911.GL15024@pendragon.ideasonboard.com>","date":"2020-10-29T23:39:11","subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\nOn Thu, Oct 29, 2020 at 07:16:24PM +0900, Paul Elder wrote:\n> Implement tracing infrastructure in libcamera. It takes .tp files, as\n> required by lttng, and generates a tracepoint header and C file, as lttng\n> requires. meson is updated accordingly to get it to compile with the\n> rest of libcamera. Update the documentation accordingly.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> ---\n> Changes in v3:\n> - rename the tracepoints header generateor in meson\n> - add protection against accidental unused variables when tracing is\n>   disabled\n> - make gen-tp-header.py read files as utf-8\n> - add macros LIBCAMERA_TRACEPOINT_IPA_{BEGIN,END}\n> \n> Changes in v2:\n> - move header.tmpl to tracepoints.h.in\n> - rename meson option 'tracepoints' to 'tracing'\n> - make sure C++ objects work in tracepoint arguments\n> - rename generate_header.py to gen-tp-header.py\n> ---\n>  Documentation/Doxyfile.in                     |  2 +\n>  README.rst                                    |  3 +\n>  include/libcamera/internal/meson.build        |  9 +++\n>  include/libcamera/internal/tracepoints.h.in   | 62 +++++++++++++++++++\n>  .../internal/tracepoints/meson.build          |  4 ++\n>  meson.build                                   |  3 +\n>  meson_options.txt                             |  5 ++\n>  src/libcamera/meson.build                     |  7 +++\n>  src/libcamera/tracepoints.cpp                 | 10 +++\n>  utils/meson.build                             |  1 +\n>  utils/tracepoints/gen-tp-header.py            | 38 ++++++++++++\n>  utils/tracepoints/meson.build                 |  5 ++\n>  12 files changed, 149 insertions(+)\n>  create mode 100644 include/libcamera/internal/tracepoints.h.in\n>  create mode 100644 include/libcamera/internal/tracepoints/meson.build\n>  create mode 100644 src/libcamera/tracepoints.cpp\n>  create mode 100644 utils/tracepoints/gen-tp-header.py\n>  create mode 100644 utils/tracepoints/meson.build\n> \n> diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\n> index 5ccd0d05..9a7a3fb4 100644\n> --- a/Documentation/Doxyfile.in\n> +++ b/Documentation/Doxyfile.in\n> @@ -842,6 +842,8 @@ EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/ipa_ipc_unixsocket.cpp \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n>  \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n> +\t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\n> +\t\t\t @TOP_BUILDDIR@/include/libcamera/internal/tracepoints.h \\\n>  \t\t\t @TOP_BUILDDIR@/include/libcamera/ipa/ \\\n>  \t\t\t @TOP_BUILDDIR@/src/libcamera/proxy/\n>  \n> diff --git a/README.rst b/README.rst\n> index fc8f4948..5c4b6989 100644\n> --- a/README.rst\n> +++ b/README.rst\n> @@ -81,6 +81,9 @@ for gstreamer: [optional]\n>  for qcam: [optional]\n>  \tqtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\n>  \n> +for tracing with lttng: [optional]\n> +        lttng-ust-dev python3-jinja2\n> +\n>  Using GStreamer plugin\n>  ~~~~~~~~~~~~~~~~~~~~~~\n>  \n> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\n> index 8dd744fd..592635a9 100644\n> --- a/include/libcamera/internal/meson.build\n> +++ b/include/libcamera/internal/meson.build\n> @@ -1,5 +1,14 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n> +subdir('tracepoints')\n> +\n> +libcamera_tracepoint_header = custom_target(\n> +    'tp_header',\n> +    input: [ 'tracepoints.h.in', tracepoint_files ],\n> +    output: 'tracepoints.h',\n> +    command: [ gen_tracepoints_header, '@OUTPUT@', '@INPUT@' ],\n> +)\n> +\n>  libcamera_internal_headers = files([\n>      'byte_stream_buffer.h',\n>      'camera_controls.h',\n> diff --git a/include/libcamera/internal/tracepoints.h.in b/include/libcamera/internal/tracepoints.h.in\n> new file mode 100644\n> index 00000000..830c61d7\n> --- /dev/null\n> +++ b/include/libcamera/internal/tracepoints.h.in\n> @@ -0,0 +1,62 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) {{year}}, Google Inc.\n> + *\n> + * tracepoints.h - Tracepoints with lttng\n> + *\n> + * This file is auto-generated. Do not edit.\n> + */\n> +#ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> +#define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__\n> +\n> +#if HAVE_TRACING\n> +#define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \\\n> +tracepoint(libcamera, ipa_call_begin, #pipe, #func)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \\\n> +tracepoint(libcamera, ipa_call_end, #pipe, #func)\n> +\n> +#else\n> +\n> +namespace {\n> +\n> +template <typename ...Args>\n> +inline void unused([[maybe_unused]] Args&& ...args)\n> +{\n> +}\n> +\n> +} /* namespace */\n> +\n> +#define LIBCAMERA_TRACEPOINT(category, ...) unused(__VA_ARGS__)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) unused(#pipe, #func)\n> +\n> +#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) unused(#pipe, #func)\n\nAs mentioned in a separate e-mail, you only need unused() for\nLIBCAMERA_TRACEPOINT.\n\n> +\n> +#endif /* HAVE_TRACING */\n> +\n> +#endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */\n> +\n> +\n> +#if HAVE_TRACING\n> +\n> +#undef TRACEPOINT_PROVIDER\n> +#define TRACEPOINT_PROVIDER libcamera\n> +\n> +#undef TRACEPOINT_INCLUDE\n> +#define TRACEPOINT_INCLUDE \"{{path}}\"\n> +\n> +#if !defined(INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)\n> +#define INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H\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> diff --git a/include/libcamera/internal/tracepoints/meson.build b/include/libcamera/internal/tracepoints/meson.build\n> new file mode 100644\n> index 00000000..2dd6733e\n> --- /dev/null\n> +++ b/include/libcamera/internal/tracepoints/meson.build\n> @@ -0,0 +1,4 @@\n> +# SPDX-License-Identifier: CC0-1.0\n> +\n> +tracepoint_files = files([\n> +])\n> diff --git a/meson.build b/meson.build\n> index e6f6c84a..55cf36e1 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -108,6 +108,9 @@ libcamera_includes = include_directories('include')\n>  # Sub-directories fill py_modules with their dependencies.\n>  py_modules = []\n>  \n> +# Libraries used by multiple components\n> +liblttng = cc.find_library('lttng-ust', required : get_option('tracing'))\n> +\n>  # Utilities are parsed first to provide support for other components.\n>  subdir('utils')\n>  \n> diff --git a/meson_options.txt b/meson_options.txt\n> index 7f7b3e59..53f2675e 100644\n> --- a/meson_options.txt\n> +++ b/meson_options.txt\n> @@ -28,6 +28,11 @@ option('test',\n>          type : 'boolean',\n>          description: 'Compile and include the tests')\n>  \n> +option('tracing',\n> +        type : 'feature',\n> +        value : 'auto',\n> +        description: 'Enable tracing (based on lttng)')\n> +\n>  option('v4l2',\n>          type : 'boolean',\n>          value : false,\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 24f7ea3d..51925bd6 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -58,6 +58,7 @@ libcamera_sources = files([\n>  \n>  libcamera_sources += libcamera_public_headers\n>  libcamera_sources += libcamera_generated_ipa_headers\n> +libcamera_sources += libcamera_tracepoint_header\n>  \n>  includes = [\n>      libcamera_includes,\n> @@ -75,6 +76,11 @@ if libgnutls.found()\n>      config_h.set('HAVE_GNUTLS', 1)\n>  endif\n>  \n> +if liblttng.found()\n> +    config_h.set('HAVE_TRACING', 1)\n> +    libcamera_sources += files(['tracepoints.cpp'])\n> +endif\n> +\n>  if libudev.found()\n>      config_h.set('HAVE_LIBUDEV', 1)\n>      libcamera_sources += files([\n> @@ -117,6 +123,7 @@ libcamera_deps = [\n>      libatomic,\n>      libdl,\n>      libgnutls,\n> +    liblttng,\n>      libudev,\n>      dependency('threads'),\n>  ]\n> diff --git a/src/libcamera/tracepoints.cpp b/src/libcamera/tracepoints.cpp\n> new file mode 100644\n> index 00000000..0173b75a\n> --- /dev/null\n> +++ b/src/libcamera/tracepoints.cpp\n> @@ -0,0 +1,10 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2020, Google Inc.\n> + *\n> + * tracepoints.cpp - Tracepoints with lttng\n> + */\n> +#define TRACEPOINT_CREATE_PROBES\n> +#define TRACEPOINT_DEFINE\n> +\n> +#include \"libcamera/internal/tracepoints.h\"\n> diff --git a/utils/meson.build b/utils/meson.build\n> index 383d5285..8e28ada7 100644\n> --- a/utils/meson.build\n> +++ b/utils/meson.build\n> @@ -2,6 +2,7 @@\n>  \n>  subdir('ipc')\n>  subdir('ipu3')\n> +subdir('tracepoints')\n>  \n>  ## Code generation\n>  py_modules += ['yaml']\n> diff --git a/utils/tracepoints/gen-tp-header.py b/utils/tracepoints/gen-tp-header.py\n> new file mode 100644\n> index 00000000..9500e474\n> --- /dev/null\n> +++ b/utils/tracepoints/gen-tp-header.py\n> @@ -0,0 +1,38 @@\n> +#!/usr/bin/env python3\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +# Copyright (C) 2020, Google Inc.\n> +#\n> +# Author: Paul Elder <paul.elder@ideasonboard.com>\n> +#\n> +# gen-tp-header.py - Generate header file to contain lttng tracepoints\n> +\n> +import datetime\n> +import jinja2\n> +import os\n> +import sys\n> +\n> +def main(argv):\n> +    if len(argv) < 3:\n> +        print(f'Usage: {argv[0]} output template tp_files...')\n> +        return 1\n> +\n> +    output = argv[1]\n> +    template = argv[2]\n> +\n> +    year = datetime.datetime.now().year\n> +    path = output.replace('include/', '', 1)\n> +\n> +    source = ''\n> +    for fname in argv[3:]:\n> +        source += open(fname, 'r', encoding='utf-8').read() + '\\n\\n'\n> +\n> +    template = jinja2.Template(open(template, 'r').read())\n\nutf-8 here too, and below ?\n\n> +    string = template.render(year=year, path=path, source=source)\n> +\n> +    f = open(output, 'w').write(string)\n> +\n> +    return 0\n> +\n> +\n> +if __name__ == '__main__':\n> +    sys.exit(main(sys.argv))\n> diff --git a/utils/tracepoints/meson.build b/utils/tracepoints/meson.build\n> new file mode 100644\n> index 00000000..807230fc\n> --- /dev/null\n> +++ b/utils/tracepoints/meson.build\n> @@ -0,0 +1,5 @@\n> +# SPDX-License-Identifier: CC0-1.0\n> +\n> +py_modules += ['jinja2']\n> +\n> +gen_tracepoints_header = find_program('./gen-tp-header.py')","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 914FBBDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 29 Oct 2020 23:40:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EE727628F5;\n\tFri, 30 Oct 2020 00:40:02 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B6F9D61563\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 30 Oct 2020 00:40:00 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 208349B7;\n\tFri, 30 Oct 2020 00:40:00 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"O/tmm6qw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1604014800;\n\tbh=wipxn5qb5X+e3yPTJV5UBfEIDUBomuva0N3G2mXh7L8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=O/tmm6qwlqpNG65ZRDKtnEcIEfQ6zyTCp+862grGyPCSBJsaD3CHrOcFlDiD25y0s\n\tHcmNhrjQmMQ+YtTRRWS+03rBT+kSvJ/mO4eGpmSAyxq42Mmk1BM4n4Pt6hrS7cBSkr\n\tKc5YPVh1JIzXgZgZa1Za4QsxSGSWdE2TDWQlOLac=","Date":"Fri, 30 Oct 2020 01:39:11 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20201029233911.GL15024@pendragon.ideasonboard.com>","References":"<20201029101629.61798-1-paul.elder@ideasonboard.com>\n\t<20201029101629.61798-2-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201029101629.61798-2-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 1/6] libcamera: tracing: Implement\n\ttracing infrastructure","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]