babeltrace.git
6 weeks agoccv: adjust for MIP 1
Simon Marchi [Fri, 4 Oct 2024 15:10:08 +0000 (11:10 -0400)] 
ccv: adjust for MIP 1

Adjust the clock correlation validation code for MIP 1.

The high level conceptual changes to adapt to are:

 - With MIP 0, the only way to have a known clock origin is for it to be
   the Unix epoch.  In MIP 1, it's possible to have known user-defined
   clock origins.

 - With MIP 0, clock classes are optionally identified with UUIDs.  With
   MIP 1, it's with a (namespace, name, UID) tuple.

The concrete changes are:

 - Pass the MIP version down to
   `ClockCorrelationValidator::validate()`and
   `bt_clock_correlation_validator_validate_message()`.

 - Rename enumerators

   - Unix epoch -> Known origin
   - UUID -> ID (which comprises both UUIDs and (namespace, name, UID)
     tuples)

 - Adjust ClockCorrelationValidator::_validate() where the logic differs
   between MIP 0 and 1.

 - Adjust the error messages given by clients of
   `ClockCorrelationValidator` to reflect the differences between MIP 0
   and 1.

 - Make `MessageComparator` take a graph MIP version, change the way
   `MessageComparator::compare()` compares trace identities based on the
   MIP version.

 - Adjust tests checking clock compatibility problems to run with MIP 0
   and 1, using the right kind of identity depending on the MIP version.

Change-Id: I12a5b5bed27fe6185ab407465901d285cbb23778
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12785
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agotests: disable coredumps in `conds-trigger`
Simon Marchi [Tue, 8 Oct 2024 15:52:41 +0000 (11:52 -0400)] 
tests: disable coredumps in `conds-trigger`

After adding some more tests in `conds-trigger`, some CI jobs would
start to fail randomly while running that test, with the Jenkins runner
process seemingly crashing.  Digging a little bit revealed that many
processes (including `systemd-coredump`) would get OOM-killed.

What I think happens is that the many quickly crashing `conds-triggers`
processes cause many `systemd-coredump` processes to get started, which
causes too much memory to be consumed.

It's just wasteful to generate core dumps while running this test
anyway, so disable them.  Use `setrlimit()` in the code path that we
know is going to lead to a crash.

I considered calling `ulimit -c 0` in the bash script that calls all
this, but I would prefer to disable core dumps in the narrowest scope
possible, so that we don't disable them for the code that's not supposed
to crash.

Change-Id: I69bf206cf0afed26f6db65e7fb7e70e9dbe7c053
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13325
Reviewed-by: Kienan Stewart <kstewart@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoiterator.c, muxer: tweak clock compatibility validation error messages
Simon Marchi [Tue, 10 Sep 2024 19:45:40 +0000 (15:45 -0400)] 
iterator.c, muxer: tweak clock compatibility validation error messages

In general, make the prose part of the messages be a bit more in line
with the enumerator names, which usually ends up a bit more specific
than the current messages.

In muxer's msg-iter.cpp:

 - Split the ExpectingOriginUnixGotNone,
   ExpectingOriginUnknownWithUuidGotNone and
   ExpectingOriginUnknownWithoutUuidGotNone, to provide slightly more
   precise error messages about what kind of clock class is expected.

 - Always include the stream class information, whenever there is a
   stream class (message iterator inactivity messages don't have an
   associated stream class).  Factor this out in a `formatStreamCls`
   lambda.

 - Factor out the formatting of the clock class info, and print an
   additional `clock-class-origin-is-unix-epoch` and `clock-class-uuid`
   fields.  This factorisation will be helpful when adding support for
   MIP 1, since the fields to format will change.  We will need to
   update fewer places.

In iterator.c:

 - Print the actual clock class info in a few more places.

 - Change phrases like "has non Unix epoch origin" for "has unknown
   origin", both in human-readable messages and conditions IDs.

 - Tweak the "Expecting a clock class, got none." messages to be a bit
   more specific, differentiating the three cases.

 - Print the expected UUID whenever we expect a clock class with a
   specific UUID.

Instead of cherry-picking the information we print for each case, we
could also print the entire reference clock class information (making it
clear that we don't necessarily expect this particular clock class
instance, perhaps with a `reference-` prefix).  It would probably make
the implementation simpler, but it would print a bit more unnecessary
information.  The user would have to infer from the error message what
is the relevant information in there.  I don't have a strong preference
for either approach.

Change-Id: I0ce2ab5b146a79baa5aa0afbd9d5de4f79f283a1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12784
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoccv: rename error type enumerators
Simon Marchi [Fri, 3 May 2024 15:18:51 +0000 (11:18 -0400)] 
ccv: rename error type enumerators

In the names of enumerators:

 - Replace "other" with "unknown" when referring to origins in clock
   correlation validator error types.

   The origin of a clock class is either known or unknown.  As of MIP 0,
   the only way for a clock class origin to be known is for it to be the
   Unix epoch, so it's really either Unix epoch or unknown.

   With MIP 1, it will become possible to have known origins that are
   not the Unix epoch.  Using the term "unknown" here makes it clear
   that we are not talking about that.

 - Replace "origin uuid" with "origin unknown with uuid", "origin no
   uuid" with "origin unknown without uuid".  The formers make it sound
   like the origins have UUIDs, which is not the case.  The clock class
   (which is implied in the name) has a UUID.

 - Make the enumerators extra explicit to avoid any ambiguity.

Change-Id: I4e9f9e6caf4e09de2ff1a2d26fe10a1a5f343453
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12783
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoccv: output reference clock class on error
Simon Marchi [Mon, 9 Sep 2024 19:44:08 +0000 (15:44 -0400)] 
ccv: output reference clock class on error

On validation error, always output the clock class used as a reference.
In combination with the error type, the callers will be able to inspect
the reference clock class to obtain the details needed to generate the
appropriate error message.

The goal of this change is to avoid having to add many output parameters
when adding support for MIP 1, keeping things simpler.

Change-Id: I032cc706d586134a35aabd14d9fb00611b430ad0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12782
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoflt.utils.muxer: rename local variable
Simon Marchi [Mon, 9 Sep 2024 19:42:07 +0000 (15:42 -0400)] 
flt.utils.muxer: rename local variable

Change-Id: If716499dd9e9f8bf0311fb314919341516823c53
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13255
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 weeks agotests/lib/conds: change `CreateClockCls` type to `std::function`
Simon Marchi [Thu, 2 May 2024 15:25:33 +0000 (11:25 -0400)] 
tests/lib/conds: change `CreateClockCls` type to `std::function`

The `CreateClockCls` callable type is currently a raw function pointer.
An upcoming patch will want to pass lambdas with captures, so change
`CreateClockCls` to be `std::function` instead.  Update the
`CreateClockCls` parameters to be non-const where we want to move the
value, and const-ref otherwise.

Remove the `noClockClass` function, and use an empty `CreateClockCls` to
mean "do not create a clock class".  I couldn't find how to do the
equivalent of the `createClockCls == noClockClass` with an
`std::function`, but using an empty `std::function` is clear enough (we
could have done it with a nullptr before too).

Change-Id: Ie30e42b68b5ffad566458933869e78da8ca01614
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12781
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agotests: make `runIn()` accept a MIP version
Simon Marchi [Wed, 1 May 2024 21:18:54 +0000 (17:18 -0400)] 
tests: make `runIn()` accept a MIP version

Make `runIn()` and `RunInCondTrigger` accept a MIP version to use when
creating the graph, instead of using 0.  Update existing users to pass a
hardcoded 0.

Add a `forEachMipVersion()` utility function, which calls a callback
once for each possible MIP version.  This is intended to help code that
wants to try testing variations of the same thing for all possible MIP
version.

Change-Id: Ic1d42d20b4eef872106f216fea9d2e883cb33775
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12780
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agotest/lib/conds: use `:` to concatenate trigger name suffix
Simon Marchi [Wed, 1 May 2024 21:29:20 +0000 (17:29 -0400)] 
test/lib/conds: use `:` to concatenate trigger name suffix

For cosmetic (and obviously subjective reasons), use `:` when
appending a trigger name suffix.

Example:

    -message-iterator-class-next-method:clock-class-is-expected-mii-mii
    +message-iterator-class-next-method:clock-class-is-expected:mii-mii

I like it because it's now of the form:

    <function name>:<cond id>:<suffix>

... where the suffix discriminates different triggers to reach the
pre/post condition identified by `<function name>:<cond id>`.  When the
suffix is concatenated using `-`, it's not clear where the cond id ends.

Change-Id: I9e27524a589f19094eb90543d500d015a985a123
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12779
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 weeks agoflt.utils.muxer: subjective re-format
Simon Marchi [Wed, 1 May 2024 20:51:43 +0000 (20:51 +0000)] 
flt.utils.muxer: subjective re-format

Wrap arguments to `BT_CPPLOGE_APPEND_CAUSE_AND_THROW` so that we can
have slightly longer strings (still within 100 columns).  Remove
unnecessary local variables.

Change-Id: If7412e6913d06d12142f01e09742d4d6a5dc5d0e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12505
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 weeks agotests/lib/conds: run pre-cond test by name
Simon Marchi [Tue, 30 Apr 2024 17:31:39 +0000 (17:31 +0000)] 
tests/lib/conds: run pre-cond test by name

Change `conds-trigger` to run triggers by name, instead of by index.
This makes it easier to run an arbitrary trigger by hand, when
developing.

Example:

    $ tests/lib/conds/conds-triggers list | python3 -m json.tool
    ...
    {
        "cond-id": "pre:field-class-integer-set-field-value-range:valid-n",
        "name": "field-class-integer-set-field-value-range:valid-n-gt-64"
    },
    ...
    $ tests/lib/conds/conds-triggers run field-class-integer-set-field-value-range:valid-n-gt-64
    <abort message>

