[Lldb-commits] [PATCH] D106328: [trace][intel pt] Add TSC timestamps

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 19 19:15:57 PDT 2021


wallace created this revision.
Herald added a subscriber: dang.
wallace updated this revision to Diff 359972.
wallace added a comment.
wallace updated this revision to Diff 359973.
wallace retitled this revision from "[intel pt] Add TSC timestamps" to "[trace][intel pt] Add TSC timestamps".
wallace edited the summary of this revision.
wallace added a reviewer: clayborg.
Herald added a subscriber: pengfei.
wallace published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

nits


wallace added a comment.

nits


I've just added the GetTimestampCounter method to Trace.h, which returns an Optional of a timestamp counter. Major CPU architectures support timestamp counters, which fortunately are invariant in modern chips (i.e. they are synchronized between logical CPUs and increase at a constant rate). This helps with having accurate timestamps even when the the thread is jumping around CPUs.

A followup diff would be to add a GetRealTime method, which would ask the trace plugin to convert a TSC to any of ms/ns/us or just to return the real time if available in the actual trace.

Tools could be built upon any of those two APIs, being GetTimestampCounter way more accurate in terms of keeping relative times.

I also implemented the specific bits for Intel PT. Now the "trace start" command accepts two params: --tsc which enables the generation of timestamp counters, and --psb_period, which is the simplest way to tweak how often these timestamps are generated. There are other ways to increase the resolution of timestamps: CYC and MTC packets, but that can be left for a follow up diff to keep this one short.

  wallace at devbig418 ~/llvm-sand/build/Release/fbcode-x86_64/toolchain ▶ ./bin/lldb ~/a.out 
  (lldb) target create "/home/wallace/a.out"
  Current executable set to '/home/wallace/a.out' (x86_64).
  (lldb) b main
  Breakpoint 1: where = a.out`main + 9 at main.cpp:6:15, address = 0x0000000000400c5f
  (lldb) r
  Process 1130363 launched: '/home/wallace/a.out' (x86_64)
  Process 1130363 stopped
  * thread #1, name = 'a.out', stop reason = breakpoint 1.1
      frame #0: 0x0000000000400c5f a.out`main at main.cpp:6:15
     3    using namespace std;
     4   
     5    int main() {
  -> 6      vector<int> s;
     7      s.push_back(1);
     8      s.push_back(2);
     9      cout << s.size() << endl;
  (lldb) thread trace start --tsc
  (lldb) n
  Process 1130363 stopped
  * thread #1, name = 'a.out', stop reason = step over
      frame #0: 0x0000000000400c6b a.out`main at main.cpp:7:15
     4   
     5    int main() {
     6      vector<int> s;
  -> 7      s.push_back(1);
     8      s.push_back(2);
     9      cout << s.size() << endl;
     10     int x = 1;
  (lldb) thread trace dump instructions --tsc -f
  thread #1: tid = 1130363
    a.out`main + 9 at main.cpp:6:15
      [ 0] [tsc=0x005a8eadd08764ba] 0x0000000000400c5f    leaq   -0x30(%rbp), %rax
      [ 1] [tsc=0x005a8eadd09356a8] 0x0000000000400c63    movq   %rax, %rdi
      [ 2] [tsc=0x005a8eadd09356a8] 0x0000000000400c66    callq  0x400d9c                  ; std::vector<int, std::allocator<int> >::vector at stl_vector.h:391:7
    ...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106328

Files:
  lldb/docs/lldb-gdb-remote.txt
  lldb/include/lldb/Target/TraceCursor.h
  lldb/include/lldb/Target/TraceInstructionDumper.h
  lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Process/Linux/IntelPTManager.cpp
  lldb/source/Plugins/Process/Linux/IntelPTManager.h
  lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTConstants.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTOptions.td
  lldb/source/Target/TraceInstructionDumper.cpp
  lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106328.359973.patch
Type: text/x-patch
Size: 38089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210720/58b7baec/attachment-0001.bin>


More information about the lldb-commits mailing list