I have a trivially simple question that I could not find the answer yet.
Say, I have a shared library X that is used by 100 simultaneously running applications A0, A1, ... A99. I had instrumented my library and with LTTNG using "X-Provider" as the provider name. How can my user distinguish between X-Provider events that happen in A10 and A15?
With the
lttngcommand-line utility, add thevpidcontext field to be recorded to your event records, for example:This targets all the user space channels of the current recording session; you can of course select a specific recording session and/or channel (see lttng-add-context(1)).
You need to use this command before you start the tracers (
lttng start).All your event records will have a context field named
vpidwhich is the virtual IDs of the processes which emitted them.Now, you need to find a way to associate such VPIDs to instance IDs (A10, A15, etc.). You can do so with your own application-specific strategy, or you can simply record an initial event when starting the application which indicates the instance ID/name, for example:
Then, when reading the resulting trace(s), you can correlate the
x_provider:app_stateevent record info with the records of your library-emitted events. For example, using the Babeltrace 2 Python bindings:I didn't test the example above, but you get the gist.