babeltrace.git
4 years agolib: add internal object pool API and use it; adapt plugins/tests
Philippe Proulx [Fri, 18 May 2018 17:32:37 +0000 (13:32 -0400)] 
lib: add internal object pool API and use it; adapt plugins/tests

Pooling
=======
This patch adds the `bt_object_pool` (object pool) internal API.

From <https://en.wikipedia.org/wiki/Object_pool_pattern>:

> The object pool pattern is a software creational design pattern that
> uses a set of initialized objects kept ready to use – a "pool" –
> rather than allocating and destroying them on demand. A client of the
> pool will request an object from the pool and perform operations on
> the returned object. When the client has finished, it returns the
> object to the pool rather than destroying it; this can be done
> manually or automatically.
>
> Object pools are primarily used for performance: in some
> circumstances, object pools significantly improve performance.

When initializing an object pool with bt_object_pool_initialize(), you
provide a function which can allocate a brand new object from memory, as
well as a function which can destroy and deallocate an existing object.
As of this patch, the destroy function is only used when you call
bt_object_pool_finalize() to finalize an object pool: all the objects
in the pool are destroyed.

The object pool API is:

bt_object_pool_create_object():
    Creates an object from an object pool. If the pool is empty, this
    function calls the "new" user function to allocate a new object
    before returning it. Otherwise this function returns a recycled
    object, removing it from the pool. The returned object is owned by
    the caller.

bt_object_pool_recycle_object():
    Recycles an object, that is, puts it back into the pool. The pool
    becomes the sole owner of the object to recycle.

There is not upper limit for the number of objects in the pool as of
this patch: the pool can grow infinitely, it never shrinks.

Within the library, the function naming convention for a recyclable, or
"poolable" object `bt_X` is as such:

bt_X_new():
    Allocates an object from memory. The object created by this function
    might be incomplete: the object is not always ready to use after
    calling this. This is the function which is passed as the "new"
    function when calling bt_object_pool_initialize().

bt_X_create():
    Creates an object from a pool and makes it useable, setting again
    the references that were reset during bt_X_recycle(), for example.
    Which pool to use is explicitly known by the function. It is part of
    an object received as a parameter. This could call bt_X_new()
    indirectly if the pool is empty.

bt_X_recycle():
    Resets the received object and recycles it within the appropriate
    pool. This function puts any reference which would keep the shared
    object alive even if the owner is now partially dead, part of a
    pool.

bt_X_destroy():
    Finalizes and deallocates the received object.

The following objects are recyclable as of this patch:

* `bt_event`; pool belongs to its event class, recycling happens when
  the event notification is destroyed.

* `bt_clock_value`; pool belongs to its clock class.

* `bt_packet`; pool belongs to its stream, recycling happens when its
  reference count reaches 0.

* `bt_packet_header_field`; pool belongs to a trace (more about this
  new object below).

* `bt_packet_context_field`; pool belongs to a stream class (more about
  this new object below).

* `bt_event_header_field`; pool belongs to a stream class (more about
  this new object below).

Unique objects
==============
Having a pool of event objects means that an event object must make sure
that everything under it which could be modified per instance is not
shared. In this case, the four `bt_field` objects (header, stream event
context, context, and payload) must not be shared.

Therefore this patch introduces unique objects (non-shared). By default,
bt_object_init() initializes a shared object. A function which creates a
unique object can mark it as unique thanks to bt_object_set_is_shared().
This is only used in developer mode to verify that the developer does
not call bt_get() or bt_put() on a unique object.

As a library user, you cannot create a unique object. It is created (and
destroyed) internally: you can only borrow the already-created object
from another object.

As of this patch, bt_event_create() and bt_field_create() are internal
functions. When you create an event notification with
bt_notification_event_create(), you pass the event class and packet to
use for the internal creation of the event object. Then you can borrow
the created (unique, non-shared) event with
bt_notification_event_borrow_event(), and its fields with
bt_event_borrow_header(), bt_event_borrow_stream_event_context(),
bt_event_borrow_context(), and bt_event_borrow_payload().

Then, recursively, you can borrow fields from compound fields
(structure, array, sequence, variant) and set their values.

