~roguescholar/babeltrace/+git/github:master

Last commit made on 2025-12-04
Get this branch:
git clone -b master https://git.launchpad.net/~roguescholar/babeltrace/+git/github

Branch merges

Branch information

Name:
master
Repository:
lp:~roguescholar/babeltrace/+git/github

Recent commits

eec90e0... by .eepp

Fix: src.ctf.lttng-live: handle inconsistent stream class ID gracefully

Replace BT_ASSERT() with proper error handling when validating stream
class IDs received from the relay daemon. Since this is external network
data, inconsistent values should result in a graceful error rather than
an assertion failure which can, amongst other things, crash your whole
application if you're building a graph with libbabeltrace2 (or with the
Python bindings).

We ran into this within an LTTng-tools test when a change in LTTng-UST
merely changed the order in which data indexes vs. inactive stream
beacons happen, exposing an already present issue in the relay daemon.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: I9396fb4157e9e32b12dc26fb49e0bfb537dcc5ef
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15761

e2580bc... by .eepp

lib: add `LIBBABELTRACE2_FORCE_COMPONENT_LOG_LEVEL` support

The new `LIBBABELTRACE2_FORCE_COMPONENT_LOG_LEVEL` environment variable
makes it possible to force the log level of all or specific components
added to any trace processing graph.

Its value is one of:

• A single log level value.

  In this case, libbabeltrace2 overrides the log level specified when
  adding _any_ component to any trace processing graph.

• A semicolon-delimited list of `PAT:LEVEL` specifiers.

  `PAT` is a globbing pattern where only the wildcard character, `*`,
  is special: it matches zero or more characters.

  `LEVEL` is a log level value.

  In this case, libbabeltrace2 overrides the log level specified when
  adding a component of which the name matches `PAT` to any trace
  processing graph.

The accepted log level values are the same as
with `LIBBABELTRACE2_INIT_LOG_LEVEL`.

libbabeltrace2 dynamically checks this environment variable before
adding a component to a trace processing graph, meaning you can modify
it at any time with setenv(3).

Example:

    *ctf*:I;my-sink:D;*:W

This is useful for quick debugging when you don't control the component
additions, for example when using `bt2.TraceCollectionMessageIterator`
with an automatically discovered component. I added it at the
libbabeltrace2 level to make this available to any component addition.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: I4de174e57d747450ac379071aa25ef14fbec4b51
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15674

ce8a1cf... by .eepp

Fix: bt2.TraceCollectionMessageIterator: avoid circular reference

OBSERVED ISSUE
━━━━━━━━━━━━━━
A `bt2.TraceCollectionMessageIterator` instance isn't deterministically
garbage-collected when losing its last reference.

This means the graph and all its components (and their resources,
including file descriptors) stay alive until a cyclic garbage
collection occurs.

For example, consider this simple script:

    import os
    import bt2

    def _event_count(trace_path):
        msg_iter = bt2.TraceCollectionMessageIterator(trace_path)
        event_count = 0

        for msg in msg_iter:
            event_count += isinstance(msg, bt2._EventMessageConst)

        return event_count

    def _main():
        for i in range(100):
            print(f"Iteration #{i + 1}")

            fd_count = len(os.listdir(f'/proc/{os.getpid()}/fd'))

            print(f' {fd_count} FDs')
            print(f' {_event_count("/path/to/trace")} event records')
            print()

    _main()

Result:

    Iteration #1
      4 FDs
      64 event records

    Iteration #2
      7 FDs
      64 event records

    Iteration #3
      10 FDs
      64 event records

    ✂️ ✂️ ✂️

    Iteration #94
      283 FDs
      64 event records

    Iteration #95
      286 FDs
      64 event records

    Iteration #96
      7 FDs
      64 event records

    Iteration #97
      10 FDs
      64 event records

    ✂️ ✂️ ✂️

The number of FDs keeps incrementing, until there's a cyclic GC which
breaks the cycles.

This works here, but add more data stream files and you quickly run into
some "Too many open files" error.

CAUSE
━━━━━
Consider how `bt2.TraceCollectionMessageIterator` (TCMI) works before
this patch:

1. `bt2.TraceCollectionMessageIterator` creates a `bt2.Graph` instance
   and stores it as `self._graph`.

2. The TCMI registers itself as a listener:

       self._graph.add_port_added_listener(self._graph_port_added)

3. The graph stores this bound method in `self._listener_partials`.

4. The bound TCMI method (self._graph_port_added()) keeps a reference
   back to the TCMI instance.

Result:

    ┌──────────────────────────────────────────────────────────────────┐
    ↓ │
    TCMI → `_graph` → `_listener_partials` → self._graph_port_added() ─┘

There's your cycle.

SOLUTION
━━━━━━━━
Use a `weakref.WeakMethod` (available since Python 3.4) to wrap
self._graph_port_added() to break the cycle.

This is also logically safe because we really only need this listener
during the _build_graph() phase.

Removing the listener would also work, but there's no
bt2.Graph.remove_port_added_listener() currently.

