• 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 #ifndef EVENT_LOGGER_PEER_BINDER_LOG_CATCHER
16 #define EVENT_LOGGER_PEER_BINDER_LOG_CATCHER
17 #include <fstream>
18 #include <string>
19 #include <memory>
20 #include <vector>
21 
22 #include "sys_event.h"
23 
24 #include "event_log_catcher.h"
25 namespace OHOS {
26 namespace HiviewDFX {
27 class PeerBinderCatcher : public EventLogCatcher {
28 public:
29     explicit PeerBinderCatcher();
~PeerBinderCatcher()30     ~PeerBinderCatcher() override{};
31     bool Initialize(const std::string& strParam1, int pid, int layer) override;
32     int Catch(int fd) override;
33     void Init(std::shared_ptr<SysEvent> event, const std::string& filePath);
34 
35     static const inline std::string LOGGER_EVENT_PEERBINDER = "PeerBinder";
36     static const inline std::string LOGGER_BINDER_DEBUG_PROC_PATH = "/proc/transaction_proc";
37 private:
38     struct BinderInfo {
39         int client;
40         int server;
41         int wait;
42     };
43     enum {
44         LOGGER_BINDER_STACK_ONE = 0,
45         LOGGER_BINDER_STACK_ALL = 1,
46     };
47 
48     int pid_ = 0;
49     int layer_ = 0;
50     std::string binderPath_ = LOGGER_BINDER_DEBUG_PROC_PATH;
51     std::shared_ptr<SysEvent> event_ = nullptr;
52 
53     std::map<int, std::list<PeerBinderCatcher::BinderInfo>> BinderInfoParser(std::ifstream& fin, int fd) const;
54     void ParseBinderCallChain(std::map<int, std::list<PeerBinderCatcher::BinderInfo>>& manager,
55     std::set<int>& pids, int pid) const;
56     std::set<int> GetBinderPeerPids(int fd) const;
57     void CatcherStacktrace(int fd, int pid) const;
58 };
59 } // namespace HiviewDFX
60 } // namespace OHOS
61 #endif // EVENT_LOGGER_PEER_BINDER_LOG_CATCHER