On creation, the structure, variant, and array fields recursively create
all their subfields. This can't be done with the sequence field because
we need to know its length: subfields are created lazily when the
sequence's length increases; they are never destroyed until the sequence
field itself is destroyed (the sequence field's length is not
necessarily its field pointer array's length). A variant field has a
current field member which points to one of its subfields depending on
the current selection.

A packet object is still shared, as it needs to be shared between
multiple event objects. Its header and context fields, however, are
unique. Like the event object, the packet object creates its own unique
fields and you can borrow them with bt_packet_borrow_header() and
bt_packet_borrow_context().

Clock values are also unique (bt_clock_value_create() is now internal).
They are created when an event or an inactivity notification is created.
Once you borrow a clock value object using a clock class, you can set
its value with the new bt_clock_value_set_value() function. Clock value
objects now have the concepts of being set and frozen (like field
objects) because they are not immutable anymore.

CTF IR field API changes
========================
* bt_field_integer_*() functions now apply to both integer and
  enumeration fields, as an enumeration field is considered to be
  an integer field.

  For this to be efficient (no branches), an enumeration field is
  nothing more than an integer field and the functions just cast the
  given `struct bt_field *` object to a common integer field:

      struct bt_field_enumeration {
          struct bt_field_common_integer common;
      };

* bt_field_string_clear(): new function to clear an existing string
  field object.

  Because field objects are reused and they are not reset when an event
  is recycled (for performance), you must call bt_field_string_clear()
  before you initially call bt_field_string_append() or
  bt_field_string_append_len(). You don't need to call
  bt_field_string_clear() before initially calling
  bt_field_string_set_value().

* bt_field_sequence_get_length() returns an integer (`int64_t`), not a
  field object. It is useless for the user to have the actual length
  integer field.

* bt_field_sequence_set_length() accepts an integer (`uint64_t`), not a
  field, for the same reason as the previous point.

* bt_field_variant_get_field() is removed. This function had a dual
  role where it would select the current field using the value of
  a tag field, and then return the current field. It is a vestige of
  the CTF writer API.

  Now, you set the tag value (plain integer) with
  bt_field_variant_set_tag_signed() or
  bt_field_variant_set_tag_unsigned(), and then you can borrow the
  variant field's current (selected) field with
  bt_field_variant_borrow_current_field().

  You can still get the variant field's current tag value with
  bt_field_variant_get_tag_signed() and
  bt_field_variant_get_tag_unsigned(). Combined with
  bt_field_type_enumeration_signed_find_mappings_by_value() and
  bt_field_type_enumeration_unsigned_find_mappings_by_value(), you can
  get the variant field's tag's mappings, so really there's no value
  keeping the actual tag enumeration field.

The CTF writer field API is unchanged and still backward compatible.

Free packet header, packet context, and event header fields
===========================================================
It is possible to create a "free" packet header field (wrapper). This is
useful to fill a packet header field without creating the packet that
would create it, because in order to create this packet, you need a
stream, which is created from a stream class, and the stream class's ID
is found in the packet header field data.

The API is:

bt_trace_create_packet_header_field():
    Creates a free packet header field
    (`struct bt_packet_header_field *`).

bt_packet_header_field_borrow_field():
    Borrows the underlying field object to fill it.

bt_packet_move_header():
    Moves the free packet header field object to a given packet,
    replacing its current packet header field. After calling this, and
    on success, the object is considered to belong to the packet object:
    you can discard it.

    What happens here is that bt_packet_move_header() first recycles its
    current packet header field wrapper object to the trace's packet
    header field pool, and then replaces it with the provided object.

bt_packet_header_field_release():
    Releases the given packet header field. This function exists for
    error handling, to discard a packet header field without leaking
    when you called bt_trace_create_packet_header_field(), but you
    cannot call bt_packet_move_header().

Analogous functions exist for a packet context field:

* bt_stream_class_create_packet_context_field()
* bt_packet_context_field_borrow_field()
* bt_packet_move_context()
* bt_packet_context_field_release()

Having free packet header and packet context fields is necessary for a
`src.ctf.fs` component to work because it needs to know some field
values of both packet header and context fields before even creating a
stream object (to have a single stream for multiple data stream files,
for example), thus also before creating a packet.

Analogous functions exist for an event header field:

* bt_stream_class_create_event_header_field()
* bt_event_header_field_borrow_field()
* bt_event_move_header()
* bt_event_header_field_release()

Those three new (unique, non-shared) objects use the internal
`bt_field_wrapper` API.

Other changes
=============
* bt_clock_class_cycles_to_ns(): new public function to transform cycles
  to nanoseconds from Epoch using a specific clock class. The
  `src.ctf.fs` component used to create a clock value just to have this
  through bt_clock_value_get_value_ns_from_epoch(), and then destroy it.
  With this patch, you cannot create a free clock value anymore,
  therefore this new function satisfies the existing use case.

* BT_LIB_LOG*() now accepts the `%!o` specifier to log the details of
  an object pool.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoctf plugin: notif iter: use "borrow" functions for metadata where possible
Philippe Proulx [Tue, 17 Apr 2018 05:38:07 +0000 (01:38 -0400)] 
ctf plugin: notif iter: use "borrow" functions for metadata where possible

Use "borrow" API functions when possible to avoid useless reference
count changes for metadata objects.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoctf plugin: BTR: use "borrow" functions where possible
Philippe Proulx [Tue, 17 Apr 2018 02:58:11 +0000 (22:58 -0400)] 
ctf plugin: BTR: use "borrow" functions where possible

Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agosrc.ctf.fs: use "borrow" functions where possible
Philippe Proulx [Tue, 17 Apr 2018 00:25:31 +0000 (20:25 -0400)] 
src.ctf.fs: use "borrow" functions where possible

Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agosink.utils.counter: use "borrow" functions where possible
Philippe Proulx [Mon, 16 Apr 2018 23:18:06 +0000 (19:18 -0400)] 
sink.utils.counter: use "borrow" functions where possible

Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agosink.text.pretty: use "borrow" functions where possible
Philippe Proulx [Mon, 16 Apr 2018 23:15:33 +0000 (19:15 -0400)] 
sink.text.pretty: use "borrow" functions where possible

Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agocli: add short option `-l` for `--log-level`
Philippe Proulx [Mon, 16 Apr 2018 22:56:26 +0000 (18:56 -0400)] 
cli: add short option `-l` for `--log-level`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoFix: bt_stream_common_finalize(): check `stream->destroy_listeners`
Philippe Proulx [Mon, 16 Apr 2018 22:47:39 +0000 (18:47 -0400)] 
Fix: bt_stream_common_finalize(): check `stream->destroy_listeners`

Issue
=====
In bt_stream_common_finalize(), `stream->destroy_listeners` is not
checked before calling iterating the array to call the destroy
listeners. This can happen if the stream is partially initialized and
then destroyed when there's an error in bt_stream_common_initialize().

Solution
========
Check `stream->destroy_listeners` before iterating the destroy listener
array.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoflt.utils.muxer: use "borrow" functions where possible
Philippe Proulx [Mon, 16 Apr 2018 22:45:40 +0000 (18:45 -0400)] 
flt.utils.muxer: use "borrow" functions where possible

Use "borrow" API functions when possible to avoid useless reference
count changes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: add "borrow" functions where "get" functions exist
Philippe Proulx [Fri, 13 Apr 2018 06:54:35 +0000 (02:54 -0400)] 
lib: add "borrow" functions where "get" functions exist

The new bt_*_borrow_*() functions return a "borrowed reference" instead
of a new reference like the bt_*_get_*() functions return.

Use the "borrow" functions as much as possible internally.

This can improve performance, especially for objects which are obtained
often, and for a short time, in the fast path (fields, events, packets,
notifications, some metadata objects), as it avoids one bt_get() and one
bt_put() call for each function call.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoinclude/babeltrace/graph: fix some include guards
Philippe Proulx [Fri, 13 Apr 2018 20:27:33 +0000 (16:27 -0400)] 
include/babeltrace/graph: fix some include guards

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agobt2: by-pass distutils changed file check
Francis Deslauriers [Wed, 11 Apr 2018 21:20:40 +0000 (17:20 -0400)] 
bt2: by-pass distutils changed file check

Changes made to a SWIG interface file (.i) that is included in
native_bt.i would not trigger rebuilding of the extension on `make`
as the main source file (native_bt.i) has not changed.

The Makefile is already tracking when files changed and need to be
recompiled so we can simply bypass the setup.py checks by using the
--force flag.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
4 years agoSilence unused variable warnings caused by BT_ASSERT() in non-debug mode
Francis Deslauriers [Tue, 3 Apr 2018 20:24:49 +0000 (16:24 -0400)] 
Silence unused variable warnings caused by BT_ASSERT() in non-debug mode

When building with the BABELTRACE_DEBUG_MODE configure option _not_ set,
multiple set-but-not-used warnings are emitted by the compiler. Most of
the time this happens because BT_ASSERT() is used to verify the return
value of functions and when not in DEBUG_MODE those return value are not
used.

The solution is to explicitly tell the compiler that we don't care about
this value so that it does not emit warning when building in non-debug
mode. This approach also makes sure not to evaluate the expression using
the `sizeof` operator, thus preventing any side effects.

See this post for further details [1].

[1]: https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
4 years agobt2: typo staitc -> static
Francis Deslauriers [Mon, 2 Apr 2018 14:05:07 +0000 (10:05 -0400)] 
bt2: typo staitc -> static

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
4 years agoCleanup: remove GCC precompiled header leftover
Francis Deslauriers [Thu, 12 Apr 2018 15:19:29 +0000 (11:19 -0400)] 
Cleanup: remove GCC precompiled header leftover

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
4 years agoSplit CTF IR and CTF writer APIs and implementations
Philippe Proulx [Sat, 7 Apr 2018 17:20:16 +0000 (13:20 -0400)] 
Split CTF IR and CTF writer APIs and implementations

This patch splits the CTF IR and CTF writer APIs, previously implemented
at a single place with aliases to make CTF writer functions and types be
synonymous to CTF IR ones, with as much common code as possible for both
APIs.

The goal of this change is to be able to modify one API/implementation
without disturbing the other, optimization being one major use case.

Common API
==========
Most of the CTF IR and CTF writer functions perform the exact same
tasks. Some functions, however, have minor differences. For example,
bt_trace_add_stream_class() tries to automatically map specific integer
field types to the stream class's CTF writer clock's class if the trace
object was created by a CTF writer object.

To keep as much common code as possible, `struct bt_*_common` types and
bt_*_common() functions are introduced. A common structure contains the
common data needed for both CTF IR and CTF writer, while actual
CTF IR/writer structures "inherit" this one. For example:

    struct bt_stream_common {
        struct bt_object base;
        int64_t id;
        struct bt_stream_class_common *stream_class;
        GString *name;
        GArray *destroy_listeners;
    };

    struct bt_stream {
        struct bt_stream_common common;
    };

    struct bt_ctf_stream {
        struct bt_stream_common common;
        struct bt_ctf_field *packet_header;
        struct bt_ctf_field *packet_context;
        GPtrArray *events;
        struct bt_ctf_stream_pos pos;
        unsigned int flushed_packet_count;
        uint64_t discarded_events;
        uint64_t size;
        uint64_t last_ts_end;
    };

All bt_stream_common_*() functions require a pointer to
`struct bt_stream_common`. You can use the BT_TO_COMMON() and
BT_FROM_COMMON() macros of `include/babeltrace/ctf-ir/utils-internal.h`
to statically cast the pointers in each direction. BT_TO_COMMON() needs
the concrete (non-common) structure to have a common structure member
named `common`.

A concrete implementation is responsible for the allocation and
deallocation of its objects, but the common API provides internal
functions to initialize and finalize the common parts. Examples are
bt_event_common_initialize(), bt_event_class_common_finalize(), and
bt_field_type_common_floating_point_initialize(). Those initialization
functions take a `release_func` parameter which is the concrete object
destruction function. The latter is responsible for finalizing the
specific part, calling bt_*_common_finalize() to finalize the common
part, and deallocating the object.

Most of the concrete functions look like this:

    struct bt_field_type *bt_event_class_get_payload_field_type(
            struct bt_event_class *event_class)
    {
        return BT_FROM_COMMON(bt_event_class_common_get_payload_field_type(
            BT_TO_COMMON(event_class)));
    }

Some common functions are more complicated and can be considered
template methods: they take various options and callback functions to be
called at specific places within the procedure.
bt_event_common_initialize() and bt_trace_common_add_stream_class() are
obvious examples.

The cases of field types and fields are special because those structures
already use inheritance: an integer field type structure inherits the
field type structure. In order for all the APIs to be able to statically
cast to the appropriate types, here's how a concrete field type is
arranged:

    +------------------------------------+
    | Common field type                  | <- bt_field_type_common_*()
    +------------------------------------+
    | Concrete common field type (union) | <- bt_(ctf_)field_type_*()
    +------------------------------------+
    | Common specific field type         | <- bt_field_type_common_integer_*()
    +------------------------------------+
    | Specific field type                | <- bt_(ctf_)field_type_integer_*()
    +------------------------------------+

The four parts are at a fixed offset.

Field objects follow the same structure.

As of this patch, `struct bt_field_type`, `struct bt_ctf_field_type`,
`struct bt_field`, and `struct bt_ctf_field` are only forward-declared
and always `(void *)` casted to and from the appropriate common type for
public APIs because they don't add specific data. For example:

    int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *ft,
            unsigned int alignment)
    {
        return bt_field_type_common_set_alignment((void *) ft, alignment);
    }