Update the `test.py` driver to match.  Update it also to output the
trigger name in a TAP comment before each test, to make it easier for a
developer to run a failing test by hand.

Example:

    $ tests/lib/conds/test-conds.sh
    # Running trigger `field-class-integer-set-field-value-range:not-null:field-class`
    # TAP results for LibPrePostCondsTestCase
    ok 1 - test_field_class_integer_set_field_value_range_not_null_field_class (test.LibPrePostCondsTestCase.test_field_class_integer_set_field_value_range_not_null_field_class)
    # Running trigger `field-class-integer-set-field-value-range:valid-n-0`
    ok 2 - test_field_class_integer_set_field_value_range_valid_n_0 (test.LibPrePostCondsTestCase.test_field_class_integer_set_field_value_range_valid_n_0)
    # Running trigger `field-class-integer-set-field-value-range:valid-n-gt-64`
    ok 3 - test_field_class_integer_set_field_value_range_valid_n_gt_64 (test.LibPrePostCondsTestCase.test_field_class_integer_set_field_value_range_valid_n_gt_64)

Note the little quirk that the `Running trigger` comment is displayed
before the `TAP results for ...` comment.  The latter is displayed when
the first result is recorded, so I'm not sure how to fix this, but I
don't think it's really a problem as it is.

Since the test name is now a used as a key, modify `condMain()` to check
that the test names passed in the `condTriggers` vectors are unique.  If
there is a duplicate name, we get:

    $ tests/lib/conds/conds-triggers list
    Duplicate test name `field-class-integer-set-field-value-range:valid-n-0`

Ensuring unique names would have probably been useful anyway, since we
generate Python methods based on that name, so we don't want any
clashes.

Change-Id: Ie05ad4070d9ea859e0678ee1cf5ed1c4010f9829
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12503
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoplugins/common/muxing: C++ify
Simon Marchi [Thu, 9 May 2024 21:11:49 +0000 (17:11 -0400)] 
plugins/common/muxing: C++ify

Change the code to be more idiomatic C++.  I tried to keep the overall
logic identical.

The pattern where we look for the presence of both objects to compare
(when we compare things that are optional) comes back often, so factor
this out in a `_compareOptional` function.

Similarly, comparing strings that can be null comes back often, factor
this out in a `_compareStrings` function.

The existing code isn't consistent about how to order things, when
comparing one empty/null and one non-empty/non-null object.  Sometimes,
the empty object goes first, sometimes the non-empty object goes first.
By factoring out these two functions, the message ordering changes
slightly in some cases.  I found two test cases that needed to be updated:

 - flt.utils.muxer/succeed/diff-stream-class-no-name.expect
 - flt.utils.muxer/succeed/diff-stream-no-name.expect

It happens often that we want to compare and order scalar value.  Factor
this out in a `_compareLt` templated function.  The starship operator
from C++20 could probably replace this, in a distant future.

Otherwise the rest should be pretty straightforward it's the same logic
as before.

Change-Id: If372de51ff5584d17705a0aed5597cea750597fa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12565
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 weeks agoplugins/common/muxing: compile as C++
Simon Marchi [Thu, 9 May 2024 17:02:43 +0000 (13:02 -0400)] 
plugins/common/muxing: compile as C++

Rename the files, re-format, and adjust files including `muxing.h`.

Change-Id: Idf16a80e1950c44a9212d3f80e690446e614c662
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12564
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 weeks agocli: add `--allowed-mip-versions` option to restrict MIP version
Mathieu Desnoyers [Wed, 10 Apr 2024 15:46:27 +0000 (11:46 -0400)] 
cli: add `--allowed-mip-versions` option to restrict MIP version

Introduce a new "--allowed-mip-versions=VER" command line argument
to babeltrace2. By default, versions 0 and 1 are allowed (prior behavior
before this patch). It allows specifying that either version 0 or 1 are
to be allowed in the graph. Its main purpose is for testing
implementation of plugin components interactions for specific MIP
versions.

Philippe's changes to the original patch:

‣ Use `--allowed-mip-versions` instead of `--allowed-mip-version`: in
  the future we might want to make it possible to specify more than one
  version, for example `--allowed-mip-versions=0,1,5` or even
  `--allowed-mip-versions=0-2,5`.

  The current single-version format is to be considered an initial,
  temporary limitation.

‣ Use the short option `-m` for `--allowed-mip-versions`.

‣ Sort options alphabetically by long name in the output of `--help`.

‣ Updated the manual pages.

Change-Id: I1c9f74176f6686ec560ede2494b89e28f35da6a6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12792
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agopyproject.toml: pyright: ignore reportPrivateUsage
Simon Marchi [Wed, 2 Oct 2024 03:07:07 +0000 (23:07 -0400)] 
pyproject.toml: pyright: ignore reportPrivateUsage

Our code does not follow the convention of treating identifiers starting
with an underscore as private.  For instance, the `bt2` module exposes
types like `_EventMessageConst`.  Even though the user is not expected
to create objects of that type, they can still use the type in a type
check like:

    if type(msg) is bt2._EventMessageConst:

That produces a `reportPrivateUsage` in pyright / pylance.  Disable that
check to get rid of a lot of false positives.

Change-Id: I78a19653aafb923d3e429b9b321cb1f87372c83e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13307
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agoAdd .pre-commit-config.yaml
Simon Marchi [Fri, 30 Aug 2024 19:32:33 +0000 (15:32 -0400)] 
Add .pre-commit-config.yaml

This can help catch problems a bit earlier than in the CI.

To use it, a developer would run `pre-commit` in the source repository.
This installs git commit hooks that will run the checks described by
`.pre-commit-config.yaml` on the modified files.

It is possible to run the checks on all files with:

    $ pre-commit run --all-files
    black....................................................................Passed
    flake8...................................................................Passed
    isort....................................................................Passed

Change-Id: I695f0b0f2fea3adadae132ceb708928db3217e0c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13202
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agotools: do not distribute development files in tarball
Simon Marchi [Fri, 4 Oct 2024 15:14:10 +0000 (11:14 -0400)] 
tools: do not distribute development files in tarball

Linters scripts are not useful to have in tarballs, as nobody is
expected to do development outside of a git tree.

Anyway, as of today, don't distribute `.clang-format`, so
`tools/format-cpp.sh` is useless in a tarball as it is.

Change-Id: I9f0aaebbe47390749c9be1085791ae09079519fe
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13318
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agolib: rename bt_clock_class_origin_is_{unknown,known}
Simon Marchi [Fri, 4 Oct 2024 15:06:11 +0000 (11:06 -0400)] 
lib: rename bt_clock_class_origin_is_{unknown,known}

The "is unknown" getter leads to double negatives:

    if (!bt_clock_class_origin_is_unknown(cls))

... which is not great for readability.  Rename to
bt_clock_class_origin_is_known().

Change-Id: I27a9c9fec80b0e23851ee62fd2c897a1c695d2b1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13317
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 weeks agotests/cli/test-intersection.sh: rewrite test to avoid shellcheck warning
Simon Marchi [Thu, 3 Oct 2024 15:20:21 +0000 (11:20 -0400)] 
tests/cli/test-intersection.sh: rewrite test to avoid shellcheck warning

Shellcheck 0.10.0 shows:

    $ shellcheck -x test-intersection.sh

    In test-intersection.sh line 36:
     ok $? "$totalevents events in the whole trace"
               ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.

    For more information:
      https://www.shellcheck.net/wiki/SC2319 -- This $? refers to a condition, no...

I think that Shellcheck is confused with what we're trying to do and
that the code is actually correct. Nevertheless, change the code to
circumvent this by using `is`, which looks nicer anyway.

This is not seen on the CI, since it currently runs Shellcheck 0.9.0.

Change-Id: I7bb861b478046ab327c5950c9deefa52953bc854
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13316
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 weeks ago.gitignore: add installed_files.txt
Simon Marchi [Fri, 13 Sep 2024 11:58:21 +0000 (07:58 -0400)] 
.gitignore: add installed_files.txt

This file gets generated when you run `make install` in the Python
bindings directory.

Change-Id: I0967276dac7a6277b0b6642e4ab73c1fecdd000d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13273
Tested-by: jenkins <jenkins@lttng.org>
2 months ago.gitignore: add some missing files
Erica Bugden [Wed, 21 Aug 2024 18:25:25 +0000 (14:25 -0400)] 
.gitignore: add some missing files

With this patch, doing:

    ./configure --enable-api-doc --enable-doxygen-doc --enable-man-pages --enable-python-bindings-doc --enable-python-bindings --enable-python-plugins
    make
    make dist

leaves a clean repo (no untracked files reported by `git status`).

Change-Id: Ifbe44eb0c93237dac933eeef3b39fabfa034601c
Signed-off-by: Erica Bugden <ebugden@efficios.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13224
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoflt.utils.muxer: add IWYU pragma
Simon Marchi [Mon, 9 Sep 2024 17:59:50 +0000 (13:59 -0400)] 
flt.utils.muxer: add IWYU pragma

clangd reports that the include of cpp-common/bt2c/fmt.hpp is unused,
but it is in fact used for the formatting of some types.  Add a pragma.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I43ebf7f7fc917f273ac6eaa88bf26790c83d9ead
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13254
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoFix: src.ctf.lttng-live: manually clear sessions vector in ~lttng_live_msg_iter()
Simon Marchi [Sat, 31 Aug 2024 02:39:50 +0000 (22:39 -0400)] 
Fix: src.ctf.lttng-live: manually clear sessions vector in ~lttng_live_msg_iter()

