• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 DFX_PROCESS_H
17 #define DFX_PROCESS_H
18 
19 #include <cinttypes>
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include "dfx_maps.h"
25 #include "dfx_thread.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 struct DfxProcessInfo {
30     pid_t pid = 0;
31     pid_t nsPid = 0;
32     uid_t uid = 0;
33     std::string processName = "";
34 };
35 
36 class DfxProcess {
37 public:
38     static std::shared_ptr<DfxProcess> Create(pid_t pid, pid_t nsPid);
39     DfxProcess(pid_t pid, pid_t nsPid);
40     virtual ~DfxProcess() = default;
41     void Attach(bool hasKey = false);
42     void Detach();
43 
44     bool InitOtherThreads(bool attach = false);
45     std::vector<std::shared_ptr<DfxThread>> GetOtherThreads() const;
46     void ClearOtherThreads();
47     pid_t ChangeTid(pid_t tid, bool ns);
48 
49     void SetFatalMessage(const std::string &msg);
50     std::string GetFatalMessage() const;
51     void InitProcessMaps();
52     void SetMaps(std::shared_ptr<DfxElfMaps> maps);
53     std::shared_ptr<DfxElfMaps> GetMaps() const;
54 
55     DfxProcessInfo processInfo_;
56     pid_t recycleTid_ = 0;
57     std::shared_ptr<DfxThread> keyThread_ = nullptr;
58     std::shared_ptr<DfxThread> vmThread_ = nullptr;
59 private:
60     DfxProcess() = default;
61     void InitProcessInfo(pid_t pid, pid_t nsPid);
62 
63     std::string fatalMsg_ = "";
64     std::shared_ptr<DfxElfMaps> maps_;
65     std::vector<std::shared_ptr<DfxThread>> otherThreads_;
66     std::map<int, int> kvThreads_;
67 };
68 } // namespace HiviewDFX
69 } // namespace OHOS
70 #endif
71