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 #ifndef EVENT_LOGGER_PEER_BINDER_LOG_CATCHER 16 #define EVENT_LOGGER_PEER_BINDER_LOG_CATCHER 17 #include <string> 18 #include <memory> 19 #include <vector> 20 21 #include "sys_event.h" 22 23 #include "event_log_catcher.h" 24 namespace OHOS { 25 namespace HiviewDFX { 26 class PeerBinderCatcher : public EventLogCatcher { 27 public: 28 explicit PeerBinderCatcher(); ~PeerBinderCatcher()29 ~PeerBinderCatcher() override{}; 30 bool Initialize(const std::string& strParam1, int pid, int layer) override; 31 int Catch(int fd) override; 32 void Init(std::shared_ptr<SysEvent> event, std::string filePath); SetBinderProcPath(std::string filePath)33 void SetBinderProcPath(std::string filePath) 34 { 35 binderProcPath_ = filePath; 36 }; 37 38 static const inline std::string LOGGER_EVENT_PEERBINDER = "PeerBinder"; 39 static const inline std::string LOGGER_BINDER_DEBUG_PROC_PATH = "/sys/kernel/debug/binder/proc/"; 40 static const inline std::string LOGGER_BINDER_TRACING_PROC_PATH = "/sys/kernel/tracing/binder/proc/"; 41 private: 42 struct BinderInfo { 43 int client; 44 int server; 45 unsigned long wait; 46 }; 47 48 enum { 49 LOGGER_BINDER_STACK_HEAD_TAIL = -2, 50 LOGGER_BINDER_STACK_ALL = -1, 51 LOGGER_BINDER_STACK_NONE = 0, 52 LOGGER_BINDER_STACK_ONE 53 }; 54 55 static constexpr int TRACE_THRESHOLD = 6; 56 static constexpr int PEER_TRACE_NUM = 3; 57 static constexpr int BINDER_TIMEOUT = 1; 58 59 int pid_ = 0; 60 int layer_; 61 std::shared_ptr<SysEvent> event_ = nullptr; 62 std::string binderProcPath_ = ""; 63 64 void SaveBinderTransactionInfo(int fd) const; 65 std::set<int> GetBinderPeerChainPids(int pid, int layer, int fd) const; 66 std::set<int> GetBinderPeerPids(int pid, long layer) const; 67 std::set<int> GetPeerBinderByLayer (int pid, int layer, 68 std::map<int, std::list<BinderInfo>> info, int fd) const; 69 std::map<int, std::list<BinderInfo>> BinderInfoParser(int pid) const; 70 std::string GetBinderProcPath() const; 71 void ParseBinderCallChain(int pid, std::map<int, std::list<BinderInfo>> info, 72 std::vector<int> path, std::map<int, bool> &visit, std::vector<std::vector<int>> &paths) const; 73 int GetMatchBinderPeerInfo(int &pid, int &tid, int &waitTime, std::string &matchLine) const; 74 }; 75 } // namespace HiviewDFX 76 } // namespace OHOS 77 #endif // EVENT_LOGGER_PEER_BINDER_LOG_CATCHER