Starting with 751aaa6218f ("src.ctf.lttng-live: make
lttng_live_msg_iter::sessions an std::vector"), when live message
iterator gets destroyed while some stream iterators are still active, we
get this assertion:

    (╯°□°)╯︵ ┻━┻  /home/simark/src/babeltrace/src/plugins/ctf/lttng-live/lttng-live.cpp:153: ~lttng_live_msg_iter(): Assertion `this->active_stream_iter == 0` failed.

When a live message iterator completes successfully, by consuming
everything the relay has to offer until all stream iterators are ended,
there are no more active stream iterators when reaching
~lttng_live_msg_iter() (they all get destroyed by
next_stream_iterator_for_trace() when they end).  So the
`this->active_stream_iter == 0` assertion in the destructor holds.

But when an unexpected exit occurs, for instance because of an error or
a SIGINT interruption, the message iterator is destroyed while there are
still some stream iterators active.

Prior to 751aaa6218f, lttng_live_msg_iter_destroy() (which has since
been renamed to ~lttng_live_msg_iter()) had:

    if (lttng_live_msg_iter->sessions) {
        g_ptr_array_free(lttng_live_msg_iter->sessions, TRUE);
    }

Clearing the `sessions` array caused the `lttng_live_session` objects to
be destroyed, which caused the `lttng_live_trace` objects to be
destroyed, which caused the stream iterators to be destroyed.  When
reaching the assertion, the count of active stream iterators was
therefore 0.

With the refactor introduced by 751aaa6218f, we rely on the destruction
of the `sessions` vector for all this to happen, which occurs after the
user-specified destructor has run, therefore after the assertion.  At
the time the assertion is checked, there are still some stream iterators
alive.

Fix this by manually clearing the sessions vector before the assertion,
to mimic the old behavior.

Add a test that purposefully sends metadata with a syntax error, which
triggers the bug.

The change adding the `kill_server_on_cli_failure` parameter to
get_cli_output_with_lttng_live_server() is useful to avoid the test
script trying to kill the Python live server, in the new test.  Since
babeltrace successfully connects to the server and the disconnects, the
server exits on its own.  This would print a "kill 1234 failed: no such
process" message.  Not fatal, but not welcome either.  It's not pretty,
but it works.

Change-Id: Id777e7ac0294d89ea236dd05651c8fbe708b2be4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13204
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoctf: use self component / message iterator C++ wrappers throughout
Simon Marchi [Mon, 9 Sep 2024 17:27:42 +0000 (13:27 -0400)] 
ctf: use self component / message iterator C++ wrappers throughout

Use `bt2::SelfComponent`, `bt2::SelfSourceComponent`,
`bt2::SelfSinkComponent` and `bt2::SelfMessageIterator` for function
parameters and fields throughout `src/plugins/ctf` instead of raw
pointers.

Don't try to adapt the code too much to use the wrappers yet.

Change-Id: I2a3ae5849ef44fd639486185e5718919a152be93
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12416
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 months agosrc.ctf.lttng-live: add IWYU pragma
Simon Marchi [Mon, 9 Sep 2024 17:59:50 +0000 (13:59 -0400)] 
src.ctf.lttng-live: add IWYU pragma

clangd reports that the include of cpp-common/bt2c/fmt.hpp is unused,
but it is in fact used for the formatting of some types.  Add a pragma.

Change-Id: I850fb44383b61bd46880c4eb67bd9a2323c0d725
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13253
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoargpar: sync with upstream
Simon Marchi [Mon, 9 Sep 2024 16:30:03 +0000 (12:30 -0400)] 
argpar: sync with upstream

Sync with upstream commit a80b22c5f492 ("Add C++ bindings").

Change-Id: I65086a80325907d029a34fde437d52dba5a323c6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13252
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agolib: add bt_get_greatest_operative_mip_version_with_restriction()
Mathieu Desnoyers [Wed, 27 Mar 2024 23:09:06 +0000 (19:09 -0400)] 
lib: add bt_get_greatest_operative_mip_version_with_restriction()

This new function works like bt_get_greatest_operative_mip_version(),
but has an additional optional MIP version restriction range set.

For example, if all the components would support MIP 0 and 1,
bt_get_greatest_operative_mip_version() would return 1, while
bt_get_greatest_operative_mip_version_with_restriction() with the
`mip_version_restriction` parameter only containing [0, 0] would
return 0.

This new function provides more control over the preferred MIP version
to use while avoiding the complexity of exposing a direct "get supported
MIP versions" method call.

Philippe updated the documentation.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ic8bbdee6055a0816e398f0f27ac0ca8c45f0b85a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12791
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

2 months agotests/utils/python/mctf.py: convert JSON array → JSON text seq.
Philippe Proulx [Mon, 13 May 2024 09:00:43 +0000 (05:00 -0400)] 
tests/utils/python/mctf.py: convert JSON array → JSON text seq.

This patch updates `mctf.py` so that it converts a JSON array found in
the part named `metadata` to a JSON text sequence.

This makes it possible to write a CTF 2 metadata part without the odd
RS characters, for example:

    --- metadata
    [
      {
        "type": "preamble",
        "version": 2
      },
      {
        "type": "trace-class"
      },
      {
        "type": "data-stream-class"
      },
      {
        "name": "test",
        "payload-field-class": {
          "member-classes": [
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu1a"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu1b"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu2"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu3"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu4"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu5"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu6"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu7"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu8"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu9"
            },
            {
              "field-class": {
                "type": "variable-length-unsigned-integer"
              },
              "name": "vu10"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi1a"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi1b"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi1c"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi2"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi3"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi4"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi5"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi6"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi7"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi8"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi9"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi10a"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi10b"
            },
            {
              "field-class": {
                "type": "variable-length-signed-integer"
              },
              "name": "vi10c"
            }
          ],
          "type": "structure"
        },
        "type": "event-record-class"
      }
    ]

    --- my-stream
    [0 : uleb128]                     # `vu1a`
    [77 : uleb128]                    # `vu1b`
    [177 : uleb128]                   # `vu2`
    [43123 : uleb128]                 # `vu3`
    [21829382 : uleb128]              # `vu4`
    [5121829382 : uleb128]            # `vu5`
    [95121829382 : uleb128]           # `vu6`
    [13895121829382 : uleb128]        # `vu7`
    [913895121855555 : uleb128]       # `vu8`
    [333333333333333333 : uleb128]    # `vu9`
    [18446744073709551615 : uleb128]  # `vu10`
    [0 : sleb128]                     # `vi1a`
    [-1 : sleb128]                    # `vi1b`
    [23 : sleb128]                    # `vi1c`
    [-156 : sleb128]                  # `vi2`
    [8556 : sleb128]                  # `vi3`
    [-100101001 : sleb128]            # `vi4`
    [8288491823 : sleb128]            # `vi5`
    [-171717171717 : sleb128]         # `vi6`
    [123456787654321 : sleb128]       # `vi7`
    [-1121231234123450 : sleb128]     # `vi8`
    [99999999999999999 : sleb128]     # `vi9`
    [9223372036853775807 : sleb128]   # `vi10a`
    [9223372036854775807 : sleb128]   # `vi10b`
    [-9223372036854775808 : sleb128]  # `vi10c`

Detecting `[` as the first character of the part is enough because a
CTF 1.8 TSDL metadata text never starts with `[`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic1d6fb1644870f3b951d26238f82c79d7f3cf25a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12772

2 months agosrc.ctf.fs: always set the correct trace IR stream ID
Philippe Proulx [Sun, 12 May 2024 11:42:00 +0000 (07:42 -0400)] 
src.ctf.fs: always set the correct trace IR stream ID

In add_ds_file_to_ds_file_group(), we don't use the original CTF data
stream ID to set the trace IR stream ID whenever the beginning timestamp
is missing.

The comment says:

    if (begin_ns == -1) {
        /*
         * No beginning timestamp to sort the stream files
         * within a stream file group, so consider that this
         * file must be the only one within its group.
         */
        stream_instance_id.reset();
    }

This might be true, but there's no need to reset the data stream ID.

Then during data stream decoding, the trace IR stream ID always matches
the CTF IR data stream ID (if any), which enables some further checks.

Furthermore, a trace which goes from `src.ctf.fs` to `sink.ctf.fs` will
keep its original data stream IDs.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3c6ea0a3cbd913017cd00c1c07c6c6bf83b8a534
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12771

2 months agotests/.../data_from_mp.py: add CTF 2 support
Philippe Proulx [Sun, 12 May 2024 11:31:45 +0000 (07:31 -0400)] 
tests/.../data_from_mp.py: add CTF 2 support

This patch changes `tests/data/plugins/src.ctf.fs/field/data_from_mp.py`
to add CTF 2 support.

The script generates a CTF 2 trace when the stripped field class text
starts with `{` (full field class) or `"` (field class alias), which are
exclusive to the CTF 2 metadata syntax (any CTF 1.8 field class starts
with some keyword).

The same automatic field class aliases as the CTF 1.8 case
are available.

_make_ctf_2_metadata() doesn't need the `@` replacement trick of
_make_ctf_1_metadata() because CTF 2 array field classes aren't
different from any CTF 2 field class, for example:

    {
      "type": "static-length-array",
      "length": 4,
      "element-field-class": "u8"
    }

vs.

    u8 @[4]

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6abe0776c64fde62633cfc7a89094c0aedf6b9be
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12770

2 months agosrc.ctf.*: make `ctf::src::ClkClsCfg` final
Philippe Proulx [Fri, 10 May 2024 20:06:25 +0000 (16:06 -0400)] 
src.ctf.*: make `ctf::src::ClkClsCfg` final

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iaf0b5564cafdca5d7ce4ca17b03639de90f69cbf
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12769