Also of interest is `struct bt_ctf_clock_class` which includes
`struct bt_clock_class`: there's no `struct bt_clock_class_common`
because as of this patch we don't expect a CTF IR clock class property
to be absent from a CTF writer clock class.

As of this patch, the common API and implementation are in the same
source and header files as CTF IR. Fast path common functions (most
getters and almost everything related to fields and events) are
implemented in internal header files as `static inline` functions.

Logging
=======
BT_LIB_LOG(), and consequently BT_ASSERT_PRE() and its variants, is
modified with an added prefix character to distinguish a CTF IR object
from a CTF writer object and from a common object. The prefix character
is inserted just before the format specifier: `_` means a common object
(underscore as in low as in base), and `w` means a CTF writer object. No
prefix means a CTF IR or other object (graph objects, value objects,
etc.).

Using `%!+_t` with a CTF IR trace object, for example, is correct
because it inherits the common part, but using `%!+t` with a common
trace object could eventually lead to bad data or to a segmentation
fault.

See the updated description in
`include/babeltrace/lib-logging-internal.h` for more details.

Testing
=======
Some tests in `tests/lib` are modified because they used a mix of CTF IR
and CTF writer APIs. Also there is a new precondition that a CTF IR
event class must be part of a trace before you can create an event from
it (the CTF writer API does not have this restriction for backward
compatibility reasons): this guarantee could make things easier in the
future and it is acceptable for a CTF IR user.

Some CTF writer tests are removed because they were in fact CTF IR
tests. In the future we should create specific CTF IR tests and reuse
the removed tests.

Limitations
===========
This patch does not address, and reserves for future work:

* Python bindings
* Python bindings tests
* `src.ctf.lttng-live`, `sink.ctf.fs`, `flt.utils.trimmer`,
  `flt.lttng-utils.debug-info`, and `src.text.dmesg` component classes

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()
Philippe Proulx [Wed, 7 Mar 2018 00:25:48 +0000 (19:25 -0500)] 
lib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()

Use BT_ASSERT_PRE() to assert that trace, stream, stream class, event
class, and field type preconditions are satisfied instead of
unconditional run-time checks for typical fast path API functions
(getters).

Update `tests/lib/test_ctf_writer.c` accordingly to remove unit tests
which expect a specific return value when preconditions are not
satisfied.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoNotification iterator: transform precondition checks to BT_ASSERT_PRE()
Philippe Proulx [Fri, 2 Mar 2018 00:08:30 +0000 (19:08 -0500)] 
Notification iterator: transform precondition checks to BT_ASSERT_PRE()

Use BT_ASSERT_PRE() to assert that notification iterator preconditions
are satisfied instead of unconditional run-time checks.

A notification iterator now expects, for a given stream, that a
BT_NOTIFICATION_TYPE_STREAM_BEGIN notification is received as the first
notification, and a BT_NOTIFICATION_TYPE_PACKET_END notification as the
last one. It also expects that, for a given sequence of
BT_NOTIFICATION_TYPE_EVENT notifications which belong to the same
packet, a BT_NOTIFICATION_TYPE_PACKET_BEGIN notification is received
before and a BT_NOTIFICATION_TYPE_PACKET_END notification after.

A notification iterator does not automatically generate
BT_NOTIFICATION_TYPE_STREAM_BEGIN, BT_NOTIFICATION_TYPE_STREAM_END,
BT_NOTIFICATION_TYPE_PACKET_BEGIN, and BT_NOTIFICATION_TYPE_PACKET_END
notifications anymore. In developer mode, the iterator validates that
those notifications were emitted in the correct order and that no
notification is missing for the stream. This is made possible by a
notification sequence number. The first time a notification is received
by an iterator, the iterator sets its sequence number to the expected
one (previous sequence number for this stream plus one). Other iterators
validate that, for a given stream, the received notification's sequence
number is expected.

Because BT_NOTIFICATION_TYPE_STREAM_BEGIN,
BT_NOTIFICATION_TYPE_STREAM_END, BT_NOTIFICATION_TYPE_PACKET_BEGIN, and
BT_NOTIFICATION_TYPE_PACKET_END notifications are expected to be
manually emitted now, the concept of notification subscription is
removed. Each notification iterator user receives all the emitted
notifications, and either forwards the whole notification sequence (for
a given stream) as is or use them to create its own stream and
notifications.

Thanks to the notification sequence number, the stream's current
component port hash table is removed. A component can send notifications
from the same stream to two different ports now, but both streams of
notifications must be complete.

A notification iterator also checks that, when requested to be ended,
its stream is finished (BT_NOTIFICATION_TYPE_STREAM_END received). This
confirms that the iterator's user (consumer) received all the
notifications for a given stream and that nothing is discarded.

`plugins/ctf/common/notif-iter/notif-iter.c` is modified so that it
emits the required BT_NOTIFICATION_TYPE_STREAM_BEGIN notification as its
first one and BT_NOTIFICATION_TYPE_STREAM_END as its last one (when the
medium returns "end of stream"). In order to support multiple stream
files which contain packets of the same logical stream (LTTng's trace
file rotation), `plugins/ctf/fs-src/fs.c` is changed to ignore
"intermediate" BT_NOTIFICATION_TYPE_STREAM_BEGIN and
BT_NOTIFICATION_TYPE_STREAM_END notifications when it resets its CTF
notification iterator (`notif-iter`) between stream files.

Python bindings, some plugins, and some tests are not updated and could
not work as of this patch because further changes in the same patch set
will significantly change them anyway. The changes also do not deal with
BT_NOTIFICATION_TYPE_DISCARDED_EVENTS and
BT_NOTIFICATION_TYPE_DISCARDED_PACKETS notification types as I plan to
remove those types and make this information part of the
BT_NOTIFICATION_TYPE_PACKET_BEGIN type.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoReplace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE()
Philippe Proulx [Wed, 28 Feb 2018 23:37:29 +0000 (18:37 -0500)] 
Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE()

In the whole project: replace assert() with BT_ASSERT(), and include
<babeltrace/assert-internal.h> instead of <assert.h>. This means that,
from now on, logic/postcondition assertions are disabled by default: you
need to enable them explicitly with `BABELTRACE_DEBUG_MODE=1` when
configuring the project.

In the library: replace the precondition checks which actively occur
while a graph is running with BT_ASSERT_PRE() or other helpers that are
only enabled in developer mode. Those are mostly checks for `bt_event`,
`bt_packet`, `bt_field`, `bt_notification`, and `bt_value` objects.

Frozen and validation flags for those objects are now only handled in
developer mode. The concept of set/unset fields is also only handled in
developer mode. This is why some internal functions have their name
prefixed with `_` and a macro is used instead to do nothing when in
non-developer mode (e.g., bt_field_freeze() calls _bt_field_freeze() in
developer mode and does nothing in non-developer mode).

The transformation of unconditional run-time precondition checks to
using BT_ASSERT_PRE() is not done for the notification iterator object.
This is a separate concern with different challenges which will be
implemented in a subsequent patch.

Tests which check that API functions fail when preconditions are not
satisfied in `tests/lib/test_bt_values.c` and
`tests/lib/test_ctf_writer.c` are removed. From my point of view,
checking for those preconditions is not part of the API now: it is only
a service provided for developers in developer mode. In other words,
because a library user cannot expect a specific reaction when not
satisfying the required preconditions, you cannot unit-test them either.
What is important is to validate that the library works as expected when
used as expected.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoAdd internal BT_ASSERT() and BT_ASSERT_PRE() helpers
Philippe Proulx [Wed, 28 Feb 2018 23:37:08 +0000 (18:37 -0500)] 
Add internal BT_ASSERT() and BT_ASSERT_PRE() helpers

This patch adds new internal assertion macros to control what is
asserted. The ultimate purpose of this is to disable logic/postcondition
assertions and run-time precondition checks in a production build to
optimize the project.

`configure.ac` is modified so that it handles two new environment
variables:

