• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
19 
20 #include <stdint.h>
21 
22 #include "perfetto/base/flat_set.h"
23 #include "perfetto/ext/base/flat_hash_map.h"
24 #include "perfetto/ext/base/optional.h"
25 #include "src/trace_processor/importers/common/args_tracker.h"
26 #include "src/trace_processor/storage/trace_storage.h"
27 #include "src/trace_processor/types/destructible.h"
28 #include "src/trace_processor/types/trace_processor_context.h"
29 
30 namespace perfetto {
31 namespace trace_processor {
32 
33 class TraceProcessorContext;
34 
35 class BinderTracker : public Destructible {
36  public:
37   using SetArgsCallback = std::function<void(ArgsTracker::BoundInserter*)>;
38   // Declared public for testing only.
39   explicit BinderTracker(TraceProcessorContext*);
40   BinderTracker(const BinderTracker&) = delete;
41   BinderTracker& operator=(const BinderTracker&) = delete;
42   ~BinderTracker() override;
GetOrCreate(TraceProcessorContext * context)43   static BinderTracker* GetOrCreate(TraceProcessorContext* context) {
44     if (!context->binder_tracker) {
45       context->binder_tracker.reset(new BinderTracker(context));
46     }
47     return static_cast<BinderTracker*>(context->binder_tracker.get());
48   }
49 
50   void Transaction(int64_t timestamp,
51                    uint32_t tid,
52                    int32_t transaction_id,
53                    int32_t dest_node,
54                    uint32_t dest_tgid,
55                    uint32_t dest_tid,
56                    bool is_reply,
57                    uint32_t flags,
58                    StringId code);
59   void Locked(int64_t timestamp, uint32_t pid);
60   void Lock(int64_t timestamp, uint32_t dest_pid);
61   void Unlock(int64_t timestamp, uint32_t pid);
62   void TransactionReceived(int64_t timestamp,
63                            uint32_t tid,
64                            int32_t transaction_id);
65   void TransactionAllocBuf(int64_t timestamp,
66                            uint32_t pid,
67                            uint64_t data_size,
68                            uint64_t offsets_size);
69 
70  private:
71   struct OutstandingTransaction {
72     bool is_reply = false;
73     bool is_oneway = false;
74     SetArgsCallback args_inserter;
75     base::Optional<TrackId> send_track_id;
76     base::Optional<SliceId> send_slice_id;
77   };
78 
79   TraceProcessorContext* const context_;
80 
81   base::FlatHashMap<int32_t, OutstandingTransaction> outstanding_transactions_;
82 
83   base::FlatHashMap<uint32_t, int64_t> attempt_lock_;
84   base::FlatHashMap<uint32_t, int64_t> lock_acquired_;
85 
86   const StringId binder_category_id_;
87   const StringId lock_waiting_id_;
88   const StringId lock_held_id_;
89   const StringId transaction_slice_id_;
90   const StringId transaction_async_id_;
91   const StringId reply_id_;
92   const StringId async_rcv_id_;
93   const StringId transaction_id_;
94   const StringId dest_node_;
95   const StringId dest_process_;
96   const StringId dest_thread_;
97   const StringId dest_name_;
98   const StringId is_reply_;
99   const StringId flags_;
100   const StringId code_;
101   const StringId calling_tid_;
102   const StringId data_size_;
103   const StringId offsets_size_;
104 };
105 
106 }  // namespace trace_processor
107 }  // namespace perfetto
108 
109 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_
110