This is an archive of the discontinued LLVM Phabricator instance.

[trace] Add the definition of a TraceExporter plugin
ClosedPublic

Authored by wallace on Jul 21 2021, 3:00 PM.

Details

Summary

Copying from the inline documentation:

Trace exporter plug-ins operate on traces, converting the trace data provided by an \a lldb_private::TraceCursor into a different format that can be digested by other tools, e.g. Chrome Trace Event Profiler.
Trace exporters are supposed to operate on an architecture-agnostic fashion, as a TraceCursor, which feeds the data, hides the actual trace technology being used.

I want to use this to make the code in https://reviews.llvm.org/D105741 a plug-in. I also imagine that there will be more and more exporters being implemented, as an exporter creates something useful out of trace data. And tbh I don't want to keep adding more stuff to the lldb/Target folder.

This is the minimal definition for a TraceExporter plugin. I plan to use this with the following commands:

  • thread trace export <plug-in name> [plug-in specific args]
    • This command would support autocompletion of plug-in names
  • thread trace export list
    • This command would list the available trace exporter plug-ins

I don't plan to create yet a "process trace export" because it's easier to start analyzing the trace of a given thread than of the entire process. When we need a process-level command, we can implement it.

I also don't plan to force each "export" command implementation to support multiple threads (for example, "thread trace start 1 2 3" or "thread trace start all" operate on many threads simultaneously). The reason is that the format used by the exporter might or might not support multiple threads, so I'm leaving this decision to each trace exporter plug-in.

Diff Detail

Event Timeline

wallace created this revision.Jul 21 2021, 3:00 PM
wallace requested review of this revision.Jul 21 2021, 3:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2021, 3:00 PM
clayborg requested changes to this revision.Jul 21 2021, 3:07 PM

Just switch to unique_ptr and this will be good to go.

lldb/include/lldb/lldb-forward.h
445

Make unique_ptr since the exporters will be short lived.

This revision now requires changes to proceed.Jul 21 2021, 3:07 PM

Lets go ahead and and the "thread trace export" command as part of this to show how this API will get used and function.

wallace updated this revision to Diff 361013.Jul 22 2021, 4:01 PM

I've added a basic implementation of a CTF exporter plugin that can be used by https://reviews.llvm.org/D105741

(lldb) help thread trace export ctf
Export a given thread's trace to Chrome Trace Format

Syntax: thread trace export ctf [<ctf-options>]

Command Options Usage:
  thread trace export ctf [-t <thread-index>]

       -t <thread-index> ( --tid <thread-index> )
            Export the trace for the specified thread index. Otherwise, the currently selected thread
            will be used.
clayborg accepted this revision.Jul 26 2021, 4:58 PM
This revision is now accepted and ready to land.Jul 26 2021, 4:58 PM
This revision was landed with ongoing or failed builds.Jul 26 2021, 6:02 PM
This revision was automatically updated to reflect the committed changes.