• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void Clear();
49 private:
50     std::string GetBinderFlagsDesc(uint32_t flag);
IsValidUint32(uint32_t value)51     bool IsValidUint32(uint32_t value) const
52     {
53         return (value != INVALID_UINT32);
54     }
55     uint32_t noReturnMsgFlag_ = 0x01;
56     uint32_t rootObjectMsgFlag_ = 0x04;
57     uint32_t statusCodeMsgFlag_ = 0x08;
58     uint32_t acceptFdsMsgFlag_ = 0x10;
59     uint32_t noFlagsMsgFlag_ = 0;
60     const DataIndex binderCatalogId_ = traceDataCache_->GetDataIndex("binder");
61     const DataIndex replyId_ = traceDataCache_->GetDataIndex("binder reply");
62     const DataIndex isReplayId_ = traceDataCache_->GetDataIndex("reply transaction?");
63     const DataIndex flagsId_ = traceDataCache_->GetDataIndex("flags");
64     const DataIndex transSliceId_ = traceDataCache_->GetDataIndex("binder transaction");
65     const DataIndex transId_ = traceDataCache_->GetDataIndex("transaction id");
66     const DataIndex asyncRcvId_ = traceDataCache_->GetDataIndex("binder async rcv");
67     const DataIndex codeId_ = traceDataCache_->GetDataIndex("code");
68     const DataIndex callingTid_ = traceDataCache_->GetDataIndex("calling tid");
69     const DataIndex destNodeId_ = traceDataCache_->GetDataIndex("destination node");
70     const DataIndex destThreadId_ = traceDataCache_->GetDataIndex("destination thread");
71     const DataIndex destThreadNameId_ = traceDataCache_->GetDataIndex("destination name");
72     const DataIndex destSliceId_ = traceDataCache_->GetDataIndex("destination slice id");
73     const DataIndex destProcessId_ = traceDataCache_->GetDataIndex("destination process");
74     const DataIndex transAsyncId_ = traceDataCache_->GetDataIndex("binder transaction async");
75     const DataIndex lockTryId_ = traceDataCache_->GetDataIndex("binder lock waiting");
76     const DataIndex lockHoldId_ = traceDataCache_->GetDataIndex("binder lock held");
77     const DataIndex dataSizeId_ = traceDataCache_->GetDataIndex("data size");
78     const DataIndex dataOffsetSizeId_ = traceDataCache_->GetDataIndex("offsets size");
79     const DataIndex nullStringId_ = traceDataCache_->GetDataIndex("null");
80     std::unordered_map<uint64_t, int64_t> lastEventTs_ = {};
81     std::unordered_set<uint64_t> transReplyWaitingReply_ = {};
82     std::unordered_map<uint64_t, FilterId> transNeedReply_ = {};
83     std::unordered_map<uint64_t, FilterId> transReplyFilter_ = {};
84     std::unordered_map<uint64_t, ArgsSet> asyncBinderEvents_ = {};
85     std::unordered_map<int, std::string> binderFlagDescs_ = {};
86 };
87 } // namespace TraceStreamer
88 } // namespace SysTuning
89 
90 #endif // BINDER_FILTER_H
91