This is an archive of the discontinued LLVM Phabricator instance.

[trace] [intel pt] Create a "thread trace dump stats" command
ClosedPublic

Authored by hanbingwang on Jul 9 2021, 11:13 AM.

Details

Summary

When the user types that command 'thread trace dump info' and there's a running Trace session in LLDB, a raw trace in bytes should be printed; the command 'thread trace dump info all' should print the info for all the threads.

Diff Detail

Event Timeline

hanbingwang created this revision.Jul 9 2021, 11:13 AM
hanbingwang requested review of this revision.Jul 9 2021, 11:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2021, 11:13 AM
wallace retitled this revision from Create "thread trace dump stats" command to [trace] [intel pt] Create a "thread trace dump stats" command.Jul 13 2021, 10:26 AM
wallace added inline comments.Jul 13 2021, 10:31 AM
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

the presentation of this line could be better. Something like this would look nicer

thread 1: tid = 123123
  
  - Tracing technology: Intel PT
  - Raw trace size: 1231232 bytes
clayborg added inline comments.Jul 13 2021, 12:02 PM
lldb/include/lldb/Target/Trace.h
155

Are any statistics being dumped here? Maybe DumpTraceSummary(...) or DumpTraceInfo(...) would be better?

lldb/source/Commands/CommandObjectThread.cpp
2206–2208

Since we are iterating on this new command, I am wondering if we should have just a "thread trace dump" command with options?

(lldb) thread trace dump --stats
(lldb) thread trace dump --instructions

This way the user could dump more than one thing at a time with a single command?:

(lldb) thread trace dump --stats --instructions

Just thinking out loud here, so no worries if you feel this is already correct and should stay this way

lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

The "Tracing technology: Intel PT" should probably come before any of the thread infos if it is added:

Tracing technology: Intel PT
thread 1: tid = 111, size = 0x1000
thread 2: tid = 222, size = 0x1000
wallace added inline comments.Jul 13 2021, 1:17 PM
lldb/source/Commands/CommandObjectThread.cpp
2206–2208

I think that's a bit too much for this patch, but I'll keep it in mind if we end up having more dumpers.

lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

That's a pretty good idea.

@hanbingwang , you can invoke trace_sp->GetPluginName() for getting the name of the tracing technology being used

wallace requested changes to this revision.Jul 15 2021, 10:22 AM
This revision now requires changes to proceed.Jul 15 2021, 10:22 AM
hanbingwang edited the summary of this revision. (Show Details)
  1. rename "thread trace dump stats" to "thread trace dump info"
  2. Additionally, print out the tracing plugin name.
hanbingwang marked 2 inline comments as done.Jul 16 2021, 10:33 AM
hanbingwang added inline comments.
lldb/include/lldb/Target/Trace.h
155

@clayborg Sorry I didn't turn on the notification! Just saw your comments yesterday.
I agree "DumpTraceInfo()" is a better name.

lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

Hi @wallace @clayborg,

I'm wondering how to let the string "Tracing technology: Intel PT" printed out exactly once, when there are more than one threads? It looks like that HandleOneThread() will be called multiple times, which will then call DumpTraceInfo() which does the printout.

It seems that it'll be easy to print the string if we know if a thread is the *first* to be handled. However the threads are not indexed though?

wallace added inline comments.Jul 16 2021, 7:21 PM
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

You need to override CommandObjectIterateOverThreads::DoExecute in your command object. Something like this (figure out the correct function names)

bool CommandObjectTraceDumpInfo::DoExecute(Args &command,
                                              CommandReturnObject &result) {
   Target &target = m_exe_ctx.GetTargetRef();
   result.GetOutput().Printf("trace technology: %s", target.GetTrace().GetPluginName().Data());
  
   return CommandObjectIterateOverThreads::DoExecute(command, result);
}

that way that piece of code is executed before iterating over the threads

hanbingwang marked an inline comment as done.

print out the tracing plugin name exactly once when there are one or more than one threads.

wallace added inline comments.Jul 19 2021, 5:00 PM
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
113

add an empty line before this to clearly separate the output of each thread

118

Add 2 empty spaces before the text to have some sort of indentation

hanbingwang updated this revision to Diff 359994.EditedJul 19 2021, 8:08 PM

add two spaces before the string "Raw trace size : xxx"; add new line between each thread.

hanbingwang updated this revision to Diff 360035.EditedJul 20 2021, 12:35 AM
hanbingwang edited the summary of this revision. (Show Details)
This comment has been deleted.
hanbingwang updated this revision to Diff 360037.EditedJul 20 2021, 12:42 AM
  • create a "thread trace dump info" command.
  • the string "Trace technology: xxx" should be only printed out once when there are more than one thread.
  • add two spaces before the string "Raw trace size : xxx"; add new line between each thread.
wallace accepted this revision.Jul 20 2021, 9:31 AM
This revision is now accepted and ready to land.Jul 20 2021, 9:31 AM
JDevlieghere added inline comments.Jul 20 2021, 10:09 AM
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
125–126

No else after return. Seems like a good candidate for a ternary operator.

This revision was landed with ongoing or failed builds.Jul 21 2021, 9:59 AM
This revision was automatically updated to reflect the committed changes.