3.5.2.2. Collecting and viewing a userspace trace on the target (inside a shell)

For LTTng userspace tracing, you need to have a properly instrumented userspace program. For this example, we'll use the 'hello' test program generated by the lttng-ust build.

The 'hello' test program isn't installed on the rootfs by the lttng-ust build, so we need to copy it over manually. First cd into the build directory that contains the hello executable:

     $ cd build/tmp/work/core2_32-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs
                

Copy that over to the target machine:

     $ scp hello root@192.168.1.20:
                

You now have the instrumented lttng 'hello world' test program on the target, ready to test.

First, from the host, ssh to the target:

     $ ssh -l root 192.168.1.47
     The authenticity of host '192.168.1.47 (192.168.1.47)' can't be established.
     RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.
     Are you sure you want to continue connecting (yes/no)? yes
     Warning: Permanently added '192.168.1.47' (RSA) to the list of known hosts.
     root@192.168.1.47's password:
                

Once on the target, use these steps to create a trace:

     root@crownbay:~# lttng create
     Session auto-20190303-021943 created.
     Traces will be written in /home/root/lttng-traces/auto-20190303-021943
                

Enable the events you want to trace (in this case all userspace events):

     root@crownbay:~# lttng enable-event --userspace --all
     All UST events are enabled in channel channel0
                

Start the trace:

     root@crownbay:~# lttng start
     Tracing started for session auto-20190303-021943
                

Run the instrumented hello world program:

     root@crownbay:~# ./hello
     Hello, World!
     Tracing...  done.
                

And then stop the trace after awhile or after running a particular workload that you want to trace:

     root@crownbay:~# lttng stop
     Tracing stopped for session auto-20190303-021943
                

You can now view the trace in text form on the target:

     root@crownbay:~# lttng view
     [02:31:14.906146544] (+?.?????????) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 0, intfield2 = 0x0, longfield = 0, netintfield = 0, netintfieldhex = 0x0, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
     [02:31:14.906170360] (+0.000023816) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 1, intfield2 = 0x1, longfield = 1, netintfield = 1, netintfieldhex = 0x1, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
     [02:31:14.906183140] (+0.000012780) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 2, intfield2 = 0x2, longfield = 2, netintfield = 2, netintfieldhex = 0x2, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
     [02:31:14.906194385] (+0.000011245) hello:1424 ust_tests_hello:tptest: { cpu_id = 1 }, { intfield = 3, intfield2 = 0x3, longfield = 3, netintfield = 3, netintfieldhex = 0x3, arrfield1 = [ [0] = 1, [1] = 2, [2] = 3 ], arrfield2 = "test", _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = "test", stringfield = "test", floatfield = 2222, doublefield = 2, boolfield = 1 }
     .
     .
     .
                

You can now safely destroy the trace session (note that this doesn't delete the trace - it's still there in ~/lttng-traces):

     root@crownbay:~# lttng destroy
     Session auto-20190303-021943 destroyed at /home/root