1 ![Icon made by Freepik from www.flaticon.com](https://lttng.org/blog/images/barectf.png)
3 [![](https://img.shields.io/pypi/v/barectf.svg)](https://pypi.python.org/pypi/barectf)
4 [![Jenkins](https://img.shields.io/jenkins/s/https/ci.lttng.org/barectf_master_build.svg)](https://ci.lttng.org/job/barectf_master_build)
6 **barectf** is a command-line utility which generates ANSI C
7 code that is able to write native [Common Trace Format](http://diamon.org/ctf)
10 You will find barectf interesting if:
12 1. You need to trace an application.
13 2. You need tracing to be efficient, yet flexible:
14 record integers of custom sizes, custom floating point numbers,
15 enumerations supported by a specific integer type, and
16 null-terminated UTF-8/ASCII strings (C strings).
17 3. You need to be able to convert the recorded binary events to
18 human-readable text, as well as analyze them with Python scripts
19 ([Babeltrace](http://diamon.org/babeltrace/) does all that,
21 4. You _cannot_ use [LTTng](http://lttng.org/), an efficient tracing
22 framework for the Linux kernel and Linux/BSD user applications, which
25 The target audience of barectf is developers who need to trace bare metal
26 systems (without an operating system). The code produced by barectf
27 is pure ANCI C (with one exception, see the current limitations below)
28 and can be lightweight enough to fit on a tiny microcontroller.
32 * Single input: easy-to-write [YAML configuration
33 file](https://github.com/efficios/barectf/wiki/Writing-the-YAML-configuration-file)
34 * 1-to-1 mapping from tracing function parameters to event fields
36 [_platforms_](https://github.com/efficios/barectf/wiki/barectf-platform)
37 hiding the details of opening/closing packets and writing them to a
38 back-end (continuous tracing), getting the clock values, etc.:
39 * _linux-fs_: basic Linux application tracing writing stream files to
40 the file system for demonstration purposes
41 * _parallella_: Adapteva Epiphany/[Parallella](http://parallella.org/)
42 with host-side consumer
43 * CTF metadata generated by the command-line tool (automatic trace UUID,
44 stream IDs, and event IDs)
45 * All basic CTF types are supported: integers, floating point numbers,
46 enumerations, and null-terminated strings (C strings)
47 * Binary streams produced by the generated C code and metadata file
48 produced by barectf are CTF 1.8-compliant
49 * Human-readable error reporting
51 **Current limitations**:
55 * All the generated tracing C functions, for a given barectf
56 stream-specific context, need to be called from the same thread, and cannot
57 be called from an interrupt handler, unless a user-provided
58 synchronization mechanism is used.
59 * The generated C code needs the `stdint.h` header, which is new in
60 C99. If your standard C library does not have this header,
61 you can create one yourself and put it in one of your include
62 directories to define the following types according to your
72 * CTF compound types (array, sequence, structure, variant) are not
73 supported yet, except at some very specific locations in the
76 barectf is written in Python 3.
81 Make sure you have Python 3 and `pip` for Python 3 installed, then
84 Note that you may pass the `--user` argument to
85 `pip install` to install the tool in your home directory (instead of
88 **Ubuntu 14.04 and 16.04**:
90 It is recommended to use the
91 [barectf PPA](https://launchpad.net/~lttng/+archive/ubuntu/barectf),
92 which also installs the man page:
94 sudo apt-add-repository ppa:lttng/barectf
96 sudo apt-get install python3-barectf
98 Otherwise, you can always use `pip3`:
100 sudo apt-get install python3-pip
101 sudo pip3 install barectf
103 **Other, recent Ubuntu**:
105 sudo apt-get install python3-pip
106 sudo pip3 install barectf
108 **Ubuntu 12.04 and lower**:
110 sudo apt-get install python3-setuptools
111 sudo easy_install3 pip
112 sudo pip3 install barectf
116 sudo apt-get install python3-pip
117 sudo pip3 install barectf
119 **Fedora 20 and up**:
121 sudo yum install python3-pip
122 sudo pip3 install barectf
126 It is recommended to use the
127 [AUR package](https://aur.archlinux.org/packages/barectf/), which also
128 installs the man page. If you have
129 [yaourt](https://archlinux.fr/yaourt-en):
131 sudo yaourt -Sy barectf
133 Otherwise, you can always use `pip`:
135 sudo pacman -S python-pip
136 sudo pip install barectf
140 With [Homebrew](http://brew.sh/):
148 Since the philosophy of setuptools packages is to include everything
149 within the package, the barectf man page is not installed on the system
150 when installing barectf with `pip` or with `setup.py`. This would be the
151 job of distribution packages.
153 You can install it manually:
155 wget https://raw.githubusercontent.com/efficios/barectf/vVERSION/doc/man/barectf.1 -O /usr/local/man/man1/barectf.1
157 Replace `VERSION` with the desired version, for example:
159 wget https://raw.githubusercontent.com/efficios/barectf/v2.1.4/doc/man/barectf.1 -O /usr/local/man/man1/barectf.1
164 See the [CTF in a nutshell](http://diamon.org/ctf/#ctf-in-a-nutshell)
165 section of CTF's website to understand the basics of this
168 The most important thing to understand about CTF, for barectf use
169 cases, is the layout of a binary stream packet:
171 * Packet header (defined at the trace level)
172 * Packet context (defined at the stream level)
173 * Sequence of events (defined at the stream level):
174 * Event header (defined at the stream level)
175 * Stream event context (defined at the stream level)
176 * Event context (defined at the event level)
177 * Event payload (defined at the event level)
179 The following diagram, stolen without remorse from CTF's website, shows
182 ![](http://diamon.org/ctf/img/ctf-stream-packet.png)
184 Any of those six dynamic scopes, if defined at all, has an associated
185 CTF type. barectf requires them to be structure types.
190 See the [project's wiki](https://github.com/efficios/barectf/wiki) which
191 contains all the information needed to use barectf.
196 Bash is required for testing barectf.
198 The barectf tests execute the `barectf` command available in your
199 `$PATH`. The best way to test a specific version of barectf is to create
200 a Python 3 [virtual environment](https://virtualenv.pypa.io/en/latest/),
201 install the appropriate version, and then run the tests.
203 In the barectf source tree root, do:
205 virtualenv --python=python3 virt
206 . ./virt/bin/activate
207 rehash # if using zsh
209 (cd tests && ./test.bash)
211 You can specify [Bats](https://github.com/sstephenson/bats) options to
212 `./test.bash`, like `--tap` to get a [TAP](https://testanything.org/)
215 You can exit the virtual environment by running `deactivate`.
220 Since the barectf community is small, it's sharing the communication
221 channels of the [LTTng](http://lttng.org/) project,
222 as [EfficiOS](http://www.efficios.com/) is the main sponsor of both
223 projects. It goes like this:
225 | Item | Location | Notes |
227 | Mailing list | [lttng-dev](https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev) (`lttng-dev@lists.lttng.org`) | Preferably, use the `[barectf]` subject prefix |
228 | IRC | [`#lttng`](irc://irc.oftc.net/lttng) on the OFTC network | More specifically, query `eepp` (barectf's maintainer) on this network or on freenode |
229 | Code contribution | Create a new GitHub [pull request](https://github.com/efficios/barectf/pulls) | |
230 | Bug reporting | Create a new GitHub [issue](https://github.com/efficios/barectf/issues/new) | |
231 | Continuous integration | [barectf item on LTTng's CI](https://ci.lttng.org/job/barectf/) | |
232 | Blog | The [LTTng blog](http://lttng.org/blog/) contains many posts about barectf | |