trace_processor: Move BinderTracker inside FtraceParser

Bug: 141459049
Change-Id: Ic732c2e58d8bd4ce9a3b51433a4c4e4e25981448
diff --git a/Android.bp b/Android.bp
index 378d257..bfdc493 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5768,7 +5768,6 @@
   name: "perfetto_src_trace_processor_storage_minimal",
   srcs: [
     "src/trace_processor/args_tracker.cc",
-    "src/trace_processor/binder_tracker.cc",
     "src/trace_processor/clock_tracker.cc",
     "src/trace_processor/destructible.cc",
     "src/trace_processor/event_tracker.cc",
@@ -5776,6 +5775,7 @@
     "src/trace_processor/ftrace_utils.cc",
     "src/trace_processor/gzip_trace_parser.cc",
     "src/trace_processor/heap_profile_tracker.cc",
+    "src/trace_processor/importers/ftrace/binder_tracker.cc",
     "src/trace_processor/importers/ftrace/ftrace_descriptors.cc",
     "src/trace_processor/importers/ftrace/ftrace_module.cc",
     "src/trace_processor/importers/ftrace/ftrace_module_impl.cc",
diff --git a/BUILD b/BUILD
index db049cd..5a2ff94 100644
--- a/BUILD
+++ b/BUILD
@@ -806,8 +806,6 @@
     srcs = [
         "src/trace_processor/args_tracker.cc",
         "src/trace_processor/args_tracker.h",
-        "src/trace_processor/binder_tracker.cc",
-        "src/trace_processor/binder_tracker.h",
         "src/trace_processor/chunked_trace_reader.h",
         "src/trace_processor/clock_tracker.cc",
         "src/trace_processor/clock_tracker.h",
@@ -823,6 +821,8 @@
         "src/trace_processor/gzip_trace_parser.h",
         "src/trace_processor/heap_profile_tracker.cc",
         "src/trace_processor/heap_profile_tracker.h",
+        "src/trace_processor/importers/ftrace/binder_tracker.cc",
+        "src/trace_processor/importers/ftrace/binder_tracker.h",
         "src/trace_processor/importers/ftrace/ftrace_descriptors.cc",
         "src/trace_processor/importers/ftrace/ftrace_descriptors.h",
         "src/trace_processor/importers/ftrace/ftrace_module.cc",
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index bf5f254..641ca40 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -78,8 +78,6 @@
   sources = [
     "args_tracker.cc",
     "args_tracker.h",
-    "binder_tracker.cc",
-    "binder_tracker.h",
     "chunked_trace_reader.h",
     "clock_tracker.cc",
     "clock_tracker.h",
@@ -185,6 +183,8 @@
   }
   if (enable_perfetto_trace_processor_ftrace) {
     sources += [
+      "importers/ftrace/binder_tracker.cc",
+      "importers/ftrace/binder_tracker.h",
       "importers/ftrace/ftrace_descriptors.cc",
       "importers/ftrace/ftrace_module_impl.cc",
       "importers/ftrace/ftrace_parser.cc",
diff --git a/src/trace_processor/binder_tracker.cc b/src/trace_processor/importers/ftrace/binder_tracker.cc
similarity index 95%
rename from src/trace_processor/binder_tracker.cc
rename to src/trace_processor/importers/ftrace/binder_tracker.cc
index 2bc3953..10bab08 100644
--- a/src/trace_processor/binder_tracker.cc
+++ b/src/trace_processor/importers/ftrace/binder_tracker.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "src/trace_processor/binder_tracker.h"
+#include "src/trace_processor/importers/ftrace/binder_tracker.h"
 
 #include "perfetto/base/compiler.h"
 
diff --git a/src/trace_processor/binder_tracker.h b/src/trace_processor/importers/ftrace/binder_tracker.h
similarity index 86%
rename from src/trace_processor/binder_tracker.h
rename to src/trace_processor/importers/ftrace/binder_tracker.h
index c3f1994..6b50fe2 100644
--- a/src/trace_processor/binder_tracker.h
+++ b/src/trace_processor/importers/ftrace/binder_tracker.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef SRC_TRACE_PROCESSOR_BINDER_TRACKER_H_
-#define SRC_TRACE_PROCESSOR_BINDER_TRACKER_H_
+#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
+#define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
 
 #include <stdint.h>
 
@@ -45,4 +45,4 @@
 }  // namespace trace_processor
 }  // namespace perfetto
 
-#endif  // SRC_TRACE_PROCESSOR_BINDER_TRACKER_H_
+#endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.cc b/src/trace_processor/importers/ftrace/ftrace_parser.cc
index 7462e58..4335a84 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.cc
@@ -19,7 +19,7 @@
 #include "perfetto/base/logging.h"
 #include "perfetto/protozero/proto_decoder.h"
 #include "src/trace_processor/args_tracker.h"
-#include "src/trace_processor/binder_tracker.h"
+#include "src/trace_processor/importers/ftrace/binder_tracker.h"
 #include "src/trace_processor/importers/systrace/systrace_parser.h"
 #include "src/trace_processor/process_tracker.h"
 #include "src/trace_processor/stats.h"
@@ -60,6 +60,7 @@
 
 FtraceParser::FtraceParser(TraceProcessorContext* context)
     : context_(context),
+      binder_tracker_(context),
       sched_wakeup_name_id_(context->storage->InternString("sched_wakeup")),
       sched_waking_name_id_(context->storage->InternString("sched_waking")),
       cpu_freq_name_id_(context->storage->InternString("cpufreq")),
@@ -770,7 +771,7 @@
                                           ConstBytes blob) {
   protos::pbzero::BinderTransactionFtraceEvent::Decoder evt(blob.data,
                                                             blob.size);
-  context_->binder_tracker->Transaction(timestamp, pid);
+  binder_tracker_.Transaction(timestamp, pid);
 }
 
 void FtraceParser::ParseBinderTransactionReceived(int64_t timestamp,
@@ -778,7 +779,7 @@
                                                   ConstBytes blob) {
   protos::pbzero::BinderTransactionReceivedFtraceEvent::Decoder evt(blob.data,
                                                                     blob.size);
-  context_->binder_tracker->TransactionReceived(timestamp, pid);
+  binder_tracker_.TransactionReceived(timestamp, pid);
 }
 
 void FtraceParser::ParseBinderTransactionAllocBuf(int64_t timestamp,
@@ -786,28 +787,28 @@
                                                   ConstBytes blob) {
   protos::pbzero::BinderTransactionAllocBufFtraceEvent::Decoder evt(blob.data,
                                                                     blob.size);
-  context_->binder_tracker->TransactionAllocBuf(timestamp, pid);
+  binder_tracker_.TransactionAllocBuf(timestamp, pid);
 }
 
 void FtraceParser::ParseBinderLocked(int64_t timestamp,
                                      uint32_t pid,
                                      ConstBytes blob) {
   protos::pbzero::BinderLockedFtraceEvent::Decoder evt(blob.data, blob.size);
-  context_->binder_tracker->Locked(timestamp, pid);
+  binder_tracker_.Locked(timestamp, pid);
 }
 
 void FtraceParser::ParseBinderLock(int64_t timestamp,
                                    uint32_t pid,
                                    ConstBytes blob) {
   protos::pbzero::BinderLockFtraceEvent::Decoder evt(blob.data, blob.size);
-  context_->binder_tracker->Lock(timestamp, pid);
+  binder_tracker_.Lock(timestamp, pid);
 }
 
 void FtraceParser::ParseBinderUnlock(int64_t timestamp,
                                      uint32_t pid,
                                      ConstBytes blob) {
   protos::pbzero::BinderUnlockFtraceEvent::Decoder evt(blob.data, blob.size);
-  context_->binder_tracker->Unlock(timestamp, pid);
+  binder_tracker_.Unlock(timestamp, pid);
 }
 
 }  // namespace trace_processor
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.h b/src/trace_processor/importers/ftrace/ftrace_parser.h
index 15bc2ef..6dfdfb7 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.h
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.h
@@ -19,6 +19,7 @@
 
 #include "perfetto/trace_processor/status.h"
 #include "src/trace_processor/event_tracker.h"