2 months agocpp-common/bt2c/libc-up.hpp: make `FileCloserDeleter` final
Philippe Proulx [Fri, 10 May 2024 19:38:50 +0000 (15:38 -0400)] 
cpp-common/bt2c/libc-up.hpp: make `FileCloserDeleter` final

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I50cb8185a1e929db9da8f7fc98967351e126b781
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12768

2 months agobt2c/logging.hpp: replace `Logger::MemData` with `ConstBytes`
Philippe Proulx [Thu, 16 May 2024 15:37:58 +0000 (11:37 -0400)] 
bt2c/logging.hpp: replace `Logger::MemData` with `ConstBytes`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iad923b8d42256fe02a9c3300045201776bfc0c4e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12767

2 months agocpp-common/bt2c/data-len.hpp: `static inline` → `inline`
Simon Marchi [Wed, 29 May 2024 15:50:31 +0000 (11:50 -0400)] 
cpp-common/bt2c/data-len.hpp: `static inline` → `inline`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8f6a6d49d24ad312c2fdead6667bc41494f1321d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12766

2 months agocpp-common/bt2c/c-string-view.hpp: remove useless `bt2c::`
Philippe Proulx [Fri, 10 May 2024 19:36:43 +0000 (15:36 -0400)] 
cpp-common/bt2c/c-string-view.hpp: remove useless `bt2c::`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7dd42aef2cc547f6e18d575f0366f899bc43b1df
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12765

2 months agocpp-common/bt2c/read-fixed-len-int.hpp: remove useless `bt2c::`
Philippe Proulx [Fri, 10 May 2024 19:30:40 +0000 (15:30 -0400)] 
cpp-common/bt2c/read-fixed-len-int.hpp: remove useless `bt2c::`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ieb06919f8a18f2cb31d542d2eeb20ff096c985a7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12764

2 months agocpp-common/bt2c/read-fixed-len-int.hpp: fix comment style
Philippe Proulx [Fri, 10 May 2024 19:30:27 +0000 (15:30 -0400)] 
cpp-common/bt2c/read-fixed-len-int.hpp: fix comment style

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ibe59847e6db70e6361d57d259155c5489b0e1750
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12763

2 months agoAdd static bt2c::Uuid::isValidUuidStr()
Philippe Proulx [Fri, 10 May 2024 19:26:11 +0000 (15:26 -0400)] 
Add static bt2c::Uuid::isValidUuidStr()

The bt2c::Uuid(bt2s::string_view) constructor wants the conversion
to work.

This new static method calls bt_uuid_from_str() directly and uses its
return value to validate the UUID string.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I279ac6521b805b0085247c8fbeb16c9ed5018e51
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12762

2 months agocpp-common/bt2c/uuid.hpp: `static inline` → `inline`
Philippe Proulx [Fri, 10 May 2024 19:24:51 +0000 (15:24 -0400)] 
cpp-common/bt2c/uuid.hpp: `static inline` → `inline`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: If7a8ce9060c4618906e0ec3ac091cb7aca17e36b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12761

2 months agobt2c::Uuid::Uuid(): accept `bt2s::string_view` instead of `CStringView`
Philippe Proulx [Fri, 10 May 2024 19:23:45 +0000 (15:23 -0400)] 
bt2c::Uuid::Uuid(): accept `bt2s::string_view` instead of `CStringView`

The input string doesn't need to be null-terminated.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1ae0be22ee44fc4b7969525224f0721689a12dd1
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12760

2 months agocpp-common/bt2c/uuid.hpp: remove useless `bt2c::`
Philippe Proulx [Fri, 10 May 2024 19:13:32 +0000 (15:13 -0400)] 
cpp-common/bt2c/uuid.hpp: remove useless `bt2c::`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I381ee08c5d5eae70a987ca941629cd8d04e2eda5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12759

2 months agoMake bt_uuid_from_str() take begin/end pointers
Philippe Proulx [Fri, 10 May 2024 19:11:15 +0000 (15:11 -0400)] 
Make bt_uuid_from_str() take begin/end pointers

Make bt_uuid_from_str() take begin/end pointers (null terminator not
required) to make it possible to call it with a string view.

What used to be bt_uuid_from_str() is now bt_uuid_from_c_str() to avoid
changing existing the logic of call sites.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4d7c0c434b71c684a90fa696c6654e4b3a5c055c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12758

2 months agosink.text.details: adapt to latest libbabeltrace2 API
Philippe Proulx [Tue, 20 Jun 2023 20:39:16 +0000 (16:39 -0400)] 
sink.text.details: adapt to latest libbabeltrace2 API

This patch makes a `sink.text.details` component write the details of
the following MIP 1 features:

Clock class:
    • Namespace
    • UID
    • Precision if unknown
    • Accuracy
    • Custom origin (namespace, name, and UID)

Stream class:
    • UID

Event class:
    • UID

Bit array field class:
    • Flags (sorted, like enumeration field class mappings)

Trace:
    • Namespace
    • UID

The clock class term "offset from origin" is more accurate and modern
than "offset", therefore I'm changing this too and updating existing
expectation files accordingly.

Also, what used to be

    Origin is Unix epoch: Yes

with MIP 0 is now the same for any MIP:

    Origin: Unix epoch

When the origin is unknown, whatever the MIP version, there's no origin
line (like most missing/empty properties of `sink.text.details`).

Here's a hypothetical MIP-1 clock class output example:

    Default clock class:
      Namespace: lttng.org,2009
      Name: monotonic
      UID: boot-id:7d19f00b-f1c7-49ea-a0a1-5f1a6a062a29
      User attributes:
        lttng.org,2009:
          tag: provigo
          original-index: 4
      Description: Monotonic Clock
      Frequency (Hz): 1,000,000,000
      Precision (cycles): 0
      Accuracy (cycles): 1000
      Offset from origin (s): 1,564,079,206
      Offset from origin (cycles): 484,157,338
      Origin:
        Namespace: quebec.ca,2017
        Name: referendum
        UID: 1995

The component only writes UIDs when the `with-uid` parameter is true
(the default). This is analogous to the `with-uuid` parameter. You may
specify both `with-uuid` and `with-uid` parameters: the former only
applies under MIP 0 and the latter under MIP 1.

Also changing some tests which set `with-uuid` to false to also set
`with-uid` to false, should they work under MIP 1.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2411acb49a878e2eb135af86bc9f618cfd284987
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12757

2 months agotests: run some Python tests with CTF 1 and CTF 2 traces
Simon Marchi [Tue, 24 Oct 2023 02:12:24 +0000 (22:12 -0400)] 
tests: run some Python tests with CTF 1 and CTF 2 traces

The goal of this patch is to run as many Python-based tests that use CTF
traces against both CTF 1 and CTF 2.  I would like to minimize the
amount of changes and boilerplate necessary in each individual test.

I've taken the approach to add a decorator named `test_all_ctf_versions`
to the test classes, inspired by the parameterized Python package [1].
Unlike the decorators, from parameterized, our decorator is hardcoded
for what we need.  When applied to a class, it makes two copies of all
`test_*` methods of that class, suffixed with `_ctf_1` and `_ctf_2`, and
removes the original method.  The two new methods are in fact wrapped in
a small wrapper that sets the `_ctf_version` attribute on the class
(with the value 1 or 2) for the duration of the method call.

The changes necessary in the test themselves are to make the test trace
paths dependent on `self._ctf_version`, instead of hard-coded.

[1] https://pypi.org/project/parameterized/

Change-Id: Idef27183db6287630e63260395d255e68da2a4c3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8737
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12755

2 months agotests/src.ctf.fs: run test_force_origin_unix_epoch succeed test on CTF 1 and CTF...
Simon Marchi [Tue, 23 Aug 2022 12:41:49 +0000 (08:41 -0400)] 
tests/src.ctf.fs: run test_force_origin_unix_epoch succeed test on CTF 1 and CTF 2 traces

Modify test_force_origin_unix_epoch such that it tests with both the CTF
1 and CTF 2 version of the trace.

Change-Id: I356a2c70c10cab2ab4f182649cbbb93debe86e7e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8738
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12754

2 months agotests: add test with incomplete packet header
Simon Marchi [Mon, 15 Aug 2022 18:02:39 +0000 (14:02 -0400)] 
tests: add test with incomplete packet header

During developement we hit a problem where src.ctf.fs's medium returned
less data than the `minSize` parameter, when reading a faulty trace.
The trace added in this patch reproduces the problem.  It consists of a
full packet, followed by a single byte.  When trying to read a second
packet, the ItemSeqIter instance would ask the medium for at least two
bytes, but the medium would return a buffer with a single byte (the data
available until the end of file).  The fix was to make the medium
generate an error in this case.

Change-Id: I9a79360b18091f517846ca2be94fbf10fb9af349
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12753
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agotests: add clock-class before trace-class CTF2 test
Simon Marchi [Mon, 15 Aug 2022 15:04:19 +0000 (11:04 -0400)] 
tests: add clock-class before trace-class CTF2 test

Add a test with a CTF 2 metadata file where a clock-class fragment is
before the trace-class fragment.  A bug triggered by this patch was hit
during development.

Change-Id: If9fd2497ca31ad73d9db1198f90e2404d9a7a8c1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12752
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agotests/src.ctf.fs: add CTF 2 tests for no stream class, no trace class
Simon Marchi [Sat, 4 Nov 2023 20:23:14 +0000 (20:23 +0000)] 
tests/src.ctf.fs: add CTF 2 tests for no stream class, no trace class

