This is an archive of the discontinued LLVM Phabricator instance.

[trace][intelpt] Add task timer classes
ClosedPublic

Authored by wallace on Apr 7 2022, 8:43 PM.

Details

Summary

I'm adding two new classes that can be used to measure the duration of long
tasks as process and thread level, e.g. decoding, fetching data from
lldb-server, etc. In this first patch, I'm using it to measure the time it takes
to decode each thread, which is printed out with the dump info command. In a
later patch I'll start adding process-level tasks and I might move these
classes to the upper Trace level, instead of having them in the intel-pt
plugin. I might need to do that anyway in the future when we have to
measure HTR. For now, I want to keep the impact of this change minimal.

With it, I was able to generate the following info of a very big trace:

(lldb) thread trace dump info                                                                                                            Trace technology: intel-pt

thread #1: tid = 616081
  Total number of instructions: 9729366

  Memory usage:
    Raw trace size: 1024 KiB
    Total approximate memory usage (excluding raw trace): 123517.34 KiB
    Average memory usage per instruction (excluding raw trace): 13.00 bytes

  Timing:
    Decoding instructions: 1.62s

  Errors:
    Number of TSC decoding errors: 0

As seen above, it took 1.62 seconds to decode 9.7M instructions. This is great
news, as we don't need to do any optimization work in this area.

Diff Detail

Event Timeline

wallace created this revision.Apr 7 2022, 8:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 8:43 PM
Herald added a subscriber: mgorny. · View Herald Transcript
wallace requested review of this revision.Apr 7 2022, 8:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 8:43 PM
jj10306 added inline comments.Apr 12 2022, 7:43 AM
lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
243

nit: Do you need an explicit initialization?

lldb/source/Plugins/Trace/intel-pt/TaskTimer.cpp
17

Should this be named to better reflect what this function is doing? It seems that this function is "getting" the ThreadTaskTimer associated with the tid and creates it if one doesn't already exist.
Maybe something like GetThreadTaskTimer, TimerForThread, TimerByThread ?

lldb/source/Plugins/Trace/intel-pt/TaskTimer.h
58
jj10306 accepted this revision.Apr 12 2022, 7:46 AM
This revision is now accepted and ready to land.Apr 12 2022, 7:46 AM
wallace added inline comments.Apr 12 2022, 12:41 PM
lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
243

yes, otherwise m_total_decoding_time takes the value of now(). That's a little bit counterintuitive for me

lldb/source/Plugins/Trace/intel-pt/TaskTimer.h
58

DenseMaps can't hold strings, only const char * :(