1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BINDER_FILTER_H 17 #define BINDER_FILTER_H 18 19 #include <unordered_set> 20 #include "args_set.h" 21 #include "filter_base.h" 22 #include "trace_data_cache.h" 23 #include "trace_streamer_filters.h" 24 namespace SysTuning { 25 namespace TraceStreamer { 26 class BinderFilter : private FilterBase { 27 public: 28 BinderFilter(TraceDataCache*, const TraceStreamerFilters*); 29 BinderFilter(const BinderFilter&) = delete; 30 BinderFilter& operator=(const BinderFilter&) = delete; 31 ~BinderFilter() override; 32 33 public: 34 void SendTraction(int64_t ts, 35 uint32_t tid, 36 uint64_t transactionId, 37 int32_t destNode, 38 int32_t destTgid, 39 int32_t destTid, 40 bool isReply, 41 int32_t flags, 42 int32_t code); 43 void ReceiveTraction(int64_t ts, uint32_t pid, uint64_t transactionId); 44 void TransactionAllocBuf(int64_t ts, uint32_t pid, uint64_t dataSize, uint64_t offsetsSize); 45 void TractionLock(int64_t ts, uint32_t pid, const std::string& tag); 46 void TractionLocked(int64_t ts, uint32_t pid, const std::string& tag); 47 void TractionUnlock(int64_t ts, uint32_t pid, const std::string& tag); 48 bool IsAsync(int32_t flags) const; 49 void Clear(); 50 51 private: 52 std::string GetBinderFlagsDesc(uint32_t flag); IsValidUint32(uint32_t value)53 static bool IsValidUint32(uint32_t value) 54 { 55 return (value != INVALID_UINT32); 56 } 57 uint32_t noReturnMsgFlag_ = 0x01; 58 uint32_t rootObjectMsgFlag_ = 0x04; 59 uint32_t statusCodeMsgFlag_ = 0x08; 60 uint32_t acceptFdsMsgFlag_ = 0x10; 61 uint32_t noFlagsMsgFlag_ = 0; 62 const DataIndex binderCatalogId_ = traceDataCache_->GetDataIndex("binder"); 63 const DataIndex replyId_ = traceDataCache_->GetDataIndex("binder reply"); 64 const DataIndex isReplayId_ = traceDataCache_->GetDataIndex("reply transaction?"); 65 const DataIndex flagsId_ = traceDataCache_->GetDataIndex("flags"); 66 const DataIndex transSliceId_ = traceDataCache_->GetDataIndex("binder transaction"); 67 const DataIndex transId_ = traceDataCache_->GetDataIndex("transaction id"); 68 const DataIndex asyncRcvId_ = traceDataCache_->GetDataIndex("binder async rcv"); 69 const DataIndex codeId_ = traceDataCache_->GetDataIndex("code"); 70 const DataIndex callingTid_ = traceDataCache_->GetDataIndex("calling tid"); 71 const DataIndex destNodeId_ = traceDataCache_->GetDataIndex("destination node"); 72 const DataIndex destThreadId_ = traceDataCache_->GetDataIndex("destination thread"); 73 const DataIndex destThreadNameId_ = traceDataCache_->GetDataIndex("destination name"); 74 const DataIndex destSliceId_ = traceDataCache_->GetDataIndex("destination slice id"); 75 const DataIndex destProcessId_ = traceDataCache_->GetDataIndex("destination process"); 76 const DataIndex transAsyncId_ = traceDataCache_->GetDataIndex("binder transaction async"); 77 const DataIndex lockTryId_ = traceDataCache_->GetDataIndex("binder lock waiting"); 78 const DataIndex lockHoldId_ = traceDataCache_->GetDataIndex("binder lock held"); 79 const DataIndex dataSizeId_ = traceDataCache_->GetDataIndex("data size"); 80 const DataIndex dataOffsetSizeId_ = traceDataCache_->GetDataIndex("offsets size"); 81 const DataIndex nullStringId_ = traceDataCache_->GetDataIndex("null"); 82 std::unordered_map<uint64_t, int64_t> lastEventTs_ = {}; 83 std::unordered_set<uint64_t> transReplyWaitingReply_ = {}; 84 std::unordered_map<uint64_t, FilterId> transNeedReply_ = {}; 85 std::unordered_map<uint64_t, FilterId> transReplyFilter_ = {}; 86 std::unordered_map<uint64_t, ArgsSet> asyncBinderEvents_ = {}; 87 std::unordered_map<int32_t, std::string> binderFlagDescs_ = {}; 88 }; 89 } // namespace TraceStreamer 90 } // namespace SysTuning 91 92 #endif // BINDER_FILTER_H 93