During development, we hit some crashes when the trace metadata did not
specify any data stream class fragment (with and without an explicit
trace class fragment).  Add tests for that.

Change-Id: Ic8ce4c7a2ae78b2f484a86e5b1306b7eae606528
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12751
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agotests/src.ctf.fs/test_fail: test with both autodiscovery and explicit component insta...
Simon Marchi [Fri, 10 Nov 2023 16:33:48 +0000 (16:33 +0000)] 
tests/src.ctf.fs/test_fail: test with both autodiscovery and explicit component instantiation

Specifying a path to a failing trace like this:

  babeltrace2 mytrace

vs

  babeltrace2 -c src.ctf.fs -p 'inputs=["mytrace"]'

... exercises different code paths.  If the failure is due to bad
metadata, the first one will error out during the support-info query
phrase, whereas the second one will error out in the component
initialization.  I think it would be good to exercise both in the test
with failing traces.

Rename the test_fail function to test_fail_method, and add a parameter
indicating which method of passing the trace path to use (autodisc vs
component).  Add a new test_fail function that tries with both methods.

Change-Id: Ieb65504a773b0915946f8ef543a7d0930ca0a7d7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12750
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agotests/src.ctf.fs: add function to compute trace path in test-fail.sh
Simon Marchi [Thu, 2 Nov 2023 18:50:16 +0000 (18:50 +0000)] 
tests/src.ctf.fs: add function to compute trace path in test-fail.sh

Add a function that returns a trace path given a trace name and a ctf
version.  This is useful for subsequent patches that add tests with CTF
2 traces.

Change-Id: Ibc81d150152cd47e7113ebbc94bfe6995773655e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12749
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoctf: remove now unused files
Simon Marchi [Tue, 21 May 2024 17:59:51 +0000 (13:59 -0400)] 
ctf: remove now unused files

Change-Id: Ib66be547edae247049f4d5b0a21233a7c68e0811
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8649
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12748

2 months agosrc.ctf.lttng-live: use the new metadata stream parser and message iterator
Simon Marchi [Fri, 24 May 2024 21:21:56 +0000 (17:21 -0400)] 
src.ctf.lttng-live: use the new metadata stream parser and message iterator

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Id2e11205bed54654942077c5336495b7bdd3f38d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8617
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8648

2 months agotests/cli/test_trace_read: use `bt_cli` and `isnt`
Simon Marchi [Thu, 4 Aug 2022 20:32:56 +0000 (16:32 -0400)] 
tests/cli/test_trace_read: use `bt_cli` and `isnt`

This makes the output more readable/analyzable on failure.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6bb7d76538c843a50e605756493de0755cc9ca11
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12747

2 months agotests/cli/test_output_ctf_metadata: use `bt_cli` and `diff`
Simon Marchi [Wed, 25 Oct 2023 02:11:44 +0000 (02:11 +0000)] 
tests/cli/test_output_ctf_metadata: use `bt_cli` and `diff`

This makes the output more readable/analyzable on failure.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2466a032d7cfc2b8b6eb2de4b473dd1bb0c193df
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12746

2 months agotests: adjust src.ctf.fs succeed tests to read CTF 2 traces
Simon Marchi [Fri, 10 Nov 2023 16:32:38 +0000 (16:32 +0000)] 
tests: adjust src.ctf.fs succeed tests to read CTF 2 traces

Change-Id: I3a78fb1641c3c1bae98be74b741ce2f4b8089ec0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8509
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8646

2 months agotests: Add CTF 2 version of succeed test traces
Francis Deslauriers [Wed, 22 Jun 2022 19:52:05 +0000 (15:52 -0400)] 
tests: Add CTF 2 version of succeed test traces

The following traces were left out:
  succeed/warnings
  succeed/succeed3
  succeed/succeed4

Because they are testing CTF1 syntax.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I84504bd934958b6c04d8350610c397a8e851383e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8465
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8645

2 months agotests: move CTF 1 test traces to their own directory
Francis Deslauriers [Fri, 9 Feb 2024 21:22:20 +0000 (16:22 -0500)] 
tests: move CTF 1 test traces to their own directory

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I4d7ca33c1187b7495dd49103ecec66316ff65001
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8433
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8644

2 months agosrc.ctf.fs: make ctf_fs_trace's logger private
Simon Marchi [Tue, 21 May 2024 17:06:21 +0000 (13:06 -0400)] 
src.ctf.fs: make ctf_fs_trace's logger private

Rename `ctf_fs_trace::logger` to `ctf_fs_trace::_mLogger` and make
private.  Pass a logger down to some functions that would previously get
it from the trace.

Change-Id: Ieae140125ac14595845739534d6bb0ee65ae114d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8372
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12745

2 months agosrc.ctf.fs: fix error path of ctf_fs_init
Simon Marchi [Fri, 30 Aug 2024 18:17:13 +0000 (14:17 -0400)] 
src.ctf.fs: fix error path of ctf_fs_init

If ctf_fs_create fails (returns nullptr), we don't want to call
bt_self_component_set_data.  Return early if that happens.

Change-Id: Ib5766c6795a841ee1c2abc30e1751f9f1930f985
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13200
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agosrc.ctf.fs: use the new metadata stream parser and message iterator
Simon Marchi [Thu, 30 May 2024 18:26:09 +0000 (14:26 -0400)] 
src.ctf.fs: use the new metadata stream parser and message iterator

Update the src.ctf.fs component class to use:

  - the new metadata stream parser / IR generator (ctf::src::CtfIrGenerator)
  - the new message iterator (ctf::src::MsgIter)

The new IR generator produces a trace class instance using the new CTF
IR type, ctf::src::TraceCls.  This instance is then fed to the message
iterator.  These two changes must therefore be done in lock step.

Add ctf::src::fs::Medium, a Medium for use with ctf::src::ItemSeqIter
that reads trace data from the filesystem.  It receives an index, which
can be thought of as the "playlist" of packets that form the logical
data stream.  Its buf method needs to be able to find a packet given a
requested offset in that logical data stream.  Therefore, add a new
`offsetInStream` field in the ctf_fs_ds_index_entry structure, and the
`updateOffsetsInStream` method to compute them.  Rename
ctf_fs_ds_index_entry::offset to offsetInFile, for clarity.

Once the buf method selected the right index entry (packet), it maps
that portion of the file, and see if the returned buffer can include
some of the following packets in the file, while at it.

Other details about the changes in this patch, in no particular order:

 - Make a copy of ctf_trace_class_configure_ir_trace that works on a
   ctf::src::TraceCls instead of a struct ctf_trace_class.  The old one
   will be removed once src.ctf.lttng-live no longer uses it.

 - Remove ctf_fs_metadata, the required fields (the decoder / IR
   generator) are now directly in ctf_fs_trace.

 - The quirks to apply are saved in the ctf_fs_component object
   directly.  They were previously saved in the old IR object (struct
   ctf_trace_class), but they are not in the new IR object.  They now
   need to be passed to all instantiated message iterators.

 - Remove ctf_fs_msg_iter_data::ds_file_group, add
   ctf_fs_msg_iter_data::port_data.  This allows message iterators to
   access the ctf_fs_component and therefore the quirks.  They can still
   access the ds_file_group through the port_data.

 - Replace ctf_fs_msg_iter_data::msg_iter (the old message iterator)
   with ctf_fs_msg_iter_data::msgIter (the new message iterator).

 - Remove ctf_fs_msg_iter_data::msg_iter_medops_data, this is the data
   for the medium (medops) for the old message iterator.

 - Adjust ctf_fs_iterator_init, ctf_fs_iterator_next,
   ctf_fs_iterator_finalize to the new message iterator.

 - Adjust ctf_fs_iterator_seek_beginning to the new message iterator.
   The simplest way I found to reset the state to the beginning state is
   to delete the message iterator and instantiate a new one.

 - Update add_ds_file_to_ds_file_group to use readPktProps to read the
   stream class and id.

 - Change decode_clock_snapshot_after_event, used for working around
   known tracer bugs, to use an ItemSeqIter.  Define two item visitors,
   ClockSnapshotAfterFirstEventItemVisitor and
   ClockSnapshotAfterLastEventItemVisitor, for the two cases.

Change-Id: I8e3ce344c940da2106bdf8320c28724ca360b48a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8349
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12744

2 months agoctf: rename ctx_create to ctf_visitor_generate_ir_create
Simon Marchi [Thu, 18 Apr 2024 14:36:22 +0000 (14:36 +0000)] 
ctf: rename ctx_create to ctf_visitor_generate_ir_create

There is an unnecessary level here, rename the existing ctx_create to
ctf_visitor_generate_ir_create.  Remove the existing
ctf_visitor_generate_ir_create.

Change-Id: I2ce578f30e1e9e25754dc9ad4f18610eb3a0be36
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8424
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12743

2 months agoctf: use `bt2s::make_unique` in one spot
Simon Marchi [Wed, 6 Dec 2023 19:43:34 +0000 (19:43 +0000)] 
ctf: use `bt2s::make_unique` in one spot

Change-Id: Ie753b3be9abc29d1e4fa6a208dcdd28f1af50e37
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12742
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoctf: make ctf_visitor_generate_ir not use ctf_metadata_decoder_config
Simon Marchi [Wed, 17 Apr 2024 18:11:19 +0000 (14:11 -0400)] 
ctf: make ctf_visitor_generate_ir not use ctf_metadata_decoder_config

The ctf_metadata_decoder_config structure is going to disappear in the
following patches.  Make ctf_visitor_generate_ir (which we will keep for
now) stop using it.

Change-Id: If4053599d0077554882a9eabe79e4489aa655c72
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8405
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12741

