= babeltrace2-run(1)
:manpagetype: command
:revdate: 14 September 2019


== NAME

babeltrace2-run - Create a Babeltrace 2 trace processing graph and run it


[[synopsis]]
== SYNOPSIS

[verse]
*babeltrace2* [<<gen-opts,'GENERAL OPTIONS'>>] *run* [opt:--retry-duration='TIME-US']
            opt:--connect='CONN-RULE'... 'COMPONENTS'


== DESCRIPTION

The `run` command creates a Babeltrace~2 trace processing graph and
runs it.

include::common-see-babeltrace2-intro.txt[]

The `run` command dynamically loads Babeltrace~2 plugins which
supply component classes. With the `run` command, you specify which
component classes to instantiate as components and how to connect them.

The steps to write a `babeltrace2 run` command line are:

. Specify which component classes to instantiate as components with many
  opt:--component options and how to configure them.
+
This is the 'COMPONENTS' part of the <<synopsis,synopsis>>. See
<<create-comps,``Create components''>> to learn more.

. Specify how to connect components together with one or more
  opt:--connect options.
+
See <<connect-comps,``Connect components''>> to learn more.

NOTE: The man:babeltrace2-convert(1) command is a specialization of the
`run` command for the very common case of converting one or more traces:
it generates a `run` command line and executes it. You can use its
manopt:babeltrace2-convert(1):--run-args or
manopt:babeltrace2-convert(1):--run-args-0 option to make it print the
equivalent `run` command line instead.


[[create-comps]]
=== Create components

To create a component, use the opt:--component option. This option
specifies:

* The name of the component, unique amongst all the component names of
  the trace processing graph.

* The type of the component class to instantiate: source, filter, or
  sink.

* The name of the plugin in which to find the component class to
  instantiate.

* The name of the component class to instantiate.

Use the opt:--component option multiple times to create multiple
components. You can instantiate the same component class multiple times
as different components.

At any point in the command line, the opt:--base-params sets the current
base initialization parameters and the opt:--reset-base-params resets
them. When you specify a opt:--component option, its initial
initialization parameters are a copy of the current base initialization
parameters.

Immediately following a opt:--component option on the command line, the
created component is known as the _current component_ (until the next
opt:--component option).

The opt:--params='PARAMS' option adds parameters to the current
component's initialization parameters. If 'PARAMS' contains a key which
exists in the current component's initialization parameters, this
parameter is replaced.


[[connect-comps]]
=== Connect components

The components which you create from component classes with the
opt:--component option (see <<create-comps,``Create components''>>) add
input and output _ports_ depending on their type. An output port is from
where messages, like trace events, are sent. An input port is where
messages are received. For a given component, each port has a unique
name.

The purpose of the `run` command is to create a trace processing graph,
that is, to know which component ports to connect together. The command
achieves this with the help of the connection rules that you provide
with one or more opt:--connect='CONN-RULE' options.

The format of 'CONN-RULE' is:

[verse]
__UP-COMP-PAT__[.__UP-PORT-PAT__]:__DOWN-COMP-PAT__[.__DOWN-PORT-PAT__]

'UP-COMP-PAT'::
    Upstream component name pattern.

'UP-PORT-PAT'::
    Upstream (output) port name pattern.

'DOWN-COMP-PAT'::
    Downstream component name pattern.

'DOWN-PORT-PAT'::
    Downstream (input) port name pattern.

When a source or filter component adds a new output port within the
processing graph, the `run` command does the following to find an
input port to connect it to:

----
For each connection rule (--connect options, in order):
  If the output port's component's name matches UP-COMP-PAT and the
  output port's name matches UP-PORT-PAT:
    For each component COMP in the trace processing graph:
      If the name of COMP matches DOWN-COMP-PAT:
        Select the first input port of COMP of which the name matches
        DOWN-PORT-PAT, or fail with no match.

No possible connection: fail with no match.
----

__UP-COMP-PAT__, __UP-PORT-PAT__, __DOWN-COMP-PAT__, and
__DOWN-PORT-PAT__ are globbing patterns where only the wildcard
character, `*`, is special: it matches zero or more characters. You must
escape the `*`, `?`, `[`, `.`, `:`, and :bs: characters with :bs:.

When you do not specify __UP-PORT-PAT__ or __DOWN-PORT-PAT__, they are
equivalent to `*`.

You can leverage this connection mechanism to specify fallbacks with a
careful use of wildcards, as the order of the opt:--connect options on
the command line is significant. For example:

----
--connect='A.out*:B.in*' --connect=A:B --connect='*:C'
----

With those connection rules, the `run` command connects:

* Any output port of which the name starts with `out` of component `A`
  to the first input port of which the name starts with `in` of
  component `B`.

* Any other output port of component `A` to the first available input
  port of component `B`.

* Any other output port (of any component except `A`) to the first
  available input port of component `C`.

The `run` command fails when it cannot find an input port to which to
connect a given output port using the provided connection rules.

See <<examples,``EXAMPLES''>> for more examples.


== OPTIONS

include::common-gen-options.txt[]


=== Component creation

See <<create-comps,``Create components''>> for more details.

opt:-b 'PARAMS'::
opt:--base-params='PARAMS'::
    Set the current base parameters to 'PARAMS'.
+
You can reset the current base parameters with the
opt:--reset-base-params option.
+
See the opt:--params option for the format of 'PARAMS'.

