lib: make BT_ASSERT_{PRE,POST}() always on; add BT_ASSERT_{PRE,POST}_DEV()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 9 Jul 2019 12:25:44 +0000 (08:25 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 9 Jul 2019 23:42:30 +0000 (19:42 -0400)
commitbdb288b3e94e412a33c8647d44f6cfac66ca0665
tree140065cbf1b713abf8c4ad4028077dda10077783
parent185ecf645233ced089ad72b060a420e8f6f7edeb
lib: make BT_ASSERT_{PRE,POST}() always on; add BT_ASSERT_{PRE,POST}_DEV()

This patch makes the BT_ASSERT_PRE() and BT_ASSERT_POST() macros, and
all their variants, always executed. In other words, the checks are
executed in developer mode and in production mode.

What used to be BT_ASSERT_PRE() and BT_ASSERT_POST(), enabled only in
developer mode, is now BT_ASSERT_PRE_DEV() and BT_ASSERT_POST_DEV().

The goal of this patch is to add precondition and postcondition checks
on the slow path which are enabled in production to catch more
programming errors. As I meticulously chose which one to invoke at each
site, this patch does not change the performance of the library during a
graph run, which is most of the execution time.

Because all the freezing functions are only enabled in developer mode,
`assert-pre.h` only offers BT_ASSERT_PRE_DEV_HOT() currently (there's no
production mode BT_ASSERT_PRE_HOT()). This is because some freezing
functions can be called on the fast path (for example, the internal
bt_event_create() freezes the event class, packet, and stream; this is
called for each event message), while other are only called on the slow
path. This patch does not decouple the frequent ones from the infrequent
ones; this work should be done by a subsequent patch.

Where all the precondition/postcondition assertions used to be only
enabled in developer mode, the library now contains 105 production
checks.

When I test with a 1.4 GiB CTF trace and a dummy output in production
mode, the difference of the total execution times with and without this
patch falls within the range of uncertainty.

The guideline to use one or the other is:

* Use BT_ASSERT_PRE_DEV() and BT_ASSERT_POST_DEV() when the call site
  could occur at least once per message.

  This is why all the borrowing functions use the developer mode
  versions as we don't know at which frequency what will be accessed.

* Use BT_ASSERT_PRE() and BT_ASSERT_POST() everywhere else.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2ccdec4cee332a13d330474d287c564b7cb90352
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1661
Tested-by: jenkins <jenkins@lttng.org>
40 files changed:
CONTRIBUTING.adoc
src/lib/assert-post.h
src/lib/assert-pre.h
src/lib/graph/component-class.c
src/lib/graph/component-filter.c
src/lib/graph/component-sink.c
src/lib/graph/component-source.c
src/lib/graph/component.c
src/lib/graph/connection.c
src/lib/graph/graph.c
src/lib/graph/graph.h
src/lib/graph/iterator.c
src/lib/graph/message/discarded-items.c
src/lib/graph/message/event.c
src/lib/graph/message/message-iterator-inactivity.c
src/lib/graph/message/message.c
src/lib/graph/message/message.h
src/lib/graph/message/packet.c
src/lib/graph/message/stream.c
src/lib/graph/port.c
src/lib/graph/query-executor.c
src/lib/object.h
src/lib/plugin/plugin.c
src/lib/trace-ir/clock-class.c
src/lib/trace-ir/clock-snapshot.c
src/lib/trace-ir/event-class.c
src/lib/trace-ir/event.c
src/lib/trace-ir/event.h
src/lib/trace-ir/field-class.c
src/lib/trace-ir/field-class.h
src/lib/trace-ir/field-path.c
src/lib/trace-ir/field.c
src/lib/trace-ir/field.h
src/lib/trace-ir/packet.c
src/lib/trace-ir/resolve-field-path.c
src/lib/trace-ir/stream-class.c
src/lib/trace-ir/stream.c
src/lib/trace-ir/trace-class.c
src/lib/trace-ir/trace.c
src/lib/value.c
This page took 0.027854 seconds and 4 git commands to generate.