2 months agocpp-common/bt2c: Logger: factor out code to append cause
Simon Marchi [Tue, 21 May 2024 16:43:47 +0000 (12:43 -0400)] 
cpp-common/bt2c: Logger: factor out code to append cause

Factor out the code that appends an error cause to a helper method, so
that it can be re-used.

Change-Id: I055314bef66968ef2ef30b5dd1728680d2f79c7c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12228
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agosrc.ctf.fs: Implement queries with new `MetadataStreamDecoder' and `Ctf1MetadataStrea...
Francis Deslauriers [Tue, 7 May 2024 15:17:57 +0000 (11:17 -0400)] 
src.ctf.fs: Implement queries with new `MetadataStreamDecoder' and `Ctf1MetadataStreamParser`

Rewrite the `babeltrace.support-info` query using the new
`Ctf1MetadataStreamParser` class.

Rewrite the `metadata-info` query using the new `MetadataStreamDecoder`
class.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I80530c6eef7ca62c4271a568e527e48e8ec2602a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7946
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12740
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

2 months agocpp-common/bt2c: make `dataFromFile()` take a `CStringView`
Simon Marchi [Thu, 25 Apr 2024 15:10:55 +0000 (15:10 +0000)] 
cpp-common/bt2c: make `dataFromFile()` take a `CStringView`

Make it easier to pass an `std::string` to `dataFromFile()`.

Change-Id: I0af7d913362e67b69c1f479e3be8024d9337b9d6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12739
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 months agocpp-common/bt2c: optionally log and append errors in `dataFromFile()`
Simon Marchi [Thu, 25 Apr 2024 14:57:24 +0000 (14:57 +0000)] 
cpp-common/bt2c: optionally log and append errors in `dataFromFile()`

For some callers, a `dataFromFile()` error (`NoSuchFileOrDirectoryError`
typically) may be fatal, in which case it would be appropriate to log an
error and append an error cause.  For others callers, it might not be
fatal, they just want to catch the exception and carry on.

To accomodate this, pass a logger to `dataFromFile()` and add a
`fatalError` boolean parameter.  Log an error and append an error cause
on error if `fatalError` is true.  Otherwise, log at the debug level.

Change-Id: Id32639b16a928195bc430c1a2ce7671ced2ad43b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12738
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 months ago`ctf` plugin: add metadata stream parser utilities
Philippe Proulx [Thu, 25 Apr 2024 15:45:38 +0000 (15:45 +0000)] 
`ctf` plugin: add metadata stream parser utilities

This patch adds:

ctf::src::getMetadataStreamMajorVersion():
    Returns the major version of a metadata stream based on its first
    byte.

ctf::src::createMetadataStreamParser(MetadataStreamMajorVersion, ...):
    Creates and returns a CTF metadata stream parser of which the
    concrete class depends on some major version.

ctf::src::createMetadataStreamParser(const std::uint8_t *, ...):
    Creates and returns a CTF metadata stream parser of which the
    concrete class depends on the first byte of some data.

ctf::src::parseMetadataStream():
    Parses a whole metadata stream, returning the resulting trace class
    and optional metadata stream UUID.

    This is the preferred way to parse a whole metadata stream as it
    calls the static parse() method of some concrete parser class which
    may contain more validation. For example,
    ctf::src::Ctf2MetadataStreamParser::parse() throws if there's no
    resulting trace class or if the current resulting trace class has no
    data stream classes (required by CTF2‑SPEC‑2.0 [1]).

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html#metadata-stream

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id869bb4fc735a75fbe16827dfb6abed62d13467b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12737
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

2 months agoAdd `ctf::src::Ctf2MetadataStreamParser` class (JSON text sequence)
Philippe Proulx [Tue, 21 May 2024 17:57:03 +0000 (13:57 -0400)] 
Add `ctf::src::Ctf2MetadataStreamParser` class (JSON text sequence)

This patch adds `ctf::src::Ctf2MetadataStreamParser` which inherits
`ctf::src::MetadataStreamParser` to implement a CTF 2 metadata stream
(JSON text sequence) parser.

The parser uses `Ctf2JsonAnyFragmentValReq` to validate each fragment,
and also performs other validation at the JSON level.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I29a29e589b9de998a2fadf7be96871902e3fd76a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12736

2 months agoAdd bt2c::join()
Philippe Proulx [Fri, 10 May 2024 19:32:10 +0000 (15:32 -0400)] 
Add bt2c::join()

This new function template joins the strings of some container with
some delimiter.

The container needs a forward iterator and its elements need the data()
and size() methods.

The container may be empty.

For example:

    int main()
    {
        std::cout << bt2c::join(std::vector<std::string> {
            "salut", "meow", "mix"
        }, ", ") << '\n';
    }

will print

    salut, meow, mix

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id3ff90cf3b2fa4336b71860dbe3c0dff83668607
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12735

2 months agoAdd `ctf::src::Ctf1MetadataStreamParser` class (TSDL)
Philippe Proulx [Sun, 10 Dec 2023 05:51:52 +0000 (05:51 +0000)] 
Add `ctf::src::Ctf1MetadataStreamParser` class (TSDL)

This patch adds the `ctf::src::Ctf1MetadataStreamParser` class which is
a concrete TSDL metadata stream parser inheriting
`ctf::src::MetadataStreamParser`.

parseSection() requires one or more complete root blocks of TSDL
contents.

`ctf::src::Ctf1MetadataStreamParser` also implements the static
ctf::src::Ctf1MetadataStreamParser::parse() which considers a whole
metadata stream. While this static method currently doesn't add anything
to creating a parser and calling parseSection() once, it could
eventually contain more validation knowing that the metadata stream was
completely parsed.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I55e0f2f05d64a0acc5949029e315aeefae424dda
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8000
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12734

2 months agoAdd `ctf::src::MetadataStreamParser` abstract base class
Philippe Proulx [Wed, 25 Oct 2023 15:41:53 +0000 (15:41 +0000)] 
Add `ctf::src::MetadataStreamParser` abstract base class

This is an abstract base class for any metadata stream parser.

Parse a metadata stream section with parseSection() (defers to the
virtual _parseSection() method).

Get the resulting, current trace class and metadata stream UUID with
traceCls() and metadataStreamUuid().

The constructor accepts an optional self component pointer so that
parseSection() may finalize the trace class after calling the
version-specific _parseSection().

The trace class finalization method finalizes a `ctf::src` CTF IR trace
class after its creation or when it gets new data stream classes or
event record classes. The method:

• Sets the value saving indexes of dependencies (field classes) and the
  saved value index of dependent (dynamic-length, optional, and variant)
  field classes.

  It also links the dependent field classes to their dependencies by
  weak pointer.

• Reconfigures the clock classes of the trace class.

• Normalizes the offsets of the clock classes of the trace class so that
  the cycle part is less than the frequency.

• With a self component pointer, translates the contained objects to
  their trace IR equivalents.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I24e175447f759220de5943ccb49c7888a5934ce5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12733

2 months agocpp-common/bt2/trace-ir.hpp: use "common event context"
Philippe Proulx [Fri, 10 May 2024 19:57:46 +0000 (15:57 -0400)] 
cpp-common/bt2/trace-ir.hpp: use "common event context"

This is easier to read.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iabfe3b3a44dcdfad03be47c3cb69b64fb729e91c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12732

2 months agocpp-common/bt2/field{,-class}.hpp: adapt to latest libbabeltrace2 API
Philippe Proulx [Mon, 18 Mar 2024 21:19:57 +0000 (17:19 -0400)] 
cpp-common/bt2/field{,-class}.hpp: adapt to latest libbabeltrace2 API

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia4dbbd5c35a482e3dff634d8e99192b0d1c08784
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12731

2 months agocpp-common/bt2/trace-ir.hpp: adapt to latest libbabeltrace2 API
Philippe Proulx [Wed, 17 Apr 2024 19:35:04 +0000 (15:35 -0400)] 
cpp-common/bt2/trace-ir.hpp: adapt to latest libbabeltrace2 API

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0dd81df640da63f1e6a1bdac43d4b89e86f36c6b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12730

2 months agocpp-common/bt2/clock-class.hpp: adapt to latest libbabeltrace2 API
Philippe Proulx [Wed, 17 Apr 2024 19:28:23 +0000 (15:28 -0400)] 
cpp-common/bt2/clock-class.hpp: adapt to latest libbabeltrace2 API

Read anything related to the origin with the new origin() method which
returns a clock origin view from which you may get the namespace, name,
UID, and whether or not it's unknown or the Unix epoch.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib44547fd60580ab9aea3c0cb3492542749d3a5da
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12729

2 months agocpp-common/bt2: add support to get / set trace UID
Simon Marchi [Tue, 28 Nov 2023 04:39:27 +0000 (23:39 -0500)] 
cpp-common/bt2: add support to get / set trace UID

Wrap bt_trace_set_uid and bt_trace_get_uid.

Change-Id: I610c426424214334fb210421809adae3e214c4e3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10154
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12728

2 months agolib: add support for bit array flags
Simon Marchi [Mon, 22 Jan 2024 21:20:58 +0000 (21:20 +0000)] 
lib: add support for bit array flags

Implement support for flags on bit array field classes, in order to
be able to add support for the fixed-length bit map field class (as
specified by CTF2-SPEC-2.0 [1]) in the CTF component classes.

A flag is a mapping between bit positions in a fixed-length bit map
field and a textual label.  A flag is considered active for a given
field if any of the bits in the flag's bit positions is set in the
field.  Flags may have overlapping bit positions, meaning that a single
bit can activate multiple flags.

Add the following public functions operating on bit array field classes:

 🥑 bt_field_class_bit_array_add_flag
 🥑 bt_field_class_bit_array_get_flag_count
 🥑 bt_field_class_bit_array_borrow_flag_by_index_const
 🥑 bt_field_class_bit_array_borrow_flag_by_label_const
 🥑 bt_field_class_bit_array_get_active_flag_labels_for_value_as_integer

Add the bt_field_class_bit_array_flag type.  Then, add the following
public functions operating on it:

 🥑 bt_field_class_bit_array_flag_get_label
 🥑 bt_field_class_bit_array_flag_borrow_index_ranges_const

Add the following public function operating on a bit array field:

 🥑 bt_field_bit_array_get_active_flag_labels

The
`bt_field_class_bit_array_get_active_flag_labels_for_value_as_integer`
function returns an array of label through an output parameter of type
`bt_field_class_bit_array_flag_label_array`.  The storage for it is
owned by the field class, so the result is only valid until the next
call to the function (or until the field class gets destroyed).  This
behavior is copied from the enum field class.

Philippe updated the documentation.

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

Change-Id: Ib88f3aecf692ea8b6453c0308fa7735fd40e55a9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12727
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agolib: add bt_clock_class_has_same_identity function
Simon Marchi [Tue, 5 Sep 2023 14:59:59 +0000 (10:59 -0400)] 
lib: add bt_clock_class_has_same_identity function

Add the bt_clock_class_has_same_identity utility function, which tells
if two clock classes have the same identify.

The criteria for whether two clock classes have the same identity are
the same as in CTF 2:

    Two clock classes which satisfy all the following conditions are
    said to have the same identity:

     - Both share the same namespace property value, or both don’t have
       any namespace property.
     - Both have a name property and share the same value.
     - Both have a uid property and share the same value.

Philippe updated the documentation.

Change-Id: I55e4e13274d413a15873099045f14690feab09c4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10749
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12726

2 months agolib: add clock class accuracy property
Simon Marchi [Fri, 1 Sep 2023 19:37:38 +0000 (15:37 -0400)] 
lib: add clock class accuracy property

With the intent of supporting CTF 2, add the accuracy property to clock
classes.

 - Add the bt_clock_class_{g,s}et_accuracy getter and setter, both of
   which are restricted to MIP >= 1.
 - Add the accuracy field to struct bt_clock_class.
 - Make lib-logging print the accuracy of a clock class, if set.

Philippe updated the documentation.

Change-Id: I199ea6d339fcb0142847825c3d12ae526564814d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10711
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12725

2 months agolib: make clock class precision optional
Simon Marchi [Fri, 1 Sep 2023 19:16:26 +0000 (15:16 -0400)] 
lib: make clock class precision optional

With the intent of supporting CTF 2, make the precision property of
clock classes optional under MIP 1.

 - Change the precision field of struct bt_clock_class to
   bt_property_uint.
 - Adjust lib-logging to omit the precision if not set.
 - Change bt_clock_class_create to make the precision property available
   with MIP 0, so that the precision will always be available with MIP
   0 (still with an initial value of 0).
 - Restrict bt_clock_class_get_precision to MIP 0.
 - Add bt_clock_class_get_opt_precision, which returns a
   bt_property_availability value.  Note that
   bt_clock_class_get_opt_precision can be used with MIP 0, it will
   always return BT_PROPERTY_AVAILABILITY_AVAILABLE.

Not done in this patch: adapt the Python bindings.

Philippe updated the documentation.

Change-Id: I1daf6627fda741f854d85ad6ff6f4ad132591662
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10710
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12724

2 months agolib: add event class UID property
Simon Marchi [Tue, 7 May 2024 20:42:24 +0000 (16:42 -0400)] 
lib: add event class UID property

Add a UID property to event class objects.  This is needed to
support CTF 2.

Philippe updated the documentation.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Iae20d1d9835de2a04b02493c824e486e6fed7dcf
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10698
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12723

2 months agolib: add stream class UID property
Simon Marchi [Tue, 7 May 2024 20:41:55 +0000 (16:41 -0400)] 
lib: add stream class UID property

Add a UID property to stream class objects.  This is needed to
support CTF 2.

Philippe updated the documentation.

Change-Id: Iac6f88ada28f0e97cf3082fd753df0867cb772d0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10696
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12722

2 months agolib: add trace namespace property
Simon Marchi [Tue, 7 May 2024 20:22:04 +0000 (16:22 -0400)] 
lib: add trace namespace property

Add a new namespace property for trace objects.  This is needed to
support CTF 2.

Philippe updated the documentation.

Change-Id: I9c382879a3181aab2859a4c41cfbb21c4f6928aa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10695
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12721

2 months agolib: add clock class namespace and UID properties
Simon Marchi [Tue, 7 May 2024 20:18:47 +0000 (16:18 -0400)] 
lib: add clock class namespace and UID properties

Add the namespace and UID properties to clock class objects.  This is
needed to support CTF 2.

Philippe updated the documentation.

Change-Id: I9b6ee8f78581ca8ebfa8b1ceca0d1fe50178c1b3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10677
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12720

2 months agolib: add bt_trace_class_get_graph_mip_version
Simon Marchi [Wed, 31 May 2023 19:59:08 +0000 (15:59 -0400)] 
lib: add bt_trace_class_get_graph_mip_version

Add bt_trace_class_get_graph_mip_version, which returns the MIP version
for the graph the trace class is in.

This will be necessary for the Python bindings functions dealing with
trace IR that need to change their behavior according to the MIP
version.  Right now, the MIP version can be obtained from a self
component.  But some Python functions (for instance
_TraceClass.create_variant_field_class) only have a IR object to work
with, and it's not possible to get the self component from there.
Adding a function to get the self component from a trace class was
considered, but it was deemed to complex because of object lifetime and
refcount cycle issues.

Philippe updated the documentation.

Change-Id: Ie31be7d31baf1242bad3927021de7c949f281247
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10155
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12719

2 months agoAdd ctf::src::normalizeClkOffset()
Simon Marchi [Mon, 11 Dec 2023 17:24:39 +0000 (12:24 -0500)] 
Add ctf::src::normalizeClkOffset()

Also, use it in `visitor-generate-ir.cpp` instead of the local
function.

Change-Id: I5073a901f8c4c434ad35e102aaeb145a30055506
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12718
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agoImplement CTF 2 JSON requirements
Philippe Proulx [Mon, 11 Dec 2023 21:51:28 +0000 (16:51 -0500)] 
Implement CTF 2 JSON requirements

This patch implements all the CTF 2 JSON requirements.

The internal "public" API is the `Ctf2JsonAnyFragmentValReq` PImpl class
which validates a single CTF 2 fragment. That's all the CTF 2 metadata
stream parser will need.

Here's an example:

Code:
    Ctf2JsonAnyFragValReq {}.validate(*bt2c::parseJson(jsonText));

JSON text:
    {
      "type": "data-stream-class",
      "namespace": "lol",
      "name": "salut",
      "packet-context-field-class": {
        "type": "structure",
        "member-classes": [
          {
            "name": "meow",
            "field-class": {
              "type": "null-terminated-string"
            }
          },
          {
            "name": "lel",
            "field-class": "uint16"
          },
          {
            "name": "meow",
            "field-class": {
              "type": "dynamic-length-array",
              "length-field-location": {"path": ["lel"]},
              "element-field-class": {
                "type": "fixed-length-signed-integer",
                "length": 23,
                "byte-order": "little-endian",
                "alignment": 24,
                "attributes": {}
              }
            }
          }
        ]
      }
    }

Exception message:
    [1:1] Invalid data stream class fragment:
    [5:33] In object property `packet-context-field-class`:
    [5:33] Invalid scope field class:
    [5:33] Invalid structure field class:
    [7:23] In object property `member-classes`:
    [18:7] In array element #3:
    [18:7] Invalid structure field member class:
    [20:24] In object property `field-class`:
    [20:24] Invalid dynamic-length array field class:
    [23:34] In object property `element-field-class`:
    [23:34] Invalid fixed-length signed integer field class:
    [27:26] In object property `alignment`:
    [27:26] Invalid alignment: 24 is not a power of two.

I'd say that Ctf2JsonAnyFragValReq::validate() can validate 95 % of a
CTF 2 metadata stream. See its class comment to learn what it can't do.

There are a few clang-format off/on comments because I hate what it does
with nested brace-enclosed lists.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic622a099a1e0aa5daa896cdfa910d24b817a9a5f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12717

2 months ago`ctf` plugin: add `ctf::src::MsgIter` class
Simon Marchi [Wed, 22 May 2024 16:00:59 +0000 (12:00 -0400)] 
`ctf` plugin: add `ctf::src::MsgIter` class

Original patch by Simon.

Philippe's changes over original patch (no functional change intended):

• Conform to the Babeltrace 2 coding style for new C++11 code and to
  some naming conventions of the common part of the `ctf` plugin.

• Add many public and internal comments.

• Rename `Quirks` class to `MsgIterQuirks`.

  Also, rename the quirks to the generic `pktEndDefClkValZero`,
  `eventRecordDefClkValGtNextPktBeginDefClkVal`, and
  `eventRecordDefClkValLtPktBeginDefClkVal` names to decouple this API
  from specific tracers.

• Remove `MsgIterItemVisitor`.

  Instead, MsgIter::_handleItem() dispatches the item to a specific
  handling method based on its numeric type.

  Move the relevant members of `MsgIterItemVisitor` into
  `MsgIter` itself.

• In `_StackFrame`, rename everything named "field" to "sub-field" so as
  to remove some ambiguity.

• Add MsgIter::_stackTop*() helper methods which defer to the
  corresponding method on the top stack frame.

• Add MsgIter::_stackPush() and MsgIter::_stackPop() helper methods.

• Add MsgIter::_addMsgToQueue() helper method.

• Only log item details when the `TRACE` level is enabled.

• Handle `PktMagicNumberItem`: validate the magic number value.

• Handle `MetadataStreamUuidItem`: validate the UUID.

  The `MsgIter` constructor now accepts an `expectedMetadataStreamUuid`
  parameter (optional UUID) which is the expected metadata stream UUID
  to compare to.

• Handle variable-length integer field items, adding the
  MsgIter::_handleUIntFieldItem() and MsgIter::_handleSIntFieldItem()
  helper method templates to do so.

• Handle BLOB field items.

  A new data member, `_mCurBlobFieldDataOffset`, tracks the current BLOB
  field data offset to write to when handling the next
  `BlobFieldSectionItem` (we can't append to a BLOB field like when
  handling `StrFieldSubstrItem`).

• Handle optional field items, adding a member
  to `MsgIter::_StackFrame::_Field`.

• In MsgIter::_StackFrame::goToNextSubField(), unconditionally increment
  `_mSubFieldIndex`: curSubField() doesn't care about `_mSubFieldIndex`
  for the variant/option field cases anyway.

  Therefore, make curSubFieldAndGoToNextSubField() reuse curSubField()
  and goToNextSubField() to remove some almost duplicate code.

• Handle UTF-16 and UTF-32 string data.

Change-Id: If2dd82b43f4d19a16ec4420c13c9a3686034766d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8227
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12716

2 months agocpp-common/bt2c: add `UnicodeConv` class
Simon Marchi [Fri, 3 May 2024 16:54:10 +0000 (12:54 -0400)] 
cpp-common/bt2c: add `UnicodeConv` class

Add the `UnicodeConv` class, which currently implements conversion
from (UTF-16, UTF-32) × (BE, LE) to UTF-8.

The `UnicodeConv` class uses `g_iconv` from GLib internally to make
the conversions.  It has a vector member that is used as an output
buffer.  Public conversion methods accept a span of
`const std::uint8_t`, and return a span `std::uint8_t` which is a view
on that internal vector.

Add a test which:

✤ Converts some hardcoded UTF-16 and UTF-32 strings to UTF-8 and
  verifies the result against a reference UTF-8 string.

✤ Feeds the UTF-16 and UTF-32 conversion methods with truncated strings
  and verifies that they throw and append specific causes to the error
  of the current thread.

Change-Id: I962bd49261a3d9779ed6a24a26c7800a24beb719
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12715

2 months agoFix: use `OptionalBorrowedObject::hasObject()` in `CommonOptionField::hasField()`
Simon Marchi [Tue, 26 Mar 2024 20:45:47 +0000 (20:45 +0000)] 
Fix: use `OptionalBorrowedObject::hasObject()` in `CommonOptionField::hasField()`

This is needed since `OptionalBorrowedObject::operator bool()` is
explicit.

Change-Id: Iabd899be72607b1d5eb1a42dec919c14d0e33868
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12714
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agocpp-common/bt2: add `CommonBlobField` and `CommonDynamicBlobField`
Philippe Proulx [Thu, 7 Dec 2023 20:38:33 +0000 (20:38 +0000)] 
cpp-common/bt2: add `CommonBlobField` and `CommonDynamicBlobField`

Use `CommonBlobField::data()` to access the data pointer and data length
(bytes) of the BLOB field as a `bt2s::span`. A `BlobField::data()`
returns `bt2s::span<std::uint8_t>` while `ConstBlobField::data()`
returns `bt2s::span<const std::uint8_t>`.

Use `CommonDynamicBlobField::length()` to set the length of a dynamic
BLOB field (like `CommonDynamicArrayField::length()`).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3d9f9417e262a5fbbc9b7bb8f3d690d6628f7988
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12713

2 months agosrc.ctf.fs: Add `readPktProps()`
Francis Deslauriers [Wed, 22 May 2024 15:57:36 +0000 (11:57 -0400)] 
src.ctf.fs: Add `readPktProps()`

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I0e98db658cc50e44bc8d77c8dea53c1984af28aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8190
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12712

2 months agosrc.ctf.fs: Add `LoggingItemVisitor`
Simon Marchi [Tue, 21 May 2024 17:12:06 +0000 (13:12 -0400)] 
src.ctf.fs: Add `LoggingItemVisitor`

While developing, I found it useful to print the sequence of items seen
by a given visitor, so I would make the various visitor methods print
some information.  Instead of re-implementing it in the various
visitors, I eventually extracted the functionality in its own visitor
(the one this patch adds).

This visitor logs details about the visited items.  Indentation is used
to represent the items that are logically nested in other ones.  For
example, everything between a ScopeBeginItem / ScopeEndItem pair gets
nested.

The logging is done unconditionally.  The intent is that the caller uses
something like:

  if (BT_LOG_ON_TRACE) {
      item.accept(loggingVisitor);
  }

to log at a given log level.

Philippe's changes:

* Add usage comments to `logging-item-visitor.hpp`.

* Move enumerator-to-string functions to `logging-item-visitor.cpp`.

* Move templates and everything `static` to `logging-item-visitor.cpp`.

* Log more details about some items.

* Reduce code redundancy.

* Use the standard Babeltrace 2 log statement format (therefore removing
  indentation).

* Log with BT_CLOGT() instead of BT_CLOGD().

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie8a95217564bfbaa59f78793d7ba0b47aad1d882
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8202
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12711

2 months agoCleanup: src.ctf.fs: remove unused decoder functions
Francis Deslauriers [Wed, 11 May 2022 22:00:24 +0000 (18:00 -0400)] 
Cleanup: src.ctf.fs: remove unused decoder functions

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I8c2610883c8730a36e3e4336c2dc48b67d3e6236
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8038
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12710

2 months agosrc.ctf.*: add old CTF IR const functions
Francis Deslauriers [Wed, 17 Apr 2024 17:53:23 +0000 (13:53 -0400)] 
src.ctf.*: add old CTF IR const functions

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I73f825b4127cff772904579c90806bd367a7fe36
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8012
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12709

2 months agosrc.ctf.fs: implement `MetadataStreamDecoder` class
Francis Deslauriers [Fri, 3 Nov 2023 19:15:49 +0000 (19:15 +0000)] 
src.ctf.fs: implement `MetadataStreamDecoder` class

This class offers a `decode()` method that decodes a potentially
packetized metadata stream as a `std::string`.

After decoding a buffer, the `pktInfo()` method may return packet
information of the packetized metadata stream.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iee867271fe6493b19c4bd77151409886b7c01ed9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8050
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12257

2 months agosrc/plugins/ctf/common/src: add item sequence iterator API
Philippe Proulx [Wed, 17 Apr 2024 17:52:29 +0000 (13:52 -0400)] 
src/plugins/ctf/common/src: add item sequence iterator API

This patch adds the item sequence iterator API, internal to the `ctf`
plugin, to be used by the source components (`src.ctf.fs`
and `src.ctf.lttng-live`).

An item sequence iterator can decode a sequence of packets using:

• A medium, which provides binary stream data to the iterator.
• A CTF IR trace class, which describes how to decode said data.

This makes it possible to completely decode CTF data streams without
ever needing to create trace IR objects. In other words, it's a
standalone CTF decoding library which, minus a few utilities borrowed
from the Babeltrace project, could even be reused in other projects.

The value of an item sequence iterator is an item. The item sequence
iterator doesn't actually create items as it advances: it has one
instance of each concrete item class and sets a pointer to one of those
as it advances (it's a single-pass input iterator).

Seek a specific packet beginning with the seekPkt() method.

Methods which make the iterator decode may append a cause to the error
of the current thread and throw `bt2c::Error`.

┌──────────────────────────────────────────────────────────────────────┐
│ NOTE: Currently, this isn't an STL-compliant iterator class: you     │
│ can't copy an instance and you can't get an end iterator, because    │
│ there's no item sequence (container) class (you need to check        │
│ whether or not the next() method returns `nullptr`). Also, the       │
│ typical STL type aliases such as `value` and `reference` aren't part │
│ of the class.                                                        │
└──────────────────────────────────────────────────────────────────────┘

This API and its implementation are inspired by the yactfr
(<https://github.com/eepp/yactfr>) element sequence iterator API,
conveniently written by the same author 😉.

Please read the class comments of `ctf::src::ItemSeqIter` and
`ctf::src::Medium` to learn how to use this API and how it
works internally.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I423cc934d2425331a09f16ba40fbeb6b5496ff3a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7966
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12256

2 months agocpp-common/bt2c/std-int.hpp: use dedicated enum. instead of `bool`
Philippe Proulx [Fri, 10 May 2024 19:41:10 +0000 (15:41 -0400)] 
cpp-common/bt2c/std-int.hpp: use dedicated enum. instead of `bool`

This makes the code clearer, for example

    bt2c::StdIntT<32, bt2c::Signedness::Signed>

vs.

    bt2c::StdIntT<32, true>

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icbb718dd36e11d5e072c7fc4b58fc2d4ca090d58
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12708

2 months agosrc.ctf.*: add `ctf::src::NullCpFinder`
Philippe Proulx [Fri, 10 May 2024 20:12:52 +0000 (16:12 -0400)] 
src.ctf.*: add `ctf::src::NullCpFinder`

An instance of this new class keeps a temporary code unit of length
`CodeUnitLenV` bytes to help finder a null codepoint (U+0000) in
contiguous buffers (especially when the encoded codepoint spans more
than one buffer).

See the comment of the new class to learn more.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I80feb4402cc0256d7c48c357ca23e355c4322ce0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12707

This page took 0.056934 seconds and 4 git commands to generate.