`BABELTRACE_DEBUG_MODE`:
    When set to `1`: enables the Babeltrace debugging mode. This enables
    internal assertions which validate logic and postconditions with the
    BT_ASSERT() macro. This defines `BT_DEBUG_MODE` in sources.

    As of this patch, when in debugging mode, BT_ASSERT() is the
    equivalent of assert(). However, assert() is enabled by not passing
    `-DNDEBUG` to the compiler, while BT_ASSERT() is enabled by passing
    `-DBT_DEBUG_MODE`.

    Because the build is not in debugging mode by default, even if
    `-DNDEBUG` is not passed to the compiler (thus not enabling
    assert()), neither is `-DBT_DEBUG_MODE`, so all logic/postcondition
    assertions are disabled in production.

    You can use BT_ASSERT() anywhere in the whole project by including
    <babeltrace/assert-internal.h>.

    If a function is to be used only within a BT_ASSERT() context,
    then the compiler would complain that it is unused in non-debugging
    mode. You can tag the function with `BT_ASSERT_FUNC` for this.

`BABELTRACE_DEV_MODE`:
    When set to `1`: enables the Babeltrace developer mode. This enables
    precondition assertions in the library. This defines `BT_DEV_MODE`
    in sources.

    A lot of run-time checks can be avoided in production once you know
    that the code is correct, i.e. that it won't perform anything
    illegal, whatever the end user does. Some examples are NULL checks,
    frozen checks, and bound checks.

    The developer mode allows run-time precondition checks to be
    performed with BT_ASSERT_PRE(). This macro expects the condition to
    check as well as a message. In developer mode, when the condition is
    false, the message is printed with BT_LIB_LOGF(), indicating that a
    library precondition was not satisfied at this point, and then
    abort() is called.

    The developer mode is a trade-off between strictness and
    performance: you can get a very strict library with a developer mode
    build, and a more efficient library with a non-developer mode build.

    If a function is to be used only within a BT_ASSERT_PRE() context,
    then the compiler would complain that it is unused in non-developer
    mode. You can tag the function with `BT_ASSERT_PRE_FUNC` for this.
    In such a function, use BT_ASSERT_PRE_MSG() to log any additional
    information without aborting (since you know the process will abort
    thanks to BT_ASSERT_PRE()).

    BT_ASSERT_PRE_NON_NULL() is a helper which does a non-NULL
    precondition check.

    BT_ASSERT_PRE_HOT() is a helper which does a non-frozen precondition
    check.

    `lib/logging.c` is modified so that, in developer mode, the
    library's default log level is FATAL and you cannot set it to NONE.
    This is important because BT_ASSERT_PRE() and BT_ASSERT_PRE_MSG()
    use BT_LIB_LOGF() to print messages.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: add BT_LIB_LOG*() macros to log/serialize library objects
Philippe Proulx [Fri, 23 Feb 2018 03:14:11 +0000 (22:14 -0500)] 
lib: add BT_LIB_LOG*() macros to log/serialize library objects

Add specialized, internal logging macros to log Babeltrace library
objects. Those macros expand to calling bt_lib_log(), which calls
bt_common_custom_vsnprintf() to support custom conversion specifiers.

Almost all Babeltrace objects are supported. The CTF writer object is
supported with the `%!w` specifier, but its formatting remains to be
done. There is no conversion specifier to format a clock class priority
map.

See `include/babeltrace/lib-logging-internal.h` for more details,
limitations, and for the list of custom conversion specifiers.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoCommon: add internal bt_common_custom_vsnprintf()
Philippe Proulx [Fri, 23 Feb 2018 03:01:15 +0000 (22:01 -0500)] 
Common: add internal bt_common_custom_vsnprintf()

This new utility function (and its corresponding
bt_common_custom_snprintf()) is like vsnprintf(), but it also allows to
use custom conversion specifiers with the help of a user callback which
consumes one or more variadic arguments and writes to the current output
buffer position according to the custom conversion specifier.

For example, it allows the following:

    bt_common_custom_snprintf(buf, buf_size, '@', handle_specifier,
                              NULL, "hello %d world %@s (%02x-%@+d)",
                              -23, my_object, 17.5, "meow", my_fd);

Here, the `%d` and `%02x` conversion specifiers are used to consume the
`-23` and `17.5` arguments as you would expect, but the custom `%@s` and
`%@+d` specifiers consume the `my_object`, `"meow"`, and `my_fd`
parameters thanks to the user-provided handle_specifier() callback.

See the block comment above the bt_common_custom_vsnprintf() declaration
for more details and for limitations regarding the format string.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoLogging: use a TLS buffer and increase its size
Philippe Proulx [Fri, 23 Feb 2018 02:57:30 +0000 (21:57 -0500)] 
Logging: use a TLS buffer and increase its size

The logging system's line buffer is on the stack, and its current size
is 512. This means any log line which is larger than 512 bytes (this can
happen with some warnings/errors with a lot of information) gets
truncated.

In order to make this buffer size arbitrarily large, use a TLS global
buffer instead.

Increase the logging system's line buffer to 16 kiB (per thread).

Drawback: the logging system had a static assertion which ensured that
the line buffer size was not greater than PIPE_BUF so that individual
write operations were atomic. With a line buffer size larger than
PIPE_BUF, different threads could write to the output stream at the same
time which could result in interlaced data. We need to add some locking
to support multithreaded logging.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agobt2: InactivityNotification, _Event: use mapping protocol for clock values
Philippe Proulx [Mon, 19 Feb 2018 23:25:05 +0000 (18:25 -0500)] 
bt2: InactivityNotification, _Event: use mapping protocol for clock values

The bt2._Event and bt2.InactivityNotification classes both have the
clock_value() and add_clock_value() methods to get and add clock values
associated to clock classes. This can be replaced with a mapping
protocol accessible with the `clock_value` property.

The mapping's add() method can be used to add a clock value to the
mapping (instead of using __setitem__() because the clock value has a
reference to its clock class (the key) anyway).

Tests are updated accordingly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agobt2: EnumerationFieldType: rename append_mapping() -> add_mapping()
Philippe Proulx [Mon, 19 Feb 2018 22:40:46 +0000 (17:40 -0500)] 
bt2: EnumerationFieldType: rename append_mapping() -> add_mapping()

We're not _appending_ anything in bt2.EnumerationFieldType here, as
opposed to bt2.StructureFieldType (which contains ordered fields), so
the method should be named add_mapping(), like a Python set has the
add() method, whereas a Python list has the append() method.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoFix: call bt_stream_class_map_clock_class() in bt_event_create()
Philippe Proulx [Mon, 19 Feb 2018 22:32:52 +0000 (17:32 -0500)] 
Fix: call bt_stream_class_map_clock_class() in bt_event_create()

Issue
=====
It is possible, for backward compatibility, to create an event before it
is appended to a CTF writer stream. This means that, when
bt_ctf_writer_create_stream() is called, bt_event_create() is already
called. Because bt_ctf_writer_create_stream() calls
bt_trace_add_stream_class(), which calls
bt_stream_class_map_clock_class() to map selected fields to the stream
class's clock's class, this is skipped in this use case and selected
fields are never mapped.

The problematic sequence is:

1. Create a stream class.
2. Set this stream class's CTF writer clock.
3. Create an event with bt_event_create().
4. Create a CTF writer stream with bt_ctf_writer_create_stream().
5. Append the event (3.) to the CTF writer stream (4.) with
   bt_stream_append_event().

In 5., the event header's `timestamp` field is not automatically
populated from the current value of the stream class's clock because its
field type was not automatically mapped to a clock class.

Solution
========
After validating the field types in bt_event_create(), call
bt_stream_class_map_clock_class() on the validated packet context and
event header field types. bt_stream_class_map_clock_class() only
performs automatic mapping when the stream class has a registered CTF
writer clock, which eventually guarantees that this is a CTF writer
stream class because it is forbidden to call bt_trace_add_stream_class()
with such a stream class when the trace was not created by a CTF writer.

In other words, this additional bt_stream_class_map_clock_class() in
bt_event_create() does NOT affect non-CTF writer objects.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoAdd tests: CTF writer: `timestamp_begin`/`timestamp_end` autopopulation
Philippe Proulx [Mon, 19 Feb 2018 21:45:55 +0000 (16:45 -0500)] 
Add tests: CTF writer: `timestamp_begin`/`timestamp_end` autopopulation

