wallace created this revision.
wallace added reviewers: clayborg, labath, kusmour.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
wallace requested review of this revision.

Depends on D84791 <https://reviews.llvm.org/D84791>.
The existing way to configure Intel PT tracing through the Python API isn't
trivial. Thus, I'm creating a helper method GetDefaultTraceOptions, which
creates an SBTraceOptions object ready to be used for tracing. This simplifies
the Python code and even some existing C++ code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84810

Files:
  lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py
  lldb/tools/intel-features/intel-pt/Decoder.cpp
  lldb/tools/intel-features/intel-pt/Decoder.h
  lldb/tools/intel-features/intel-pt/PTDecoder.cpp
  lldb/tools/intel-features/intel-pt/PTDecoder.h
  lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp

Index: lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp
===================================================================
--- lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp
+++ lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp
@@ -136,8 +136,9 @@
       return false;
 
     // Default initialize API's arguments
-    lldb::SBTraceOptions lldb_SBTraceOptions;
-    uint32_t trace_buffer_size = m_default_trace_buff_size;
+    lldb::SBTraceOptions lldb_SBTraceOptions =
+        ptdecoder::PTDecoder::GetDefaultTraceOptions();
+    uint32_t trace_buffer_size = lldb_SBTraceOptions.getTraceBufferSize();
     lldb::tid_t thread_id;
 
     // Parse Command line options
@@ -169,22 +170,11 @@
       trace_buffer_size = m_max_trace_buff_size;
 
     // Set API's arguments with parsed values
-    lldb_SBTraceOptions.setType(lldb::TraceType::eTraceTypeProcessorTrace);
     lldb_SBTraceOptions.setTraceBufferSize(trace_buffer_size);
-    lldb_SBTraceOptions.setMetaDataBufferSize(0);
     lldb_SBTraceOptions.setThreadID(thread_id);
-    lldb::SBStream sb_stream;
-    sb_stream.Printf("{\"trace-tech\":\"intel-pt\"}");
-    lldb::SBStructuredData custom_params;
-    lldb::SBError error = custom_params.SetFromJSON(sb_stream);
-    if (!error.Success()) {
-      result.Printf("error: %s\n", error.GetCString());
-      result.SetStatus(lldb::eReturnStatusFailed);
-      return false;
-    }
-    lldb_SBTraceOptions.setTraceParams(custom_params);
 
     // Start trace
+    lldb::SBError error;
     pt_decoder_sp->StartProcessorTrace(process, lldb_SBTraceOptions, error);
     if (!error.Success()) {
       result.Printf("error: %s\n", error.GetCString());
@@ -198,7 +188,6 @@
 private:
   std::shared_ptr<ptdecoder::PTDecoder> pt_decoder_sp;
   const uint32_t m_max_trace_buff_size = 0x3fff;
-  const uint32_t m_default_trace_buff_size = 4096;
 };
 
 class ProcessorTraceInfo : public lldb::SBCommandPluginInterface {
Index: lldb/tools/intel-features/intel-pt/PTDecoder.h
===================================================================
--- lldb/tools/intel-features/intel-pt/PTDecoder.h
+++ lldb/tools/intel-features/intel-pt/PTDecoder.h
@@ -262,6 +262,19 @@
   void GetProcessorTraceInfo(lldb::SBProcess &sbprocess, lldb::tid_t tid,
                              PTTraceOptions &options, lldb::SBError &sberror);
 
+  /// Get an instance of an \a lldb::SBTraceOptions object with a default
+  /// configuration for tracing with Intel(R) Processor Trace. This object
+  /// is ready to be passed as argument to \a PTDecoder::StartProcessorTrace.
+  ///
+  /// The default configuration sets 4096 bytes as trace buffer size per thread.
+  /// Besides, this configuration traces all the running threads of the target
+  /// process.
+  ///
+  /// \return
+  ///     An \a lldb::SBTraceOptions object with a default tracing
+  ///     configuration.
+  static lldb::SBTraceOptions GetDefaultTraceOptions();
+
 private:
   std::shared_ptr<ptdecoder_private::Decoder> m_opaque_sp;
 };
Index: lldb/tools/intel-features/intel-pt/PTDecoder.cpp
===================================================================
--- lldb/tools/intel-features/intel-pt/PTDecoder.cpp
+++ lldb/tools/intel-features/intel-pt/PTDecoder.cpp
@@ -147,3 +147,7 @@
 
   options.SetSP(trace_options_ptr);
 }
+
+lldb::SBTraceOptions PTDecoder::GetDefaultTraceOptions() {
+  return Decoder::GetDefaultTraceOptions();
+}
Index: lldb/tools/intel-features/intel-pt/Decoder.h
===================================================================
--- lldb/tools/intel-features/intel-pt/Decoder.h
+++ lldb/tools/intel-features/intel-pt/Decoder.h
@@ -171,6 +171,8 @@
   void GetProcessorTraceInfo(lldb::SBProcess &sbprocess, lldb::tid_t tid,
                              TraceOptions &traceinfo, lldb::SBError &sberror);
 
+  static lldb::SBTraceOptions GetDefaultTraceOptions();
+
 private:
   class ThreadTraceInfo;
   typedef std::vector<uint8_t> Buffer;
Index: lldb/tools/intel-features/intel-pt/Decoder.cpp
===================================================================
--- lldb/tools/intel-features/intel-pt/Decoder.cpp
+++ lldb/tools/intel-features/intel-pt/Decoder.cpp
@@ -958,3 +958,19 @@
     return;
   }
 }
+
+lldb::SBTraceOptions Decoder::GetDefaultTraceOptions() {
+  lldb::SBTraceOptions trace_opts;
+  trace_opts.setThreadID(LLDB_INVALID_THREAD_ID);
+  trace_opts.setType(lldb::TraceType::eTraceTypeProcessorTrace);
+  trace_opts.setTraceBufferSize(4096); // 1 page
+  trace_opts.setMetaDataBufferSize(0);
+
+  lldb::SBStream sb_stream;
+  sb_stream.Printf("{\"trace-tech\":\"intel-pt\"}");
+  lldb::SBStructuredData custom_params;
+  custom_params.SetFromJSON(sb_stream);
+  trace_opts.setTraceParams(custom_params);
+
+  return trace_opts;
+}
Index: lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py
===================================================================
--- lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py
+++ lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py
@@ -102,17 +102,8 @@
         tid = process.GetProcessID()
 
         # We configure the tracing options
-        trace_opts = lldb.SBTraceOptions()
+        trace_opts = lldbIntelFeatures.PTDecoder.GetDefaultTraceOptions()
         trace_opts.setThreadID(tid)
-        trace_opts.setType(lldb.eTraceTypeProcessorTrace)
-        trace_opts.setMetaDataBufferSize(0)
-        trace_opts.setTraceBufferSize(4096)
-
-        stream = lldb.SBStream()
-        stream.Print('{"trace-tech":"intel-pt"}')
-        custom_params = lldb.SBStructuredData()
-        self.assertSuccess(custom_params.SetFromJSON(stream))
-        trace_opts.setTraceParams(custom_params)
 
         # We start tracing
         error = lldb.SBError()
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D... walter erquinigo via Phabricator via lldb-commits

Reply via email to