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 #include <unordered_map> 22 #include <unordered_set> 23 24 #include "src/trace_processor/importers/common/args_tracker.h" 25 #include "src/trace_processor/storage/trace_storage.h" 26 #include "src/trace_processor/types/destructible.h" 27 #include "src/trace_processor/types/trace_processor_context.h" 28 29 namespace perfetto { 30 namespace trace_processor { 31 32 class TraceProcessorContext; 33 34 class BinderTracker : public Destructible { 35 public: 36 using SetArgsCallback = std::function<void(ArgsTracker::BoundInserter*)>; 37 // Declared public for testing only. 38 explicit BinderTracker(TraceProcessorContext*); 39 BinderTracker(const BinderTracker&) = delete; 40 BinderTracker& operator=(const BinderTracker&) = delete; 41 ~BinderTracker() override; GetOrCreate(TraceProcessorContext * context)42 static BinderTracker* GetOrCreate(TraceProcessorContext* context) { 43 if (!context->binder_tracker) { 44 context->binder_tracker.reset(new BinderTracker(context)); 45 } 46 return static_cast<BinderTracker*>(context->binder_tracker.get()); 47 } 48 49 void Transaction(int64_t timestamp, 50 uint32_t tid, 51 int32_t transaction_id, 52 int32_t dest_node, 53 int32_t dest_tgid, 54 int32_t dest_tid, 55 bool is_reply, 56 uint32_t flags, 57 StringId code); 58 void Locked(int64_t timestamp, uint32_t pid); 59 void Lock(int64_t timestamp, uint32_t dest_pid); 60 void Unlock(int64_t timestamp, uint32_t pid); 61 void TransactionReceived(int64_t timestamp, 62 uint32_t tid, 63 int32_t transaction_id); 64 void TransactionAllocBuf(int64_t timestamp, 65 uint32_t pid, 66 uint64_t data_size, 67 uint64_t offsets_size); 68 69 private: 70 TraceProcessorContext* const context_; 71 std::unordered_set<int32_t> awaiting_rcv_for_reply_; 72 73 std::unordered_map<int32_t, TrackId> transaction_await_rcv; 74 std::unordered_map<int32_t, SetArgsCallback> awaiting_async_rcv_; 75 76 std::unordered_map<uint32_t, int64_t> attempt_lock_; 77 78 std::unordered_map<uint32_t, int64_t> lock_acquired_; 79 80 const StringId binder_category_id_; 81 const StringId lock_waiting_id_; 82 const StringId lock_held_id_; 83 const StringId transaction_slice_id_; 84 const StringId transaction_async_id_; 85 const StringId reply_id_; 86 const StringId async_rcv_id_; 87 const StringId transaction_id_; 88 const StringId dest_node_; 89 const StringId dest_process_; 90 const StringId dest_thread_; 91 const StringId dest_name_; 92 const StringId is_reply_; 93 const StringId flags_; 94 const StringId code_; 95 const StringId calling_tid_; 96 const StringId dest_slice_id_; 97 const StringId data_size_; 98 const StringId offsets_size_; 99 }; 100 101 } // namespace trace_processor 102 } // namespace perfetto 103 104 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_BINDER_TRACKER_H_ 105