Those new tests validate that the automatic population of the
`timestamp_begin` and `timestamp_end` fields in CTF writer work as
expected.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoFix: bt_stream_class_map_clock_class(): copy field type when mapping
Philippe Proulx [Wed, 14 Feb 2018 19:54:39 +0000 (14:54 -0500)] 
Fix: bt_stream_class_map_clock_class(): copy field type when mapping

Issue
=====
When a CTF writer stream class's packet context type contains the
special field types `timestamp_begin`, `timestamp_end`, and `timestamp`,
they are automatically mapped to the stream class's clock's class when
the stream class is about to be frozen in bt_trace_add_stream_class().
However, because the field type is mapped as is without a prior copy, it
is possible that this field type is shared with other locations in the
metadata tree which should not be mapped to a clock class.

Solution
========
Before automatically mapping any field type to a clock class, or more
generally, before modifying any field type, make a copy and replace the
original within its parent.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: add internal bt_field_type_structure_replace_field()
Philippe Proulx [Wed, 14 Feb 2018 19:53:36 +0000 (14:53 -0500)] 
lib: add internal bt_field_type_structure_replace_field()

This new internal function replaces the field type of a field identified
by name within a structure field type.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: logging: change warnings from BT_LOGE to BT_LOGW
Philippe Proulx [Tue, 13 Feb 2018 23:39:28 +0000 (18:39 -0500)] 
lib: logging: change warnings from BT_LOGE to BT_LOGW

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoFix: CTF writer: validate and set `timestamp_begin`/`timestamp_end`
Philippe Proulx [Tue, 13 Feb 2018 22:19:00 +0000 (17:19 -0500)] 
Fix: CTF writer: validate and set `timestamp_begin`/`timestamp_end`

Issue
=====
A CTF writer stream's packet context's `timestamp_begin` and
`timestamp_end` fields are not correctly automatically set and not
validated. There are many issues:

1. There's no validation that the `timestamp_begin` value of flushed
   packet N is greater than or equal to the `timestamp_end` value of
   packet (N - 1).

2. The automatic values are the event header's `timestamp` field of the
   first appended event for `timestamp_begin` and of the last appended
   event for `timestamp_end`. A field updating the stream's clock could
   exist in the payload of the last appended event, for example, making
   the automatic `timestamp_end` value too small.

   Also, the current code does not consider mapped integer fields with a
   size which is less than the size of the `timestamp_begin` field. In
   this case, the CTF clock update mechanism must be used.

3. Because of 2., a CTF writer stream cannot flush an empty packet (no
   appended events) without providing `timestamp_begin` and
   `timestamp_end` because there's no event to extract the automatic
   values.

4. There's no validation that `timestamp_end` is greater than or equal
   to `timestamp_begin`.

Solution
========
When flushing a CTF writer stream:

1. Set the initial packet's timestamp to one of:

   * The value of `timestamp_begin`, if the field is set.
   * The previous packet's last timestamp, if available. The stream
     object contains this value. It's not available before the first
     flush.
   * Zero.

2. Set the current clock value to the value computed in 1. It is correct
   to have a single current clock value because the library guarantees
   that a given stream class contains at most a single clock class.

3. Visit all the fields of the packet context (except the special fields
   which could not be set at this point), and then all the fields of all
   the appended events, in order, to update the current clock value.
   Apply the CTF clock update mechanism to handle updating fields which
   have a wrapping value.

4. If `timestamp_end` is set, validate that its value is greater than
   or equal to the computed current clock value. This is a validation
   step.

5. If `timestamp_end` is not set, set it to the current clock value.

6. If `timestamp_begin` is not set, set it to the initial timestamp.

7. Set the stream's last final timestamp to the value of
   `timestamp_end`.

Those steps perform validation and automatic field value setting at the
same time.

Known drawbacks
===============
This solution makes the stream flushing process slower. However, there's
room for optimization. For example, there's no need to visit all the
fields: we just need to visit the fields which are mapped to a clock
class. Moreover, if all the types of the mapped fields have a size which
is at least the size of the `timestamp_begin` field, then there's no
need to visit them at all: we can use the last event's last mapped
field's value directly because the mapped fields always overwriting the
current clock value anyway.

Tests for the `succeed/lttng-modules-2.0-pre5` trace are removed because
this solution reveals an invalid trace: the `timestamp_begin` value of
the second packet in `channel0_5` is less than the `timestamp_end` value
of the first packet. This was produced by the LTTng-modules 2.0-pre5
tracer, so it can be considered an invalid trace as per CTF.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: add internal bt_field_sequence_get_int_length()
Philippe Proulx [Tue, 13 Feb 2018 22:17:31 +0000 (17:17 -0500)] 
lib: add internal bt_field_sequence_get_int_length()

This new internal helper returns a sequence field's length as an
`int64_t` value instead of returning the integer field. Returns a
negative value on error or if the sequence fields's length field is not
set.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoAdd stream class's single clock class tests
Philippe Proulx [Wed, 7 Feb 2018 20:05:27 +0000 (15:05 -0500)] 
Add stream class's single clock class tests

Those new tests verify that:

* You cannot have a clock class in one of the stream class's field types
  and a different one in one of its event classes.
* You cannot have two different clock classes in two different event
  classes of the same event class.
* You cannot set a stream class's CTF writer clock and have a clock
  class within this stream class which is not the stream class's clock's
  class.

The tests check those conditions when calling specific API functions and
in the expected order:

* bt_trace_add_stream_class()
* bt_event_create()
* bt_stream_class_add_event_class()

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: allow a single mapped clock class within a stream class
Philippe Proulx [Wed, 31 Jan 2018 21:17:19 +0000 (16:17 -0500)] 
lib: allow a single mapped clock class within a stream class

This patch makes it illegal to have more than one mapped clock class
within the field types of a stream class and all its event classes. Many
field types can map to the same, unique clock class.

Multiple clock classes within a given stream class is not a well-defined
nor well-supported feature, if it is one in the first place, of CTF.
Considering the known use cases we have in the field, it is not used
either. A clock's value should be reset to the value of the
`timestamp_begin` field of the packet's context for each packet, but
this field can only be mapped to a single clock class anyway. What
should its initial value be in this case? The specification is silent on
this matter.

We keep an "expected" clock class in the stream class object. This is
only valid when the stream class is frozen; otherwise, the stream
class's field types can change, even when event classes are already part
of it. If the stream class is already frozen, then if the expected clock
class is still NULL (no mapped clock class at this point), an added
event class can set it (for future added event classes).

If the stream class is eventually part of a trace which was created by a
CTF writer, we make sure that the expected clock class is the stream
class's clock's class, if any. This is important because, in
bt_trace_add_stream_class(), on success, we try to map some special
fields to the stream's clock's class. Because we know at this point that
the stream's clock's class is also the stream class's expected clock
class, it is safe to perform this mapping once the single clock class
validation is already done.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoFix: libctfcopytrace: replace clock classes in copies
Philippe Proulx [Fri, 2 Feb 2018 21:35:07 +0000 (16:35 -0500)] 
Fix: libctfcopytrace: replace clock classes in copies

Issue
=====
Using the functions of libctfcopytrace, some field types are reused as
is in the copied event class/stream class. For example, when we copy a
stream class, we set the copy's packet context field type to the
original packet context field type, without copying it. However, we copy
the clock classes from the original trace to the copy. The result of
this is that the copied packet context field type can contain a mapped
clock class which is not registered to its stream class's trace. This is
considered invalid.

Solution
========
This patch makes those functions systematically copy the all the field
types and then replace the original mapped clock classes to their copy
with replace_clock_classes().

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agobt_field_type_compare(): deep-compare mapped clock classes
Philippe Proulx [Fri, 2 Feb 2018 21:31:37 +0000 (16:31 -0500)] 
bt_field_type_compare(): deep-compare mapped clock classes

Deep-compare mapped clock classes in bt_field_type_integer_compare()
instead of just comparing the pointers. Given the same contexts, two
integer field types which have equal properties and equal mapped clock
classes (not just equal clock class pointers) are considered equal.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agoAdd test: no clock class in trace's packet header field type
Philippe Proulx [Fri, 22 Dec 2017 00:00:31 +0000 (19:00 -0500)] 
Add test: no clock class in trace's packet header field type

This patch adds a test case which uses the Python bindings to test that
it is not possible to set a trace's packet header field type containing
an integer field type mapped to a clock class.

The new tests/lib/ctf-ir directory is set so that future CTF IR test
cases can be added easily if need be instead of going to
tests/lib/test_ctf_writer.c.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agolib: do not allow any mapped clock class in trace's packet header FT
Philippe Proulx [Wed, 20 Dec 2017 22:33:15 +0000 (17:33 -0500)] 
lib: do not allow any mapped clock class in trace's packet header FT