opt:-c __NAME__:__COMP-CLS-TYPE__.'PLUGIN-NAME'.'COMP-CLS-NAME'::
opt:--component=__NAME__:__COMP-CLS-TYPE__.'PLUGIN-NAME'.'COMP-CLS-NAME'::
    Create a component named 'NAME' from the component class of type
    'COMP-CLS-TYPE' named 'COMP-CLS-NAME' found in the plugin named
    'PLUGIN-NAME', and set it as the current component.
+
The available values for 'TYPE' are:
+
--
`source`::
`src`::
    Source component class.

`filter`::
`flt`::
    Filter component class.

`sink`::
    Sink component class.
--
+
The initial initialization parameters of this component are copied from
the current base initialization parameters (see the opt:--base-params
option).

opt:-l 'LVL'::
opt:--log-level='LVL'::
    Set the log level of the current component to 'LVL'.
+
The available values for 'LVL' are:
+
--
include::common-log-levels.txt[]
--

opt:-p 'PARAMS'::
opt:--params='PARAMS'::
    Add 'PARAMS' to the initialization parameters of the current
    component.
+
If 'PARAMS' contains a key which exists in the current component's
initialization parameters, replace the parameter.
+
--
include::common-cmd-params-format.txt[]
--

opt:-r::
opt:--reset-base-params::
    Reset the current base parameters.
+
You can set the current base parameters with the opt:--base-params
option.


=== Component connection

opt:-x 'CONN-RULE'::
opt:--connect='CONN-RULE'::
    Add the connection rule 'CONN-RULE'.
+
The format of 'CONN-RULE' is:
+
[verse]
__UP-COMP-PAT__[.__UP-PORT-PAT__]:__DOWN-COMP-PAT__[.__DOWN-PORT-PAT__]
+
--
'UP-COMP-PAT'::
    Upstream component name pattern.

'UP-PORT-PAT'::
    Upstream (output) port name pattern.

'DOWN-COMP-PAT'::
    Downstream component name pattern.

'DOWN-PORT-PAT'::
    Downstream (input) port name pattern.
--
+
See <<connect-comps,``Connect components''>> to learn more.


=== Graph configuration

opt:--retry-duration='TIME-US'::
    Set the duration of a single retry to 'TIME-US'~µs when a sink
    component reports "try again later" (busy network or file system,
    for example).
+
Default: 100000 (100~ms).


include::common-cmd-info-options.txt[]


[[examples]]
== EXAMPLES

.Create a single-port source component and a single-port sink component and connect them.
====
[role="term"]
----
$ babeltrace2 run --component=A:src.plug.my-src \
                  --component=B:sink.plug.my-sink \
                  --connect=A:B
----

Possible resulting graph:

----
+-----------------+    +-------------------+
| src.plug.my-src |    | sink.plug.my-sink |
|       [A]       |    |         [B]       |
|                 |    |                   |
|             out @--->@ in                |
+-----------------+    +-------------------+
----
====

.Use the opt:--params option to set the current component's initialization parameters.
====
In this example, the opt:--params option only applies to component
`the-source`.

[role="term"]
----
$ babeltrace2 run --component=the-source:src.my-plugin.my-src \
                  --params=offset=123,flag=true \
                  --component=the-sink:sink.my-plugin.my-sink \
                  --connect=the-source:the-sink
----
====

.Use the opt:--base-params and opt:--reset-base-params options to set and reset the current base initialization parameters.
====
In this example, the effective initialization parameters of the
created components are:

Component `A`::
    `offset=1203, flag=false`

Component `B`::
    `offset=1203, flag=true, type=event`

Component `C`::
    `ratio=0.25`

[role="term"]
----
$ babeltrace2 run --base-params=offset=1203,flag=false \
                  --component=A:src.plugin.compcls \
                  --component=B:flt.plugin.compcls \
                  --params=flag=true,type=event \
                  --reset-base-params \
                  --component=C:sink.plugin.compcls \
                  --params=ratio=0.25 \
                  --connect=A:B --connect=B:C
----
====

.Specify a component connection fallback rule.
====
In this example, any `A` output port of which the name starts with
`foo` is connected to a `B` input port of which the name starts with
`nin`. Any other `A` output port is connected to a `B` input port of
which the name starts with `oth`.

The order of the opt:--connect options is important here: the opposite
order would create a system in which the first rule is always satisfied,
and _any_ `A` output port, whatever its name, would be connected to a
`B` input port with a name that starts with `oth`.

[role="term"]
----
$ babeltrace2 run --component=A:src.plug.my-src \
                  --component=B:sink.plug.my-sink \
                  --connect='A.foo*:B:nin*' --connect='A:B.oth*'
----

Possible resulting graph:

----
+-----------------+    +-------------------+
| src.plug.my-src |    | sink.plug.my-sink |
|       [A]       |    |        [B]        |
|                 |    |                   |
|            foot @--->@ nine              |
|         foodies @--->@ ninja             |
|       some-port @--->@ othello           |
|           hello @--->@ other             |
+-----------------+    +-------------------+
----
====


include::common-cli-env.txt[]


include::common-cli-files.txt[]


include::common-cmd-footer.txt[]


== SEE ALSO

man:babeltrace2-intro(7),
man:babeltrace2(1),
man:babeltrace2-convert(1)
