Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 18 Oct 2019 15:59:27 +0000 (11:59 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 22 Oct 2019 17:56:14 +0000 (13:56 -0400)
commit98b15851a941e7342b8bb19e265cdc3a40fabfb8
tree21669a0bde552df905085f26cd2e97c6f8515ac8
parent4b3b8e4ad436df173c9ecdf8279ccaa3a6d41201
Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only

This patch makes BT_ASSERT() always evaluate its condition.

The goal is to make a lot of _slow path_ assertions evaluated whatever
the debug or non-debug mode. This will help detect project programming
errors and hopefully end users will report them.

What used to be BT_ASSERT() is now BT_ASSERT_DBG(), that is, only
evaluated in debug mode. This is similar to how BT_ASSERT_PRE() is
always evaluated while BT_ASSERT_PRE_DEV() is only evaluated in
developer mode.

I went over each single BT_ASSERT() statement in `src` and decided
whether to use BT_ASSERT() or BT_ASSERT_DBG(). My strategy is similar
to what we do for BT_ASSERT_PRE(), that is:

* Use BT_ASSERT_DBG() in anything potentially executed once or more per
  _event_ message.

  Other messages occur so infrequently compared to event messages that
  we don't care.

* Use BT_ASSERT_DBG() in property getters and object borrowing
  functions.

  We don't know how frequently the user can call those, so we don't take
  any chance.

Everything else uses BT_ASSERT(), for example:

* In the library and plugins, everything related to metadata objects.
* Everything related to graph topology.
* Everything in the CLI.
* Network communication functions in `src.ctf.lttng-live`.

I believe some BT_ASSERT_DBG() statements could still be converted
BT_ASSERT(), but this patch is a good starting point.

I left the whole CTF writer code with BT_ASSERT_DBG() for the moment
as this library is not a priority.

All the tests use BT_ASSERT() because they are not an end user use case;
we don't care if they are less efficient in production mode.

This change does not seem to affect the production build's performance;
I compared, before and after, and I do not get a run time difference
that's greater than the observed measurement error.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia74951a39b1fcc79579661562f6a98ed208fd9bb
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2217
Tested-by: jenkins <jenkins@lttng.org>
102 files changed:
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
src/bindings/python/bt2/bt2/native_bt_message_iterator.i.h
src/common/assert.h
src/common/common.c
src/common/common.h
src/common/uuid.c
src/compat/stdio.h
src/ctf-writer/assert-pre.h
src/ctf-writer/attributes.c
src/ctf-writer/clock-class.c
src/ctf-writer/clock.c
src/ctf-writer/event-class.c
src/ctf-writer/event-class.h
src/ctf-writer/event.c
src/ctf-writer/event.h
src/ctf-writer/field-path.c
src/ctf-writer/field-types.c
src/ctf-writer/field-wrapper.c
src/ctf-writer/fields.c
src/ctf-writer/fields.h
src/ctf-writer/object-pool.c
src/ctf-writer/object-pool.h
src/ctf-writer/object.h
src/ctf-writer/resolve.c
src/ctf-writer/stream-class.c
src/ctf-writer/stream-class.h
src/ctf-writer/stream.c
src/ctf-writer/stream.h
src/ctf-writer/trace.c
src/ctf-writer/trace.h
src/ctf-writer/utils.c
src/ctf-writer/utils.h
src/ctf-writer/values.c
src/ctf-writer/writer.c
src/ctfser/ctfser.h
src/lib/assert-post.h
src/lib/assert-pre.h
src/lib/graph/component-class-sink-simple.c
src/lib/graph/component-filter.c
src/lib/graph/component-sink.c
src/lib/graph/component-source.c
src/lib/graph/component.h
src/lib/graph/connection.h
src/lib/graph/graph.c
src/lib/graph/graph.h
src/lib/graph/interrupter.h
src/lib/graph/iterator.c
src/lib/graph/message/discarded-items.c
src/lib/graph/message/event.c
src/lib/graph/message/message.h
src/lib/graph/message/packet.c
src/lib/graph/message/stream.c
src/lib/graph/port.h
src/lib/integer-range-set.c
src/lib/object-pool.h
src/lib/object.h
src/lib/plugin/plugin.c
src/lib/prio-heap/prio-heap.c
src/lib/trace-ir/attributes.c
src/lib/trace-ir/clock-class.h
src/lib/trace-ir/clock-snapshot-set.h
src/lib/trace-ir/clock-snapshot.c
src/lib/trace-ir/clock-snapshot.h
src/lib/trace-ir/event-class.h
src/lib/trace-ir/event.c
src/lib/trace-ir/event.h
src/lib/trace-ir/field-class.c
src/lib/trace-ir/field-path.h
src/lib/trace-ir/field-wrapper.c
src/lib/trace-ir/field.c
src/lib/trace-ir/field.h
src/lib/trace-ir/stream-class.h
src/lib/trace-ir/stream.h
src/lib/trace-ir/trace.c
src/lib/trace-ir/utils.h
src/plugins/ctf/common/bfcr/bfcr.c
src/plugins/ctf/common/metadata/ctf-meta.h
src/plugins/ctf/common/metadata/decoder.c
src/plugins/ctf/common/metadata/parser.y
src/plugins/ctf/common/metadata/visitor-generate-ir.c
src/plugins/ctf/common/msg-iter/msg-iter.c
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/fs-sink.c
src/plugins/ctf/fs-src/data-stream-file.c
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/lttng-live/lttng-live.c
src/plugins/ctf/lttng-live/metadata.c
src/plugins/lttng-utils/debug-info/debug-info.c
src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-mapping.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
src/plugins/text/details/details.c
src/plugins/text/details/obj-lifetime-mgmt.c
src/plugins/text/details/write.c
src/plugins/text/dmesg/dmesg.c
src/plugins/text/pretty/pretty.c
src/plugins/text/pretty/print.c
src/plugins/utils/counter/counter.c
src/plugins/utils/dummy/dummy.c
src/plugins/utils/muxer/muxer.c
src/plugins/utils/trimmer/trimmer.c
This page took 0.036566 seconds and 4 git commands to generate.