Do not allow any integer field type to be mapped to a clock class within
the packet header field type of a trace.

This is one of the steps to ensure that a given stream class has only
one (if any) mapped clock class, recursively. More than one clock class
for a given stream class was never well supported anyway in CTF 1.8
because you cannot have multiple `timestamp_begin` and `timestamp_end`
fields.

It's also weird to have a clock value update in the packet header
because we don't have the value of `timestamp_begin` yet. Where would
this value be "located" on the timeline if `timestamp_begin` is the
absolute beginning timestamp of the packet containing said header?
Unless it is always the exact same value as `timestamp_begin` (which is
useless), it does not fit with the clock value update mechanism where,
as fields are decoded (or encoded), a given clock's value must be
updated monotonically: if the clock value found in the packet header is
less than `timestamp_begin`, then its lower bound is not
`timestamp_begin`.

The check is performed whenever the trace is about to be frozen (this
freezes the packet header field type) on success, that is:

* bt_trace_add_stream_class()
* bt_trace_set_is_static()

The check uses the new bt_validate_single_clock_class() internal
function. This one makes sure that a given field type recursively
contains only one clock class. You pass the expected clock class to the
function, or NULL so that the function sets it for you. In the trace
packet header field type case, even if this function returns 0
(success), that is, the field contains _at most_ one clock class, we
check that the returned expected clock class is still NULL to make sure
the field type in fact contains none.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agotests/plugins/test_lttng_utils_debug_info.in: use specific pattern
Philippe Proulx [Mon, 18 Dec 2017 23:31:39 +0000 (18:31 -0500)] 
tests/plugins/test_lttng_utils_debug_info.in: use specific pattern

If this new pattern is not passed to the test runner, then any new `.py`
file would also be discovered by this test.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 years agotests/utils/python/testrunner.py: add optional pattern argument
Philippe Proulx [Mon, 18 Dec 2017 23:29:40 +0000 (18:29 -0500)] 
tests/utils/python/testrunner.py: add optional pattern argument

Add an optional command-line argument (second) to `testrunner.py`: the
test file name pattern. You can use this argument to run only specific
files in a given test directory, instead of the default which is
`test*.py`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 years agoFix: invalid alignment of enumeration fields
Jérémie Galarneau [Tue, 30 Oct 2018 23:19:14 +0000 (00:19 +0100)] 
Fix: invalid alignment of enumeration fields

Issue
---

According to the CTF specification, the alignment of an enumeration is
that of its container integer field type. However, ctf-ir does not
forward the alignment of an enumeration field type's alignment in
bt_field_type_get_alignment().

This causes babeltrace to fail to read traces produced by lttng-ust
following a fix that causes it to generate extended event headers. The
problem is observed on ARM platforms since lttng-ust will produce
a layout that does not result in unaligned memory accesses.

Solution
---

The alignment of the enumeration field type's container is sampled
when the enumeration field type is frozen.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoAdd git version string
Michael Jeanson [Tue, 1 May 2018 18:30:02 +0000 (14:30 -0400)] 
Add git version string

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix live-comm: merge TCP socket write-write sequence in a single write
Jonathan Rajotte [Fri, 24 Nov 2017 20:48:31 +0000 (15:48 -0500)] 
Fix live-comm: merge TCP socket write-write sequence in a single write

The live protocol implementation is often sending content
on TCP sockets in two separate writes. One to send a command header,
and the second one sending the command's payload. This was presumably
done under the assumption that it would not result in two separate
TCP packets being sent on the network (or that it would not matter).

Delayed ACK-induced delays were observed [1] on the second write of the
"write header, write payload" sequence and result in problematic
latency build-ups for live clients connected to moderately/highly
active sessions.

Fundamentally, this problem arises due to the combination of Nagle's
algorithm and the delayed ACK mechanism which make write-write-read
sequences on TCP sockets problematic as near-constant latency is
expected when clients can keep-up with the event production rate.

In such a write-write-read sequence, the second write is held up until
the first write is acknowledged (TCP ACK). The solution implemented
by this patch bundles the writes into a single one [2].

[1] https://github.com/tbricks/wireshark-lttng-plugin
Basic Wireshark dissector for lttng-live by Anto Smyk from Itiviti
[2] https://lists.freebsd.org/pipermail/freebsd-net/2006-January/009527.html

Reported-by: Anton Smyk <anton.smyk@itiviti.com>
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: wrong type specifier used with long argument
Jérémie Galarneau [Fri, 18 May 2018 17:58:31 +0000 (13:58 -0400)] 
Fix: wrong type specifier used with long argument

clang reports "format specifies type 'long long' but the argument has
type 'long' [-Wformat]" which is correct. retry_duration has
changed types from long long to long in the previous commit.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 years agoFix: POPT_ARG_LONGLONG does not exist in popt 1.13
Jérémie Galarneau [Thu, 17 May 2018 19:35:17 +0000 (15:35 -0400)] 
Fix: POPT_ARG_LONGLONG does not exist in popt 1.13

The retry duration parameter is currently declared as a long long,
which popt 1.13 does not support. The support for that type was only
added in popt 1.14.

Using POPT_ARG_LONG instead of the 'long long' variant makes no real
difference in this case (or at least, not enough to justify bumping
the minimal popt version).

This fixes a build failure that was reported on Red Hat 7 where
1.13 is the default version.

Reported-by: Abderrahmane Benbachir <abenbach@ciena.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: Use bash for all test scripts
Michael Jeanson [Mon, 26 Mar 2018 15:47:44 +0000 (11:47 -0400)] 
Fix: Use bash for all test scripts

We already use bash in most test scripts shebang and the sh binary on
Solaris 10 doesn't like some of our "modern" scripts syntax.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoAdd missing clock.h compatiblity header under ctf-ir
Jérémie Galarneau [Tue, 30 Jan 2018 15:51:59 +0000 (10:51 -0500)] 
Add missing clock.h compatiblity header under ctf-ir

Babeltrace 1.5 exposes a clock.h header under ctf-ir which
is equivalent to what is now ctf-writer/clock.h.

This commit adds a compatiblity header which includes
ctf-writer/clock.h in order to maintain the backward
compatibility with the 1.x API.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agobabeltrace-filter.lttng-utils.debug-info(7): fix LTTng prerequisites
Philippe Proulx [Wed, 29 Nov 2017 17:02:29 +0000 (12:02 -0500)] 
babeltrace-filter.lttng-utils.debug-info(7): fix LTTng prerequisites

Add:

* Enable LTTng-UST state dump events.
* Enable LTTng-UST dynamic linker tracing helper events.

Convert some prose to procedures.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agobt2 tests: add unit tests for __str__ implementation of Fields
Jérémie Galarneau [Sat, 2 Dec 2017 13:41:15 +0000 (14:41 +0100)] 
bt2 tests: add unit tests for __str__ implementation of Fields

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ instead of __str__ for python Value
Jérémie Galarneau [Sun, 26 Nov 2017 10:46:19 +0000 (11:46 +0100)] 
Implement __repr__ instead of __str__ for python Value

Implement the __repr__ method for the various Value classes
as it provides a fallback for __str__ and provides both a
non-ambiguous and human-readable string representation of those
objects.

The Array and Map values' implementation is made more compact by
using list comprehensions, as is done for the Fields API.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoReturn 'Unset' on unset field __repr__()
Jérémie Galarneau [Thu, 23 Nov 2017 20:39:29 +0000 (15:39 -0500)] 
Return 'Unset' on unset field __repr__()

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ for _StringField
Jérémie Galarneau [Thu, 23 Nov 2017 19:43:04 +0000 (14:43 -0500)] 
Implement __repr__ for _StringField

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ instead of __str__ for _NumericField
Jérémie Galarneau [Thu, 23 Nov 2017 19:41:25 +0000 (14:41 -0500)] 
Implement __repr__ instead of __str__ for _NumericField

