Create virtual LTTng environments with vlttng
In my day to day job at EfficiOS, I often have to manually test different versions and configurations of LTTng. The typical way to test LTTng 2.7 if LTTng 2.8 is installed, for example, is, for each of the three LTTng projects (LTTng-tools, LTTng-UST, and LTTng-modules):
- Uninstall the current version (2.8).
- Check out version 2.7.
- Configure, build, and install version 2.7.
This whole manual process becomes painful over time. I'm not even mentioning the situations where I also need to test different versions of the tools' dependencies, like Glib and Libxml2. The same laborious process applies to Babeltrace.
In an ideal world, I would have multiple environments containing
different versions and configurations of the tools and dependencies
which form the LTTng ecosystem. This is totally possible with the
various environment variables and configure flags (
--with-lttng-ust-prefix, and the rest) of the projects. And this is
exactly what vlttng exploits to
achieve this. vlttng is a project I've been working on in my spare time.
In this article I explain what vlttng is exactly, after which I show a concrete example.
I'm a big fan of
virtualenv. This tool
is used to create isolated Python environments. A Python virtual
environment has its own packages, its own version of Python, and its own
pip. It's as easy as this to create one:
Then you get a directory named
my-env which contains the virtual
environment tree, as well as an activation script. You can "enter" the
virtual environment by sourcing this script:
Your prompt is prefixed with
(my-env) to indicate that you're in this
virtual environment. Now, everything you do that's Python-related only
has an effect on this directory. For example, let's install a few
pip and start
pip install zmq pip install pyyaml pip install flask ipython
pip installs the packages in
ipython uses the Python
interpreter found in
This is an awesome tool if you are a Python developer because you can create a Python environment with a very specific set of packages (with precise versions).
virtual-env, I made
vlttng to create LTTng virtual
environments. The concept is very similar.
vlttng command-line tool knows how to download, configure, build,
and install each LTTng-related project, including
analyses, and Trace
Compass, as well as all their dependencies.
The tool knows how to configure the projects depending on which other
projects need to be built and installed.
I also created a command-line tool named
interactively asks you a few questions to generates a
vlttng-quick can also run this command line once you answer its
Some notable features of the generated virtual environment are:
vlttngdownloads and installs Apache log4j in the virtual environment when it detects that the LTTng-UST Java agent for log4j needs to be installed.
VLTTNG_CLASSPATHenvironment variable when it detects that the LTTng-UST Java agent needs to be installed. You can use this environment variable when you build and run your Java application:
javac -cp $VLTTNG_CLASSPATH MyApp.java java -cp $VLTTNG_CLASSPATH:. MyApp
PYTHONPATHenvironment variable so that the Babeltrace Python bindings, LTTng analyses, and LTTng-UST Python agent packages are found in the virtual environment first.
PKG_CONFIG_PATHenvironment variable so that
pkg-configfinds the metadata in the virtual environment first:
pkg-config --libs lttng-ust
MANPATHenvironment variable so that you can read the environment's man pages using
man lttng-enable-event man babeltrace
LDFLAGSenvironment variables so that you can build an application which uses any build system that recognizes those variables against the headers and libraries of the virtual environment:
./configure && make
vlttnggenerates scripts in the virtual environment directory to reconfigure, rebuild, reinstall, and update projects that were installed from a Git source:
vlttng can probably help you if:
- You want to contribute to one of the LTTng or Babeltrace projects.
- You want to test a specific configuration of the tools without tainting the system.
- You want to use LTTng on a distribution with no LTTng packages.
- You want to cross-compile the tools.
Let's try it!
sudo pip3 install --upgrade vlttng
If you're not fond of a system-wide installation, install it for you only:
pip3 install --user --upgrade vlttng
In this case, make sure
$HOME/.local/bin is part of your
Let's create an LTTng virtual environment with LTTng 2.8, Babeltrace 1.4, the latest Libxml2, and the latest LTTng analyses:
vlttng -p lttng-stable-2.8 -p babeltrace-stable-1.4 -p libxml2-master \ -p lttng-analyses-master --jobs=4 my-env
The output of the command shows the current operation. Once the command exits, you can activate the generated virtual environment:
Since the LTTng-modules project is part of the profile, the activation script removes the currently loaded LTTng kernel modules, if any.
Your prompt is prefixed with
[my-env] to indicate that you're in this
virtual LTTng environment.
Now, you can use the tracers as usual:
sudo --preserve-env lttng-sessiond --daemonize lttng create lttng enable-event --kernel sched_'*' lttng start # ... lttng stop lttng view lttng destroy
You need to use the
--preserve-env option of
sudo to preserve the
virtual environment variables when
sudo runs the session daemon.
By default, LTTng creates the trace in the
lttng view command executes the
babeltrace program installed
Once you're done, exit this virtual environment:
Make sure to read the project's README to learn how to customize profiles, override profile properties, ignore projects, and more.