Simon Marchi [Thu, 5 Sep 2019 16:29:21 +0000 (12:29 -0400)]
cli: improve error logging in set_stream_intersections
I experienced some errors in set_stream_intersections, and found the
error messages to be very generic and non-helpful. This patch makes the
function use BT_CLI_LOGE_APPEND_CAUSE when possible and produce more
precise error messages.
Change-Id: I4db2859f8f76de95de12c4139c621b068e22d3ba Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2003 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Tue, 3 Sep 2019 14:35:23 +0000 (10:35 -0400)]
bt2: pass all params to `babeltrace.trace-info` query when computing stream intersection
TraceCollectionMessageIterator currently makes it mandatory to pass an
`inputs` parameter to source components when using the stream
intersection mode. It then picks out that parameter and passes just by
itself to the `babeltrace.trace-info` query.
This is not right for two reasons:
1. The `babeltrace.trace-info` query should be executed with the same
parameters as what the component will be created with. This is because
some parameters can influence the response of the query, such as
`clock-class-offset-ns` for `src.ctf.fs`.
2. The `inputs` parameter is not mandatory. It is a convention to which
source component classes can adhere to work with auto source discovery,
but it's not mandatory. Stream intersection mode should work even with
a source component class that doesn't use it.
A test is added, where a CTF trace is read using the stream intersection
mode, as well as a `clock-class-offset-s` parameter. Without this
patch, the test would fail because the trimmer components would be
created with a range that doesn't consider the offset. Therefore all
messages produced by the source (which have the offset applied) fall
outside the trimmers' ranges. With this patch, the
`babeltrace.trace-info` query returns stream ranges with the offset
applied, so the trimmers have the correct ranges.
Change-Id: I79c86cafafe123c6d306d196d5dde71002b711f7 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1998 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 28 Aug 2019 20:31:12 +0000 (16:31 -0400)]
ctf: remove `intersection-range-ns` from `babeltrace.trace-info` query
The `intersection-range-ns` field of the `src.ctf.fs` component class
response to the `babeltrace.trace-info` query is not essential, since it
can easily be computed from the stream ranges also in the response.
Remove it, and adjust users to compute the intersection themselves.
One user is the CLI and the other is the TraceCollectionMessageIterator
class in the Python bindings.
There is a small implementation detail change in
TraceCollectionMessageIterator. Previously, we would do one
`babeltrace.trace-info` query per port. With this patch, we pre-compute
the intersection range for each source component port and store it in a
port name to intersection mapping. When we create the trimmers, we just look
up that value.
It results in less queries and avoids computing the intersections many
times. It is also in line with how the CLI does.
Change-Id: Ic5ebded4d810ef992594941dde3316613909c98c Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1994 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 28 Aug 2019 19:01:10 +0000 (15:01 -0400)]
ctf: make src.ctf.fs handle a single trace
Now that traces with different UUIDs get grouped in different src.ctf.fs
instances, it's not (as) useful for one src.ctf.fs component to support
reading multiple traces at the same time.
This patch simplifies the src.ctf.fs component class to make it handle
only a single logical trace (which can actually be composed of multiple
traces with the same UUID).
Internally, it works the same way as before: we create one `struct
ctf_fs_trace` per input path. We then merge all of them to a single
one, the one that has the most expansive metadata.
Change-Id: I5a395cac3c379dedc06d98ccffa02b3750a35173 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1993 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 28 Aug 2019 17:13:07 +0000 (13:13 -0400)]
ctf: make src.ctf.fs not recurse
This patch makes the src.ctf.fs component class not recurse into the
directories passed as `inputs`. This affects instantion of a new
component as well as `babeltrace.trace-info` queries.
Recursion is no longer needed, because it is handled by the automatic
source discovery feature at the CLI and TraceCollectionMessageIterator
levels.
This means that the elements of the `inputs` array must point directly
to traces, i.e. the directory that directly contains the `metadata`
file.
Providing an input path that does not point to such a directory is
unacceptable and will be met with an error of this class:
CAUSED BY [src.ctf.fs: 'source.ctf.fs'] (/home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/fs.c:1140)
Path is not a CTF trace (does not contain a metadata file): `/home/smarchi/src/babeltrace/tests/data/ctf-traces/succeed/session-rotation`.
The bulk of the change is mostly in the
ctf_fs_component_create_ctf_fs_traces_one_root, which used to do the
recursion. It now handles a single path, and is therefore renamed
ctf_fs_component_create_ctf_fs_traces_one_path.
Change-Id: Idb0bbf11f822c50f467fa4e4f661e65242ea78e2 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1989 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Thu, 8 Aug 2019 19:22:02 +0000 (15:22 -0400)]
ctf: make src.ctf.fs group inputs by UUID in `babeltrace.support-info` query
When replying to the `babeltrace.support-info` query, the src.ctf.fs component
class currently groups all recognized CTF inputs in a single `ctf`
group. It then internally groups traces with the same UUID together to
process them as a single trace (to support LTTng's session rotation
feature).
This commit makes it group the inputs by UUID, which will naturally
assign all inputs beloning to one logical trace to one instance of
src.ctf.fs. Input traces without UUID are not placed in a group,
meaning that they will have their own src.ctf.fs component.
This paves the way to simplifying src.ctf.fs to support only a single
(logical) trace.
I added a test CTF trace for this, `session-rotation`, which consists of
two traces with three rotation chunks each. We therefore expect to have
two groups with three inputs each.
The new Python test checks the `babeltrace.support-info` query directly.
I also added a new .expect file for this new test trace, it will at
least verify that we have the right number of streams (which will be off
if the grouping doesn't work as intended).
Change-Id: I13374fff9bafa94c5d8f4b6bac1c64afadef7a46 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1844 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Tested-by: jenkins <jenkins@lttng.org>
This new internal function gets the trace class's UUID from the AST,
without having to create trace IR and CTF IR trace classes, which is a
much slower process (many allocations and checks).
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I04d58c66a461219ca01bf120417d629d9a1b9d10
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1843
CI-Build: Simon Marchi <simon.marchi@efficios.com> Tested-by: jenkins <jenkins@lttng.org>
Philippe Proulx [Tue, 9 Jul 2019 23:40:45 +0000 (19:40 -0400)]
ctf: refactor metadata decoder to always have an instance
This patch changes the internal `ctf` plugin's metadata decoder API so
that you need to create a decoder instance to read properties instead of
calling ctf_metadata_decoder_packetized_file_stream_to_buf().
Now, you create a metadata decoder, you call
ctf_metadata_decoder_append_content() (similar to what was called
ctf_metadata_decoder_decode()), and then you can get the decoder's
current properties:
The decoder's configuration contains two new flags:
`create_trace_class`:
Controls whether or not ctf_metadata_decoder_append_content()
invokes the AST visitor to generate trace class objects.
Trace classes are not needed, for example, for the `metadata-info`
query.
`keep_plain_text`:
Controls whether or not the decoder accumulates the metadata
stream's plain text when you call
ctf_metadata_decoder_append_content().
This needs to be true to use ctf_metadata_decoder_get_text().
The goal of all this is to eventually add new metadata property getters
which do not need to create trace classes or to keep the metadata plain
text.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: If1095da91aee0f446d7f5efcec765e5abbb2b30a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1842
CI-Build: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Simon Marchi <simon.marchi@efficios.com> Tested-by: jenkins <jenkins@lttng.org>
Simon Marchi [Thu, 29 Aug 2019 03:22:04 +0000 (23:22 -0400)]
ctf: use create + append/insert functions when possible
Make the query code use the container value functions that create a new
empty map/array and append it to the container at the same time. It
requires less lines of code, but also makes ownership management easier:
from the start the created container is owned by the parent container.
So there is no need to track it and free it on failure.
Change-Id: Ie0e81c67f50c721ef62e159f6f1d28380078ca86 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1995 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Wed, 28 Aug 2019 18:30:57 +0000 (14:30 -0400)]
ctf: remove ctf_fs_trace::name
Now that we don't report the name of CTF traces in
`babeltrace.trace-info`, it is no longer useful to invent a name for
each trace. So remove the ctf_fs_trace::name field, and everything
related to it.
Note that the name set on the bt_trace (in set_trace_name) does not
depend on this field.
Change-Id: Ia1d3e917e7b1c553c0da0c8365cda9ec600c854b Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1991 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Wed, 28 Aug 2019 17:44:20 +0000 (13:44 -0400)]
ctf: remove unused fields from `babeltrace.trace-info` query
The response of the src.ctf.fs component class to the
`babeltrace.trace-info` query object contains a few fields that are not
used at the moment. Remove them, before somebody uses them, making us
stuck with them for eternity.
The removed fields are:
- stream class ids
- stream ids
- stream paths
- trace path
- trace range-ns
- trace name
The field `intersection-range-ns` will be removed in a separate patch.
Change-Id: Iee673acbb766cd951e758b5186eabb6fc058b442 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1990 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Tue, 27 Aug 2019 04:50:06 +0000 (00:50 -0400)]
python: fix all 'is assigned to but never used' warnings
Fix all instances of this warning (code F841) found in the repo by
flake8. In one instance (in test_plugin.py), I added an assertion to
use the variable. In all others, I considered the variable not useful
and removed it.
Simon Marchi [Mon, 26 Aug 2019 20:52:33 +0000 (16:52 -0400)]
autodisc: don't accept NULL values for `support-info` query `group` key
It is not necessary to support that, and it doesn't help much in
implementing component classes. To keep the support-info protocol a bit
simpler, let's make it mandatory that if you have a `group` key, it must
be a string.
Change-Id: I45aa0a6fb57727d73d9fea48fbebc04dc9c0d5f5 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1977 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Mon, 26 Aug 2019 20:24:21 +0000 (16:24 -0400)]
autodisc: improve logging
Improve the logging in the support_info_query_all_sources function:
- Include the group after a successful query
- Include the group when announcing the winner
- Format messages according to our standard, "message: key=value, ...".
Change-Id: I9833ea63314cde912c1da56d6ed2483f34783f17 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1976 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Mon, 12 Aug 2019 22:31:15 +0000 (18:31 -0400)]
bt2: make ComponentSpec take a component class object
... rather than a plugin and component class name. It can be a user
component class:
class MySource(bt2._UserSourceComponent, ...):
...
spec = bt2.ComponentSpec(MySource)
or a component class from a plugin:
cc = bt2.find_plugin('my_plugin').source_component_classes['cerfeuil']
spec = bt2.ComponentSpec(cc)
This is a bit more general compared to taking a plugin name and a
component class name, since it allows passing an component class that
does not come from a plugin. It also allows the user to use component
classes from plugins in non-standard locations, by looking up plugins
manually with bt2.find_plugins_in_path.
For convenience, there is a new static method
bt2.ComponentSpec.from_named_plugin_and_component_class that creates a
ComponentSpec from a plugin and component class names.
Change-Id: I39e3fec6bbc7e7a9ba375065c9318b61b1791e35 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1890
CI-Build: Francis Deslauriers <francis.deslauriers@efficios.com> Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Mon, 26 Aug 2019 20:26:33 +0000 (16:26 -0400)]
autodisc: cast when assigning to different enum type
Gets rid of these warnings with clang:
/home/smarchi/src/babeltrace/src/autodisc/autodisc.c:766:13: warning: implicit conversion from enumeration type 'auto_source_discovery_internal_status' (aka 'enum auto_source_discovery_internal_status') to different enumeration type 'auto_source_discovery_status' (aka 'enum auto_source_discovery_status') [-Wenum-conversion]
status = internal_status;
~ ^~~~~~~~~~~~~~~
/home/smarchi/src/babeltrace/src/autodisc/autodisc.c:778:13: warning: implicit conversion from enumeration type 'auto_source_discovery_internal_status' (aka 'enum auto_source_discovery_internal_status') to different enumeration type 'auto_source_discovery_status' (aka 'enum auto_source_discovery_status') [-Wenum-conversion]
status = internal_status;
~ ^~~~~~~~~~~~~~~
Change-Id: Id4cdaaf20da1789e604d346ff2c08239352eb381 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1975 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Tue, 20 Aug 2019 00:56:26 +0000 (20:56 -0400)]
autodisc: make it possible to interrupt auto source discovery
It is currently not possible to interrupt babeltrace2 while it is doing
auto source discovery. However, it can be a quite long process that the
user might want to interrupt using ctrl-C. This patch makes it possible
to do that.
An interrupter object is taken by the auto source discovery code and
passed all the way to support_info_query_all_sources. In the CLI, the
global `the_interrupter` object, which is set on sigint, is passed.
Because support_info_query_all_sources (and other internal functions)
can now return a few different values (success with a match, success
without a match, error and interrupted), I changed it to return an enum
type. The entry point of auto source discovery,
auto_discover_source_components, can now return "interrupted" as well.
However, since that function doesn't return "no match", I didn't want to
make it use the same return type as support_info_query_all_sources. I
therefore made an "internal" and public version of the status enum.
With this patch, there is no way to interrupt an auto source discovery
started from Python.
Change-Id: I0040c7fab1887c4e05decd0659fa8ff3c85a16a1 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1972 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Simon Marchi [Sat, 17 Aug 2019 05:24:46 +0000 (01:24 -0400)]
bt2: make _create_event_message's parent parameter mandatory
The `parent` parameter of _create_event_message currently has the None
default value. However, None is never a valid value, as parent must
either be a Stream or a Packet. Having a None default value makes it
look like the parameter is optional, but is actually always required.
Therefore, remove the None default value from the parameter.
Change-Id: Id0f8d64006ca25281529fc6bb3b9912365799f44 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1962 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Tue, 13 Aug 2019 15:56:18 +0000 (11:56 -0400)]
ctf: make src.ctf.fs append error causes
This patch makes the src.ctf.fs plugin code append error causes whenever
an error status is returned.
A few new macros are added to comp-logging.h to support that.
Some functions are called both in component context and component class
context. When appending error causes, we need to call the
function/macro for the right context. My solution to this is to pass
both bt_self_component and bt_self_component_class pointers, but expect
only one of them to be set. The new macro
BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE takes care of calling the right
function for whichever is set.
Change-Id: I8d54f463d9a13066abdc140ef41f374e4daed303 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1966 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 21 Aug 2019 23:47:32 +0000 (19:47 -0400)]
Fix: ctf: fix possible use-after-free in ctf_fs_component_create
The error path destroys the ctf_fs_component, but doesn't reset the
variable, so we return a pointer to free'd memory. We should be
returning NULL in the error case. Fix it by assigning to NULL after
destroying the ctf_fs_component.
Change-Id: Ib7afd03009dc646460f77fae331920307229220a Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1973 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CID 1404550 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking tsdl suggests that it may be null,
but it has already been dereferenced on all paths leading to the
check.
Reported-by: Coverity - Dereference before null check (REVERSE_INULL) Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I7566cbd74529e93587079d163bb1691e420f723f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1974 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Fix: sink.utils.counter: possible NULL pointer dereference
If the null check at line 148 is true, the `counter` pointer might be
used will be used while being NULL by the
`destroy_private_counter_data()` function.
scan-build report:
Access to field 'msg_iter' results in a dereference of a null pointer
(loaded from variable 'counter')
Issue
=====
We might use of `trace` pointer after freeing it in the error path.
Solution
========
Move the `fclose()` call (and surroundings) before the `end` label as
the `fh` pointer is only initialized after the only possible `goto end`.
Simon Marchi [Fri, 16 Aug 2019 03:05:13 +0000 (23:05 -0400)]
bt2: don't show warning when query method raises a non-error exception
I noticed that when a Python query raised bt2.UnknownObject, we show
this warning:
W BT2-PY component_class_query@native_bt_component_class.i.h:802 Failed to call Python class's _bt_query_from_native() method: py-cls-addr=0x6190001090a0
In my opinion, a query returning "unknown object" is part of the normal
course of operation, and we should not show a warning. So, only show it
when the exception gets translated to a status < 0. Also, append an
error cause while at it in case of error.
Change-Id: I079f67b74df881ab000c6e223667ca72dcd52713 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1952
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Philippe Proulx [Fri, 16 Aug 2019 22:06:41 +0000 (18:06 -0400)]
Fix: pass `inputs` parameter to implicit `src.ctf.lttng-live`, not `url`
Since the `src.ctf.lttng-live` component class started to handle the
`babeltrace.support-info` query object, its component accepts the
`inputs` array parameter, not the `url` string parameter.
The chosen syntax uses curly braces to delimit the map. It uses an
equal sign between the key an value, to be consistent with the syntax of
the implicit map at the top-level of `--params` values.
Speaking of which: it's not done in this patch, but it should be
possible to make the new function a bit more generic and re-use it for
parsing the top-level dict of `--params` values.
Change-Id: I1400ff6a2cf6c9132a9c5dd731a462f43225146b Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1936 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Thu, 15 Aug 2019 00:06:21 +0000 (20:06 -0400)]
cli: exit with error if a plugin fails to load
The CLI is currently permissive when plugins fails to load, it will
display an error but carry on. To make it easier for users to catch
configuration and programming problems, this patch changes that be
strict. If a plugin fails to load (for example, Python syntax error),
the CLI stops and the error is reported to the user.
If this ever becomes a problem (a user would like to carry on even
though some plugin fails to load), we can add a switch like
`--ignore-plugin-loading-error` to have a permissive mode.
Change-Id: Ic89d4e044ecdc34a6e169309479e17bb947ae637 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1937 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 14 Aug 2019 20:47:26 +0000 (16:47 -0400)]
cli: set log levels earlier
The problem this patch is aiming to solve is that the effective log
level is not set when executing bt_config_convert_from_args. For
example, bt_python_bindings_bt2_log_level is still NONE, only to be set
later. So if Python plugin fails to be imported during the auto source
discovery phase, nothing will be logged, making debugging quite
difficult. Any argument passed (top level --log-level, --debug or
--verbose) won't help because they will take effect later, when we call
set_auto_log_levels.
This patch moves the call to set_auto_log_levels earlier, as soon as we
know what the default log level will be. For all commands but
`convert`, it is after we are done parsing the top-level arguments. The
default log level will be the most verbose any --debug, --verbose or
--log-level argument passed.
With the `convert` command, it is possible to pass --debug and
--verbose, with the same effect as the top-level equivalents. So for
this command, we call set_auto_log_levels just after parsing its
arguments.
The --debug argument sets the log level to TRACE and the --verbose
argument sets it to INFO. If more than one of --debug, --verbose and
--log-level are specified, the most verbose level of all specified
arguments is chosen.
Note that the --log-level argument of the convert command is not the
same as the top-level's --log-level argument. The argument of the
convert command sets the --log-level of a specific component or
auto-source-discovery input.
The behavior of the environment variables LIBBABELTRACE2_INIT_LOG_LEVEL,
BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL and
BABELTRACE_PYTHON_BT2_LOG_LEVEL is kept. If they are specified, they
force the log level of the corresponding subsystem, overriding the
log level specified on the command line.
Change-Id: I9ac558737df4789fc8f5bd8d0240887b3b11b295 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1935 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Wed, 14 Aug 2019 17:49:51 +0000 (13:49 -0400)]
cli: return if bt_plugin_find_all_from_dir fails in load_dynamic_plugins
If the call to bt_plugin_find_all_from_dir in load_dynamic_plugins
returns an error (a negative status code), we currently continue
execution as if nothing happened.
This patch makes it so that we exit the loop and report the error to the
caller.
Change-Id: Ib22813b92fe06156cde1681c55651a294cd67909 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1934 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Thu, 15 Aug 2019 15:56:14 +0000 (11:56 -0400)]
Fix: lib: increment refcount of bt_value_null when copying it
Value copy functions must return a new reference. This is not done for
bt_value_null_copy, which causes refcount imbalance when a null value
gets copied. A bug caused by this can be triggered with:
$ git:(3e3535450850) ✗ LIBBABELTRACE2_INIT_LOG_LEVEL=W ~/build/babeltrace/src/cli/babeltrace2 -c src.ctf.fs --params='yo=null,madame=null,la=null'
...
08-15 11:58:25.070 2757 2757 W LIB/VALUE bt_value_null_instance_release_func@value.c:72 Releasing the null value singleton: addr=0x7f070e1fc8e0
08-15 11:58:25.070 2757 2757 F LIB/VALUE bt_object_put_ref@object.h:367 Babeltrace 2 library precondition not satisfied; error is:
08-15 11:58:25.070 2757 2757 F LIB/VALUE bt_object_put_ref@object.h:367 Decrementing a reference count set to 0: addr=0x7f070e1fc8e0, ref-count=0
08-15 11:58:25.070 2757 2757 F LIB/VALUE bt_object_put_ref@object.h:367 Aborting...
Change-Id: I338e6700201892cbe582719bf349041f316d78d8 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1942 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Simon Marchi [Thu, 15 Aug 2019 15:24:24 +0000 (11:24 -0400)]
Fix: cli: increment bt_value_null ref count when returning null value
The ini_parse_value function returns a new reference to a value.
When return a null value, it needs to acquire a new reference to
bt_value_null to account for that.
A crash can be triggered because of this bug with:
$ LIBBABELTRACE2_INIT_LOG_LEVEL=W ~/build/babeltrace/src/cli/babeltrace2 -c src.ctf.fs --params='yo=null,madame=null,la=null'
08-15 11:27:23.947 8793 8793 W LIB/VALUE bt_value_null_instance_release_func@value.c:72 Releasing the null value singleton: addr=0x7fb46d3038e0
08-15 11:27:23.947 8793 8793 F LIB/VALUE bt_object_put_ref@object.h:367 Babeltrace 2 library precondition not satisfied; error is:
08-15 11:27:23.947 8793 8793 F LIB/VALUE bt_object_put_ref@object.h:367 Decrementing a reference count set to 0: addr=0x7fb46d3038e0, ref-count=0
08-15 11:27:23.947 8793 8793 F LIB/VALUE bt_object_put_ref@object.h:367 Aborting...
Change-Id: I6748fd9d8a7ba89728f0e4ddb9ea62bf423fdc91 Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1941 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Philippe Proulx [Fri, 16 Aug 2019 03:24:12 +0000 (23:24 -0400)]
cli: `convert` command: do not allow more than one sink component
It's a nonsense to allow more than one component sink because, starting
from the muxer's single output port, there's a chain of components until
it reaches a sink. We don't have any tee filter, so we can't have more
than one sink: the second one won't get connected.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ibec54ae29b64bb0fb8637f1b37131f05abc53b77
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1953 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Philippe Proulx [Fri, 16 Aug 2019 03:04:06 +0000 (23:04 -0400)]
cli: make --plugin-path and --omit-{system,home}-plugin-path global opts
This patch makes the `--plugin-path`, `--omit-system-plugin-path`, and
`--omit-home-plugin-path` options global options, in that you must
specify them before the command's name.
This change exists because those three options were handled by all five
commands anyway, so there was a lot of code redundancy.
Tests are adapted accordingly. Everything about those three options in
`test_convert_args` is removed as they will never be part of the
`--run-args` output now.
This patch makes a `src.ctf.lttng-live` component class handle the
`babeltrace.support-info` query object. The query method replies a
weight of 0.75 (arbitrary, but it leaves some room for other component
classes to recognize this very specific URL format) when the input
string matches
net://HOST[:PORT]/host/TGTHOST/SESSION
This makes it possible to create a conversion graph with a
`src.ctf.lttng-live` source like this:
Note that this will use the component's default "session not found"
action which is to continue, so the `src.ctf.lttng-live` message
iterator will never end. The legacy mode still works, however; when you
do:
Philippe Proulx [Fri, 16 Aug 2019 01:01:49 +0000 (21:01 -0400)]
lib: make empty array/map appending/inserting functions return new object
This makes the bt_value_array_append_empty_array_element(),
bt_value_array_append_empty_map_element(),
bt_value_map_insert_empty_array_entry(), and
bt_value_map_insert_empty_map_entry() accept a new optional output
parameter to return the created empty value object.
The goal of appending/inserting an empty array/map value object is
typically to fill it afterwards, so it makes this less painful, for
example:
bt_value *inner_arr_obj;
status = bt_value_array_append_empty_array_element(outer_array_obj,
&inner_arr_obj);
assert(status == 0);
status = bt_value_array_append_bool_element(inner_arr_obj, true);
assert(status == 0);
status = bt_value_array_append_string_element(inner_arr_obj, "id");
assert(status == 0);
You can pass `NULL` as this new parameter.
The returned reference is borrowed.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2cd3359f357a3eb1da52c0e1426ef7804a4b13aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1948 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tests: ctf: add tracers timestamp quirks workaround test cases
This commit adds test traces and test cases to cover the `src.ctf.fs`
workarounds used to support timestamp corner cases or bugs in the
tracers.
Note: I manually modified the test traces to contain problematic
timestamp values using an hex editor as if there would be created by an
affected tracer.
Test traces
===========
* `event-after-packet` lttng test trace
This trace `event-after-packet` was modified manually to simulate the
hard to reproduce `event-after-packet` LTTng tracers bug.
When the bug occurs, the timestamp of the last event of a packet is larger than
the `timestamp_end` of it's own packet. It makes it look like the event
happened after the packet was closed which is non compliant with the CTF
specification.
To create a trace exhibiting this bug, the `timestamp_end` field of
the last 2 packets was made one clock cycle smaller than the timestamp
of the last event of the said packet.
This bug was fixed in the follow versions of the LTTng tracers:
- lttng-ust 2.11.0
- lttng-module 2.11.0
- lttng-module 2.10.10
- lttng-module 2.9.13
* `lttng-crash` test trace
This trace was modified manually to simulate a trace resulting from the
lttng-crash utility.
When extracting a trace using the lttng-crash utility the `timestamp_end` of
some packets may be left uninitialized with the default value of 0.
To create a trace exhibiting this behavior, the `timestamp_end` of the last
three packets were set to 0.
This is _not_ a bug and all LTTng tracers can produce such trace.
* `event-before-packet` barectf test trace
This trace `event-before-packet` exhibits a barectf bug where the first
event of the second packet has a timestamp smaller than the
`timestamp_begin` field of its own packet.
This bug was fixed in barectf tracer version 2.3.1.
Test cases
==========
* `trace-info` query
- Add test case for `event-after-packet` LTTng quirk,
- Add test case for `lttng-crash` workaround.
Both of this test traces used in these test cases are based on the same
trace and the end result on the `trace-info` query is the same. We use
the same code for both test cases.
* Trace decoding
-Add `test_succeed` cases for all three of the above test traces.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Icfdb8052aa2a88038e22ad6a58f391b6d8dbd3df
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1542 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
See prior commit titled:
src.ctf.fs: index: accommodate bug in barectf tracer
for an explanation of the non-compliance of some barectf traces.
How this commit fixes the decoding for the affected traces
==========================================================
When about to emit a packet beginning message, check if the said packet
might be affected by barectf's `event-before-packet` bug by looking at
the version. If it's the case, delay the emission of the packet
beginning message until we decoded the first event of the packet. We
then check if the event is indeed before the packet.
For affected packets, we create packet beginning message using the
timestamp of the first event.
If there is event in the packet, there is nothing to fix so we emit the
packet beginning message when we are about to emit the packet end
message.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ia94e94edef27971c4acf7ab62463c80411ff1978
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1552 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
See prior commit titled:
src.ctf.fs: index: accommodate bug in LTTng tracers
for an explanation of the non-compliance of some LTTng traces.
How this commit fixes the decoding for the affected traces
==========================================================
When about to emit a packet end message, check if the said packet is
affect by LTTng's `event-after-packet` bug. If it's the case, omit to
update the default_clock_snapshot to the `timestamp_end` of the packet.
This will expand the packet time span to the contain all its events.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I205caf0243c1d6f270bdb1b6508bb55a0806ba19
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1550 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
See previous commit titled:
src.ctf.fs: index: accommodate lttng-crash timestamp quirk
for an explanation of the non-compliance of lttng-crash traces.
How this commit fixes the decoding for the affected traces
==========================================================
When about to emit a packet end message, check if the said packet is
affected by the trace-crash non-compliance. If it's the case, omit to
update the default_clock_snapshot to the `timestamp_end` of the packet.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: If965a424afa160692c2ec148fc8f60d3d9ac1273
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1548 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
This commit is to accommodate the indexing of non-compliant CTF traces
produced by LTTng tracers and extracted by the lttng-crash utility.
What makes those traces non-compliant ?
=======================================
The lttng-crash is used to extract a trace from the tracing buffers from
non-volatile memory following a system crash. Because a system crash can
happen at any time, it's possible that some tracing packets might not
have been closed properly. It's possible to observe this by looking at
the `timestamp_end` field of the packets. They might be left to their
initial value of 0 when their `timestamp_begin` are often larger than 0.
This has the higher level effect that affected packets have a
`timestamp_end` smaller than their `timestamp_begin`, as if their end
time was before the beginning time.
How this commit fixes the index for the affected traces
=====================================================
For each index entry, if the entry's `timestamp_end` is 0 and the
`timestamp_begin` is not 0:
- If it's the stream file's last packet: set the packet index entry's end
time to the packet's last event's time, if any, or to the packet's
beginning time otherwise.
- If it's not the stream file's last packet: set the packet index
entry's end time to the next packet's beginning time.
Affected versions
=================
All current and future lttng-ust and lttng-modules versions are affect
because this really cannot be fixed by the tracers because lttng-crash
only tries to make the most of a critical situation (i.e. a system
crash).
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib6ff9683b676983d8691f514f4d6c3e5c8c7e071
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1436 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
This commit is to accommodate the indexing of non-compliant CTF traces
produced by the barectf tracer.
What makes those traces non-compliant ?
=======================================
A bug in barectf leads to events being emitted with timestamp less than
their packet's `timestamp_begin` field.
At a higher level, such event would appear as before the beginning of
its own containing packet and not within the range of any packet of the
trace.
How this commit fixes the index for the affected traces
=====================================================
For each index entry excluding the first:
- Decode the packet until the first event and use the timestamp of
this event as the `timestamp_begin` of this index entry.
- Set the previous index entry's `timestamp_end` to the
`timestamp_end` of the current index entry.
Affected versions
=================
- before barectf 2.3.1
This commit is to accommodate the indexing of non-compliant CTF traces
produced by LTTng tracers.
What makes those traces non-compliant ?
=======================================
A bug in lttng tracers may lead them to emit events with timestamps that
are greater than the timestamp_end of the their packets.
At a higher level, such event would appear as not within the range of a
packet in the trace.
How this commit fixes the index for the affected traces
=======================================================
For each index entry:
- If it's the stream file's last packet: set the packet index entry's end
time to the packet's last event's time by decoding the packet, if
any, or to the packet's beginning time otherwise.
- If it's not the stream file's last packet: set the packet index
entry's end time to the next packet's beginning time.
Affected versions
=================
- before lttng-ust 2.11.0
- before lttng-module 2.11.0
- before lttng-module 2.10.10
- before lttng-module 2.9.13
This commit adds a utility function to extract tracer version of a given
trace.
Because, it was discovered that some tracers may produce non-compliant
CTF traces more-or-less frequently. To accommodate those external tools,
we will add ad-hoc fixes for the affected version. We thus need a way to
check the tracer versions of the traces.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I67e73a5928dfac0cebc1135552f5525af930ebfc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1418 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Adds functions to extract the timestamp of the first and last event of
the current packet.
BT_HIDDEN
enum bt_msg_iter_status bt_msg_iter_first_event_clock_snapshot(
struct bt_msg_iter *notit, uint64_t *first_event_cs);
Those functions use the `decode_until_state()` function to decode the
current packet until one of two specific states and then used the clock
value of the default clock class.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I18736151fd8367fb33c6b46d81a860f54432ad55
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1432 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Dry-run mode can be used when component classes need to decode CTF
packets but do not want the `bt_msg_iter` to create and use the
Babeltrace library objects (bt_field, bt_message_*, etc.).
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I336ec4c893835e7b1d6f32262841793f7543aa06
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1417 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
ctf: only reset state of `bt_msg_iter` on _reset()
The `bt_msg_iter` configuration should be left untouched by the reset.
The `bt_msg_iter_reset()` is used at the creation of the `bt_msg_iter`
(`bt_msg_iter_create()`) and when seeking with it
(`bt_msg_iter_seek()`). It's also used by `src.ctf.fs` message iterators
when seeking is done.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I2ab948858aa5b955a3063174c9887c54d98bad5d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1416 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
You can set the user attributes of those objects at creation time, when
calling the creation method, or when appending a structure field class
member or a variant field class option for `_StructureFieldClassMember`
and `_VariantFieldClassOption`.
To make the `_user_attributes` property of `_StructureFieldClassMember`
and `_VariantFieldClassOption` above possible, I made them wrap a real
BT pointer and keep a reference on the owning field class, making all
the properties make a call to the library instead of the object just
containing them.
In `test_field_class.py`, because there's now a common property to test
for each field class, the new `_TestFieldClass` mixin does that,
requiring a _create_default_field_class() method which accepts custom
positional and keyword arguments to create a specific default field
class to test.
Philippe Proulx [Wed, 14 Aug 2019 17:34:10 +0000 (13:34 -0400)]
sink.text.details: print user attributes
This patch makes a `sink.text.details` component print user attributes.
The component only prints user attributes when the map value is not
empty.
The output looks like this:
Event class (ID 0):
User attributes:
domain: Python
ip: Length 4:
[0]: 192
[1]: 168
[2]: 0
[3]: 100
weight: 17.231600
with-net: Yes
...
The new write_value() function textually and recursively serializes a
value object. When writing a map value object, the keys are sorted
first.
The change brought by this patch is not invasive in that all the current
test expectation files do not need any change because the sources never
set any user attribute. The goal of this patch is not to add any textual
noise.
When an enumeration, a structure, or a variant field class has user
attributes, the component prints the mappings, members, and options
indented within a dedicated section, for example:
Payload field class: Structure (3 members):
User attributes:
a: 23
b: 'log'
Members:
hello: String
bbb: Boolean
opt: Option:
Content: Unsigned integer (64-bit, Base 10)
The same strategy applies to structure field class members and variant
field class options:
Payload field class: Structure (3 members):
hello:
Field class: String
User attributes:
factor: 17.150000
bbb: Boolean
opt: Option:
Content: Unsigned integer (64-bit, Base 10)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icf3060dbf23bab607ebb7af6e839aa5b28bd2658
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1926 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Philippe Proulx [Wed, 14 Aug 2019 03:21:46 +0000 (23:21 -0400)]
lib: add user attributes property to metadata, stream, and trace objects
This patch adds an optional user attributes property to the following
trace IR objects:
* Clock class
* Event class
* Field class
* Structure field class member
* Variant field class option
* Stream class
* Stream
* Trace class
* Trace
A user attributes object is a map value object which adds custom
information to any of the objects above. It is entirely up to the user
to set user attributes. At creation time, all the objects above contain
an initial, empty map value.
CTF 2 will very likely have such user attributes for metadata objects,
so Babeltrace 2.0 will be ready.
For CTF 2, it is intended that user attributes will be namespaced to
reduce or eliminate clashes, for example using URLs or domain names,
which are also typically used for Java packages and XML namespaces:
CTF 2 will only have user attributes for metadata objects, but I decided
to also have user attributes for long-lived data objects: streams and
traces.
This is not enforced in Babeltrace however: the user is free to put
whatever she needs into this map value.
There's a bt_*_set_user_attributes() function to set the user attributes
of an object and
bt_*_borrow_user_attributes()/bt_*_borrow_user_attributes_const()
functions to borrow them from the object.
This patch changes when structure field class members and variant field
class options are frozen:
Before this patch:
When you append to a structure/variant field class, the
member/option is frozen, including its field class.
With this patch:
When you append to a structure/variant field class, the
member/option itself is not frozen, but its field class is.
The member/option is frozen when its containing structure/variant
field class is frozen.
This makes it possible to append a member/option to a structure/variant
field class, borrow that member/option, and then set its user attributes
before the whole structure/variant field class is frozen.
Those are non-const versions of the existing
bt_field_class_variant_borrow_option_by_index_const() and
bt_field_class_variant_borrow_option_by_name_const().
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I322c202c35d815012d2f6de494dce76a161692e4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1920 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Philippe Proulx [Tue, 13 Aug 2019 23:35:12 +0000 (19:35 -0400)]
bt2: add bit array field class and field support
This patch adds bit array field class and field support to the Python
bindings.
A bit array field class has a `length` property (number of bits in the
array).
As of this patch, a bit array field is not a Python sequence. It could
become in the future however. The way to access a bit array field's
value is the `value_as_integer` property which simply wraps the
corresponding library functions.
A bit array field is not considered a numeric field. Its _spec_eq()
method only compares if the other object is also a bit array fields.
I did not implement the __bool__() operator because it will need to
satisfy the Python sequence protocol (length is not 0, which in fact is
always the case with a bit array field), should we decide as such in the
future. I implemented the __len__() operator however which is
straightforward.
Philippe Proulx [Tue, 13 Aug 2019 23:09:25 +0000 (19:09 -0400)]
sink.ctf.fs: write bit array field classes and fields
This patch makes a `sink.ctf.fs` component handle bit array field classes
and fields. Because CTF 1.8 has no bit array field class type, it makes a
best effort and translates it to an unsigned integer field class with
a hexadecimal base.
When a `src.ctf.fs` component reads a trace generated by `sink.ctf.fs`
where the input trace IR contained bit array field classes, the
corresponding unsigned integer field classes will stay unsigned integer
field classes; the source component has no way to determine if the
metadata describes a bit array field class or a genuine unsigned integer
field class. However, the CTF 1.8 to CTF 1.8 scenario will always be
unambiguous because a `src.ctf.fs` component never creates bit array
field classes.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6375723d8513b06f984dc27f88d3d9b668191d21
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1911 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Philippe Proulx [Tue, 13 Aug 2019 21:34:02 +0000 (17:34 -0400)]
lib: add bit array field class and field types
This patch adds the bit array field class (FC) and field to the
available library types.
A bit array field is a simple array of bits. As opposed to integer
fields, a bit array field has no sign: it does not contain a quantity.
Such a field can be used to hold CPU register values, for example, or an
array of flags which is typically read and written as a (small) unsigned
integer.
CTF 2 will very likely have such a type, so Babeltrace 2.0 will be
ready.
You create a bit array FC with bt_field_class_bit_array_create(). This
function expects a length parameter which must be in the [1, 64] range
as of this version. The length is the number of bits in the array. You
can get the length of a bit array with
bt_field_class_bit_array_get_length().
You can set the value of a bit array field with
bt_field_bit_array_set_value_as_integer(). This function accepts an
unsigned integer and conceptually sets all the bits of the array
accordingly, where the _first_ bit of the array is the LSB of the value.
In other words, should there be a bit accessor (by index), getting the
value of bit 0 would return the LSB of that unsigned integer:
0 1 1 0 1 1 0 1
^ MSB: bit 7 ^ LSB: bit 0
Unsigned integer value: 0x6d
As such, you can get the value of the bit array with
bt_field_bit_array_get_value_as_integer(). Again, the value of bit 0 is
the LSB of the returned unsigned integer.
I chose to apply a mask to the received value in
bt_field_bit_array_set_value_as_integer() to ensure that there's no set
bit outside the bit array's range. This is to lessen the user's burden
instead of a having a precondition assertion. This in turns guarantees
that bt_field_bit_array_get_value_as_integer() always returns a value
without superfluous set bit. If this automatic masking becomes a
performance issue in the future, then we can add another function which
expects the user to do it (with a precondition assertion).
This patch does not adapt existing plugins and the Python bindings to
use and wrap the new bit array FC and field; this work is reserved for
subsequent patches.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8ba4d111df275962cfa9f2c4f754f83a1de40e29
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1907 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Philippe Proulx [Tue, 13 Aug 2019 15:58:10 +0000 (11:58 -0400)]
bt2: add option field class and field support
This patch adds option field class and field support to the Python
bindings.
You can create an option field class with
_TraceClass.create_option_field_class(). This method requires the
optional field class and also accepts an optional selector field class
(just like the library's equivalent bt_field_class_option_create()
function).
An option field class only has the `field_class` (the optional field
class) and `selector_field_path` (can be `None`) properties.
An option field is similar to a variant field:
* You can use the `has_field` property to set whether or not the option
field has an optional field.
* You can access the optional field with the `field` property, which
returns `None` when the option field has no field.
* The __bool__() operator of an option field is the equivalent of the
`has_field` property.
* You can use the `value` property (write only, like
`_VariantField.value`) to assign a value to the optional field. This
property also sets `has_field` to `True` so it's always safe to use.
Philippe Proulx [Tue, 13 Aug 2019 00:16:09 +0000 (20:16 -0400)]
sink.ctf.fs: write option field classes and fields
This patch makes a `sink.ctf.fs` component handle option field classes
and fields. Because CTF 1.8 has no option field class type, it makes a
best effort and translates it to a variant field class with two
options:
* An empty structure field class (option field contains nothing).
* The optional field class itself.
The tag field class is always generated before the variant field class
and is an 8-bit unsigned enumeration field class.
For example, a `sink.ctf.fs` component would translate an optional
string field class to:
/*
* This enumeration field class and the following variant field
* class were a trace IR option field class.
*/
enum : integer { size = 8; align = 8; } {
none = 0,
content = 1,
} __module_name_tag;
variant <__module_name_tag> {
struct { } none;
string { encoding = UTF8; } content;
} module_name;
When a `src.ctf.fs` component reads a trace generated by `sink.ctf.fs`
where the input trace IR contained option field classes, the
corresponding variant field classes will stay variant field classes; the
source component has no way to determine if the metadata describes an
option field class or a genuine variant field class. However, the CTF
1.8 to CTF 1.8 scenario will always be unambiguous because a
`src.ctf.fs` component never creates option field classes.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib83e011f73795d70cd8545f55ea87e0bf10b68bc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1901 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>