__repr__ provides a generic fallback for __str__ and, in the
case of IntegerFields the representation is both human readable
and unambiguous.

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ for _ArraySequenceField
Jérémie Galarneau [Thu, 23 Nov 2017 16:57:26 +0000 (11:57 -0500)] 
Implement __repr__ for _ArraySequenceField

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ for _VariantField
Jérémie Galarneau [Thu, 23 Nov 2017 16:57:02 +0000 (11:57 -0500)] 
Implement __repr__ for _VariantField

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ for _StructureField
Jérémie Galarneau [Thu, 23 Nov 2017 16:56:46 +0000 (11:56 -0500)] 
Implement __repr__ for _StructureField

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoImplement __repr__ for _EnumerationField
Jérémie Galarneau [Thu, 23 Nov 2017 16:56:23 +0000 (11:56 -0500)] 
Implement __repr__ for _EnumerationField

Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: typo using bt2.ClockClassOffset constructor
Francis Deslauriers [Tue, 21 Nov 2017 19:29:35 +0000 (14:29 -0500)] 
Fix: typo using bt2.ClockClassOffset constructor

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoAdd bindings/python/babeltrace/test_ctf_writer.py test
Philippe Proulx [Thu, 9 Nov 2017 17:38:40 +0000 (12:38 -0500)] 
Add bindings/python/babeltrace/test_ctf_writer.py test

This test ensures that we can use the legacy Python bindings to create a
CTF trace without caring about timestamp fields (they should be
automatically updated from the stream's class's clock value).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: stream.c: autopopulate timestamp fields even when not mapped to CC
Philippe Proulx [Thu, 9 Nov 2017 17:35:27 +0000 (12:35 -0500)] 
Fix: stream.c: autopopulate timestamp fields even when not mapped to CC

To remain backward compatible with Babeltrace 1's CTF writer,
automatically set the event header `timestamp` fields (when appending
the event) and packet context `timestamp_begin` and `timestamp_end`
fields (on stream flush) when the stream's class has a registered CTF
writer clock, even if the field's types are not mapped to a clock class.

If the field is mapped to a clock class, then it is automatically set
when this mapped clock class is the same as the stream's class's clock's
class.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: writer.py: make `uint64_ft` a 64-bit (instead of 32-bit) int FT
Philippe Proulx [Thu, 9 Nov 2017 16:24:30 +0000 (11:24 -0500)] 
Fix: writer.py: make `uint64_ft` a 64-bit (instead of 32-bit) int FT

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: Replace bt_timegm with a thread-safe implementation
Michael Jeanson [Mon, 13 Nov 2017 20:17:47 +0000 (15:17 -0500)] 
Fix: Replace bt_timegm with a thread-safe implementation

The current compat wrapper for timegm is not thread-safe, it modifies
the process wide time settings with tzset. This was not a problem in bt1
as it was only used in the cli binary but it is now used in the trimmer
plugin which is used by the library.

Replace the wrapper with a basic implementation and add more tests.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoTypo: informations -> information
Michael Jeanson [Mon, 13 Nov 2017 23:23:56 +0000 (18:23 -0500)] 
Typo: informations -> information

Information is an uncountable noun in english.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoTypo: paramater -> parameter
Michael Jeanson [Mon, 13 Nov 2017 23:22:42 +0000 (18:22 -0500)] 
Typo: paramater -> parameter

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoTypo: priorty -> priority
Michael Jeanson [Thu, 12 Oct 2017 21:15:25 +0000 (17:15 -0400)] 
Typo: priorty -> priority

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: uninitialized variable may be used warning
Jérémie Galarneau [Wed, 8 Nov 2017 15:55:16 +0000 (10:55 -0500)] 
Fix: uninitialized variable may be used warning

gcc 7.2 warns of potentially uninitialized variables being
used as the callers rely on output parameters being
initialized by the callees on error. This behaviour is not
specified as part of the API so relying on this is iffy.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agocli: support --output opt. for -o ctf-metadata and -i lttng-live
Philippe Proulx [Tue, 7 Nov 2017 19:57:32 +0000 (14:57 -0500)] 
cli: support --output opt. for -o ctf-metadata and -i lttng-live

Babeltrace 1 supports the -w/--output option to print the metadata text
or the available LTTng live sessions to a file instead of the standard
output.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: doc/man/Makefile.am: use appropriate variable for sources
Philippe Proulx [Thu, 2 Nov 2017 17:37:47 +0000 (13:37 -0400)] 
Fix: doc/man/Makefile.am: use appropriate variable for sources

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoAdd basic flt.lttng-utils.debug-info tests
Philippe Proulx [Thu, 2 Nov 2017 17:20:18 +0000 (13:20 -0400)] 
Add basic flt.lttng-utils.debug-info tests

This new test uses the bt2 Python bindings to test the
flt.lttng-utils.debug-info component class. The test opens the
tests/debug-info-data/trace trace and makes it pass through a
flt.lttng-utils.debug-info component to inject debugging information.
The test then checks that specific debugging information fields in
specific event notifications have the expected values.

This patch also removes the old tests/cli/test_debug_info.in test which
is not even enabled and relied on the output of sink.text.pretty.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agobt2: TraceCollectionNotificationIterator: support custom filter CCs
Philippe Proulx [Thu, 2 Nov 2017 17:14:54 +0000 (13:14 -0400)] 
bt2: TraceCollectionNotificationIterator: support custom filter CCs

This patch adds an optional `filter_component_specs` parameter to
TraceCollectionNotificationIterator's constructor so that the trace
collection notification iterator supports a chain of custom filter
components. The filter chain is connected to the implicit muxer's output
port or to the implicit trimmer's output port if it exists.

This is useful to add debugging information, for example:

    src = bt2.ComponentSpec('ctf', 'fs', trace_path)
    flt = bt2.ComponentSpec('lttng-utils', 'debug-info')
    it = bt2.TraceCollectionNotificationIterator(src, flt)

    for notif in it:
        ...

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: debug-info: remove `_` prefix when finding fields by name
Philippe Proulx [Thu, 2 Nov 2017 15:30:38 +0000 (11:30 -0400)] 
Fix: debug-info: remove `_` prefix when finding fields by name

The CTF plugin source components now remove the `_` prefix from field
names, so that other downstream components should not expect it as it's
an escaping mechanism in CTF 1.8.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoRemove doc/API.txt (Babeltrace 1.x API documentation)
Philippe Proulx [Thu, 5 Oct 2017 21:02:15 +0000 (17:02 -0400)] 
Remove doc/API.txt (Babeltrace 1.x API documentation)

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoAdd modern Babeltrace man pages
Philippe Proulx [Tue, 28 Feb 2017 19:41:57 +0000 (14:41 -0500)] 
Add modern Babeltrace man pages

The configuration to generate man pages from their AsciiDoc sources is
the same as the LTTng-tools setup, although doc/man/README.adoc is
specific to the Babeltrace project.

See doc/man/README.adoc for more details.

This patch also removes legacy documentation files of which the content
is now in the new man pages.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoRemove `PLUGIN` from component class log level environment variables
Philippe Proulx [Thu, 5 Oct 2017 18:05:42 +0000 (14:05 -0400)] 
Remove `PLUGIN` from component class log level environment variables

For example, `BABELTRACE_PLUGIN_CTF_FS_SRC_LOG_LEVEL` becomes
`BABELTRACE_SRC_CTF_FS_LOG_LEVEL`. This is in line with the way we
specify the component classes in the CLI and documentation, for
example `src.ctf.fs`.

