• 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 #include "hiperf_client.h"
26 namespace OHOS {
27 namespace HiviewDFX {
28 class PeerBinderCatcher : public EventLogCatcher {
29 public:
30     explicit PeerBinderCatcher();
~PeerBinderCatcher()31     ~PeerBinderCatcher() override{};
32     bool Initialize(const std::string& perfCmd, int layer, int pid) override;
33     int Catch(int fd) override;
34     void Init(std::shared_ptr<SysEvent> event, const std::string& filePath);
35 
36     static const inline std::string LOGGER_EVENT_PEERBINDER = "PeerBinder";
37     static const inline std::string LOGGER_BINDER_DEBUG_PROC_PATH = "/proc/transaction_proc";
38     static constexpr int BP_CMD_LAYER_INDEX = 1;
39     static constexpr int BP_CMD_PERF_TYPE_INDEX = 2;
40     static constexpr int PERF_LOG_EXPIRE_TIME = 60;
41     static constexpr size_t BP_CMD_SZ = 3;
42 
43 private:
44     struct BinderInfo {
45         int client;
46         int server;
47         int wait;
48     };
49     enum {
50         LOGGER_BINDER_STACK_ONE = 0,
51         LOGGER_BINDER_STACK_ALL = 1,
52     };
53 
54     int pid_ = 0;
55     int layer_ = 0;
56     std::string perfCmd_ = "";
57     std::string binderPath_ = LOGGER_BINDER_DEBUG_PROC_PATH;
58     std::shared_ptr<SysEvent> event_ = nullptr;
59     std::unique_ptr<Developtools::HiPerf::HiperfClient::Client> perfClient_ = nullptr;
60     std::map<int, std::list<PeerBinderCatcher::BinderInfo>> BinderInfoParser(std::ifstream& fin, int fd) const;
61     void ParseBinderCallChain(std::map<int, std::list<PeerBinderCatcher::BinderInfo>>& manager,
62     std::set<int>& pids, int pid) const;
63     std::set<int> GetBinderPeerPids(int fd) const;
64     void CatcherStacktrace(int fd, int pid) const;
65     void ForkToDumpHiperf(const std::set<int>& pids);
66     void DoExecHiperf(const std::string& fileName, const std::set<int>& pids);
67 };
68 } // namespace HiviewDFX
69 } // namespace OHOS
70 #endif // EVENT_LOGGER_PEER_BINDER_LOG_CATCHER