+#include "src/trace_processor/importers/ftrace/binder_tracker.h"
 #include "src/trace_processor/importers/ftrace/ftrace_descriptors.h"
 #include "src/trace_processor/importers/ftrace/sched_event_tracker.h"
 #include "src/trace_processor/timestamped_trace_piece.h"
@@ -94,6 +95,7 @@
                          protozero::ConstBytes);
 
   TraceProcessorContext* context_;
+  BinderTracker binder_tracker_;
 
   const StringId sched_wakeup_name_id_;
   const StringId sched_waking_name_id_;
diff --git a/src/trace_processor/trace_processor_context.cc b/src/trace_processor/trace_processor_context.cc
index 8c2b946..dbefd62 100644
--- a/src/trace_processor/trace_processor_context.cc
+++ b/src/trace_processor/trace_processor_context.cc
@@ -17,7 +17,6 @@
 #include "src/trace_processor/trace_processor_context.h"
 
 #include "src/trace_processor/args_tracker.h"
-#include "src/trace_processor/binder_tracker.h"
 #include "src/trace_processor/chunked_trace_reader.h"
 #include "src/trace_processor/clock_tracker.h"
 #include "src/trace_processor/event_tracker.h"
diff --git a/src/trace_processor/trace_processor_context.h b/src/trace_processor/trace_processor_context.h
index 3e7dc86..6d5b75c 100644
--- a/src/trace_processor/trace_processor_context.h
+++ b/src/trace_processor/trace_processor_context.h
@@ -28,7 +28,6 @@
 namespace trace_processor {
 
 class ArgsTracker;
-class BinderTracker;
 class ChunkedTraceReader;
 class ClockTracker;
 class EventTracker;
@@ -60,7 +59,6 @@
   std::unique_ptr<TraceSorter> sorter;
   std::unique_ptr<ChunkedTraceReader> chunk_reader;
   std::unique_ptr<HeapProfileTracker> heap_profile_tracker;
-  std::unique_ptr<BinderTracker> binder_tracker;
 
   // These fields are stored as pointers to Destructible objects rather than
   // their actual type (a subclass of Destructible), as the concrete subclass
diff --git a/src/trace_processor/trace_processor_storage_impl.cc b/src/trace_processor/trace_processor_storage_impl.cc
index 30d9405..46aefbf 100644
--- a/src/trace_processor/trace_processor_storage_impl.cc
+++ b/src/trace_processor/trace_processor_storage_impl.cc
@@ -18,7 +18,6 @@
 
 #include "perfetto/base/logging.h"
 #include "src/trace_processor/args_tracker.h"
-#include "src/trace_processor/binder_tracker.h"
 #include "src/trace_processor/clock_tracker.h"
 #include "src/trace_processor/event_tracker.h"
 #include "src/trace_processor/forwarding_trace_parser.h"
@@ -48,9 +47,6 @@
   context_.process_tracker.reset(new ProcessTracker(&context_));
   context_.clock_tracker.reset(new ClockTracker(&context_));
   context_.heap_profile_tracker.reset(new HeapProfileTracker(&context_));
-#if PERFETTO_BUILDFLAG(PERFETTO_TP_FTRACE)
-  context_.binder_tracker.reset(new BinderTracker(&context_));
-#endif  // PERFETTO_BUILDFLAG(PERFETTO_TP_FTRACE)
 
 #if PERFETTO_BUILDFLAG(PERFETTO_TP_FTRACE)
   context_.modules.emplace_back(new FtraceModuleImpl(&context_));