The log level environment variables common to a whole plugin are still
prefixed with `PLUGIN`, for example
`BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agosink.text.dmesg: remove `read-from-stdin` parameter, use absent `path`
Philippe Proulx [Thu, 5 Oct 2017 04:15:23 +0000 (00:15 -0400)] 
sink.text.dmesg: remove `read-from-stdin` parameter, use absent `path`

We don't need separate `path` and `read-from-stdin` parameters for
this component class: if `path` is absent, read from standard input.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoLazy load the python plugin provider
Michael Jeanson [Mon, 2 Oct 2017 21:28:17 +0000 (17:28 -0400)] 
Lazy load the python plugin provider

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoPort: no sighandlers on Windows
Michael Jeanson [Mon, 2 Oct 2017 18:12:43 +0000 (14:12 -0400)] 
Port: no sighandlers on Windows

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoPort: normalize path in test_plugin_bt2
Michael Jeanson [Mon, 2 Oct 2017 17:52:14 +0000 (13:52 -0400)] 
Port: normalize path in test_plugin_bt2

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoPort: fix library load in python tests on Windows
Michael Jeanson [Mon, 2 Oct 2017 17:11:42 +0000 (13:11 -0400)] 
Port: fix library load in python tests on Windows

On Windows, the PATH variable is used to load library dependencies at runtime.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: use configured python in test_python_plugin_provider
Michael Jeanson [Mon, 2 Oct 2017 16:59:30 +0000 (12:59 -0400)] 
Fix: use configured python in test_python_plugin_provider

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoPort: open files in binary mode on Windows
Michael Jeanson [Thu, 15 Sep 2016 15:11:29 +0000 (15:11 +0000)] 
Port: open files in binary mode on Windows

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: ctf: notif-iter: do not call request_medium_bytes() when not needed
Philippe Proulx [Wed, 4 Oct 2017 00:10:17 +0000 (20:10 -0400)] 
Fix: ctf: notif-iter: do not call request_medium_bytes() when not needed

Do not systematically call request_medium_bytes(), that is, at the
beginning of read_dscope_begin_state(), because the scope field which is
about to be decoded might be empty, an already aligned structure
field or the equivalent (through a variant field for example, of which
the tag is outside this scope).

To do this we also need to make bt_btr_start() accept a size of 0. In
this case, if the field to decode is an empty structure which is already
aligned, then bt_btr_start() does not need to consume any bit and
returns BT_BTR_STATUS_OK with 0 consumed bits. In this case, the next
notif-iter state is not a continuing state, thus request_medium_bytes()
is not called yet.

Checking for a bad state when request_medium_bytes() receives
BT_NOTIF_ITER_MEDIUM_STATUS_EOF from the medium is easier. Good states
are:

* If the current packet size is set:
** Current packet offset is current packet size.
* Otherwise:
** Current packet offset is 0.
** Last event header offset is set and current offset is equal to it.

All other states are invalid.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoflt.lttng-utils.debug-info: `dir`/`debug-dir` param -> `debug-info-dir`
Philippe Proulx [Mon, 2 Oct 2017 20:03:40 +0000 (16:03 -0400)] 
flt.lttng-utils.debug-info: `dir`/`debug-dir` param -> `debug-info-dir`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agocli: do not automatically create an implicit filter.lttng-utils.debug-info comp.
Philippe Proulx [Mon, 2 Oct 2017 17:18:39 +0000 (13:18 -0400)] 
cli: do not automatically create an implicit filter.lttng-utils.debug-info comp.

Remove --no-debug-info option, and add --debug-info option to explicitly
enable this filter.

Fix tests/cli/test_convert_args.in which now does not depend on
ENABLE_DEBUG_INFO.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoctf, ir: escape and unescape enumeration FT labels starting with `_`
Philippe Proulx [Mon, 2 Oct 2017 16:57:12 +0000 (12:57 -0400)] 
ctf, ir: escape and unescape enumeration FT labels starting with `_`

This is a solution to work with TSDL 1.8 which asks identifiers starting
with `_` to be named without the `_` for viewing and analysis purposes.
Since a variant FT can refer to an enumeration FT tag which also has its
labels starting with `_`, we systematically remove leading `_` in
enumeration FT labels too.

For example:

    enum {
        _salut,
        hello,
        __zoom,
        _integer,
    } tag;

    variant <tag> {
        A _salut;
        B hello;
        C __zoom;
        D _integer;
    } var;

Once in CTF IR, the equivalent is:

    enum {
        salut,
        hello,
        _zoom,
        integer,
    } tag;

    variant <tag> {
        A salut;
        B hello;
        C _zoom;
        D integer;
    } var;

Once back to TSDL (through CTF writer), it is:

    enum {
        salut,
        hello,
        __zoom,
        _integer,
    } tag;

    variant <tag> {
        A salut;
        B hello;
        C __zoom;
        D _integer;
    } var;

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agocli: --stream-intersection is not an implicit src.ctf.fs component's option
Philippe Proulx [Thu, 28 Sep 2017 13:36:22 +0000 (09:36 -0400)] 
cli: --stream-intersection is not an implicit src.ctf.fs component's option

You can use the --stream-intersection option with any source component
class which supports the `trace-info` query, not just with src.ctf.fs.
Also, using --stream-intersection does not imply a src.ctf.fs component
like --clock-class-offset-s does for example.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agocli: do not use --component in help command, only use leftover argument
Philippe Proulx [Wed, 20 Sep 2017 00:04:03 +0000 (20:04 -0400)] 
cli: do not use --component in help command, only use leftover argument

Options should be used for optional arguments. In the case of
`babeltrace help`, the component class specification is mandatory when
you don't want help about a plugin, so use the first positional
"leftover" argument.

First try the TYPE.PLUGIN.COMPCLS form, then fallback to PLUGIN if it's
invalid.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoAdd compat layer's log level env. var. to CLI's list of known env. vars
Philippe Proulx [Tue, 19 Sep 2017 20:10:08 +0000 (16:10 -0400)] 
Add compat layer's log level env. var. to CLI's list of known env. vars

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agocli: put the project's version on the first line with no args.
Philippe Proulx [Mon, 25 Sep 2017 19:44:47 +0000 (15:44 -0400)] 
cli: put the project's version on the first line with no args.

This is to ensure backward compatibility with Babeltrace 1.x, especially
for the LTTng analyses project which check the Babeltrace's version this
way because of a missing --version option.

Reported-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: legacy python bindings Makefile
Michael Jeanson [Thu, 21 Sep 2017 19:09:38 +0000 (15:09 -0400)] 
Fix: legacy python bindings Makefile

No need for build_ext, this is a pure python module.
Add missing stamp file to CLEANFILES.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agobt2, babeltrace: apply PEP 8 except for E501 and E722
Philippe Proulx [Fri, 22 Sep 2017 19:37:52 +0000 (15:37 -0400)] 
bt2, babeltrace: apply PEP 8 except for E501 and E722

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: babeltrace: writer.py: do not use += on bt2.trace._TraceEnv
Philippe Proulx [Fri, 22 Sep 2017 19:08:14 +0000 (15:08 -0400)] 
Fix: babeltrace: writer.py: do not use += on bt2.trace._TraceEnv

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agobindings/python/babeltrace/Makefile.am: do not clean __init__.py
Philippe Proulx [Fri, 22 Sep 2017 05:24:04 +0000 (01:24 -0400)] 
bindings/python/babeltrace/Makefile.am: do not clean __init__.py

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoRename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
Philippe Proulx [Fri, 22 Sep 2017 00:51:34 +0000 (20:51 -0400)] 
Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer

This patch replaces the `bt_ctf_` prefix with `bt_` for all the
functions, types, and enumerations. It also replaces the `BT_CTF_`
prefix with `BT_` for all the preprocessor definitions and enumerators.

Since there is only one IR as of Babeltrace 2, there is no need for this
superfluous prefix: there's no confusion without it, and it might even
be more straightforward for the newcomer to see `bt_trace` instead of
`bt_ctf_trace`, for example.

Backward compatibility is maintained with the help of specific
preprocessor definitions placed in each relevant public header file to
create aliases for legacy function names, type names, enumerator names,
and preprocessor definition names. Because Babeltrace 2 asks current
applications to be rebuilt anyway (soname is bumped), it is okay to lose
some symbol names as long as the API is equivalent.

The only possible issue that I can see is if an application uses a new
API name as a variable name, for example:

    struct bt_ctf_trace bt_ctf_trace;
    struct something_else bt_trace;

This is an error after this patch is applied because, after the
preprocessor pass, it is the equivalent of:

    struct bt_trace bt_trace;
    struct something_else bt_trace;

because of (include/babeltrace/ctf-ir/trace.h):

    #define bt_ctf_trace bt_trace

which affects both the type name and the variable name. This should not
be a problem in most cases, and it is easy to fix otherwise.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: variable declaration shadows previously declared variable
Jérémie Galarneau [Thu, 5 Oct 2017 20:39:39 +0000 (16:39 -0400)] 
Fix: variable declaration shadows previously declared variable

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: use tabs rather than spaces in makefile
Mathieu Desnoyers [Wed, 20 Sep 2017 17:58:43 +0000 (13:58 -0400)] 
Fix: use tabs rather than spaces in makefile

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reported-by: Jonah Caplan <jcaplan@blackberry.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoPort: do not depend on GNU readlink
Michael Jeanson [Tue, 19 Sep 2017 20:26:30 +0000 (16:26 -0400)] 
Port: do not depend on GNU readlink

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: use the configured swig executable
Michael Jeanson [Mon, 18 Sep 2017 21:28:13 +0000 (17:28 -0400)] 
Fix: use the configured swig executable

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoTests python: reference ctf traces are not copied to the build dir
Jérémie Galarneau [Mon, 18 Sep 2017 21:36:38 +0000 (17:36 -0400)] 
Tests python: reference ctf traces are not copied to the build dir

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 years agoFix: tests/Makefile.am: add missing LOG_DRIVER
Philippe Proulx [Mon, 18 Sep 2017 21:27:28 +0000 (17:27 -0400)] 
Fix: tests/Makefile.am: add missing LOG_DRIVER

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
This page took 0.050612 seconds and 4 git commands to generate.