With this patch:

    Iteration #1
      4 FDs
      64 event records

    Iteration #2
      4 FDs
      64 event records

    Iteration #3
      4 FDs
      64 event records

    ✂️ ✂️ ✂️

    Iteration #98
      4 FDs
      64 event records

    Iteration #99
      4 FDs
      64 event records

    Iteration #100
      4 FDs
      64 event records

KNOWN DRAWBACKS
━━━━━━━━━━━━━━━
None.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: Ifa37efe01dd445d53fedd862689bb4e6efc8f244
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15673
Reviewed-by: Simon Marchi <email address hidden>
Tested-by: jenkins <email address hidden>

9936246... by .eepp

Fix: test_mip1.py: skip without Python plugins

The test needs to find the `trace-ir-test` plugin, a Python plugin.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: I6c4cd3b6d0e0824a83628d3ed289aa784f24d5dd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15695

402f4d0... by .eepp

Fix: tests/plugins/src.ctf.lttng-live/test-query.sh: `utils.sh` path

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: Id81347afd79dd79acbacb8437afe6798a5f537ba
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15686

b09aa30... by Simon Marchi <email address hidden>

tests/bindings: fix PackageTestCase always testing the same attribute

The way this test is written is not good. The function `test_func`,
defined inside the loop, does not capture the current value of `name`.
All test methods therefore test with the same `name` value. I confirmed
this with a print inside `PackageTestCase._assert_in_bt2`.

Change it to have an external function that returns the function to use
as the test method. This way, each test method will refer to its own
`name`.

I found this because I happened to have "flake8-bugbear" installed
locally, and flake8 showed this warning:

    ./test_package.py:309:29: B023 Function definition does not bind loop variable 'name'.

Change-Id: I97a1a417801f55a822279068306f4d1ccdc8c801
Signed-off-by: Simon Marchi <email address hidden>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15247
Tested-by: jenkins <email address hidden>
Reviewed-by: Philippe Proulx <email address hidden>

515d68a... by Simon Marchi <email address hidden>

pre-commit autoupdate

Run `pre-commit autoupdate` to bump the versions of the
linting/formatting tools.

The black version used to be limited by the Debian or Ubuntu version on
the CI. Now that the workers run the bleeding edge Debian 13, let's try
to go to the latest version.

flake8 complains with warnings such as:

    src/bindings/python/bt2/bt2/graph.py:61:5: E704 multiple statements on one line (def)

It doesn't like the "..." that black now puts on the same line as the
function signature. The formatting is dictated by black, so ignore that
warning.

Change-Id: I7e76a0dcb7fe4f17e66911bb558dbf0610608122
Signed-off-by: Simon Marchi <email address hidden>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15244
Reviewed-by: Philippe Proulx <email address hidden>
Tested-by: jenkins <email address hidden>

635a7c3... by Kienan Stewart

misc: Bump clang-format version to 19

Change-Id: Iea0436b9c2db45f3e518eae34142365c642d18c2
Signed-off-by: Kienan Stewart <email address hidden>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/15207
Reviewed-by: Simon Marchi <email address hidden>

343ace3... by .eepp

doc/internal: document `src/cpp-common/bt2`

This patch adds partial documentation for what's "internally public" in
`src/cpp-common/bt2`.

Documenting all the files, types, and functions would be a very tedious
task because it's equivalent to the effort of documenting the whole
libbabeltrace2 C API. That being said, most of the `bt2` namespace is
straightforward if you already know the libbabeltrace2 C API.

I documented what might be less obvious to understand, namely:

• In `all.dox`:

  ‣ Quick start to show how the C++ bindings work in general.
  ‣ Gneral terminology.
  ‣ Borrowed object wrapper, optional wrapper.
  ‣ Shared object, reference counting, creation.
  ‣ How to create a new wrapper class.
  ‣ C++ component class development: usage and internals.
  ‣ C++ plugin development.

• The `bt2::BorrowedObjectIterator` class template.

• The `bt2::BorrowedObjectProxy` class template.

• The `bt2::BorrowedObject` class template.

• The `bt2::OptionalBorrowedObject` class template.

• The whole `component-class-dev.hpp` header.

• The whole `error.hpp` header.

• Exception classes in `exc.hpp`.

• The bt2::internal::validateCreatedObjPtr() function.

• The `bt2::ConstMessageArray` class.

• The `bt2::SharedObject` class template.

• The `type-traits.hpp` header.

• The `wrap.hpp` header.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: I0c22d7adef99b0b5f711ae6582ba2f947445ef03
Reviewed-on: https://review.lttng.org/c/babeltrace/+/14037

327d524... by .eepp

bt2::Graph: add user component class instantiation methods

This patch adds new templated bt2::Graph::addComponent() methods.

Those new ones are a combination of the existing addComponent() ones
and bt2::createComponentClass(), for example:

    const auto myComp = myGraph.addComponent<MyFilterComp>("meow",
                                                           params);

This is intended for simple use cases where you instantiate a component
class only once within the graph. Otherwise, it's still preferred to
create a component class first and then instantiate this one multiple
times with the non-templated bt2::Graph::addComponent() overload.

Signed-off-by: Philippe Proulx <email address hidden>
Change-Id: I3fa90761bb9c3622c2d18f3ea3b7adb96f5d371c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/14036