1 /* 2 * Copyright (c) 2021-2022 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 DFX_PROCESS_H 16 #define DFX_PROCESS_H 17 18 #include <cinttypes> 19 #include <memory> 20 #include <string> 21 22 #include "dfx_define.h" 23 #include "dfx_elf.h" 24 #include "dfx_maps.h" 25 #include "dfx_thread.h" 26 27 namespace OHOS { 28 namespace HiviewDFX { 29 class DfxProcess { 30 public: 31 DfxProcess() = default; 32 virtual ~DfxProcess() = default; 33 static std::shared_ptr<DfxProcess> CreateProcessWithKeyThread(pid_t pid, std::shared_ptr<DfxThread> keyThread); 34 bool InitProcessMaps(); 35 bool InitProcessThreads(std::shared_ptr<DfxThread> keyThread); 36 bool InitOtherThreads(bool attach = true); 37 void FillProcessName(); 38 void PrintProcessMapsByConfig(); 39 void PrintThreadsHeaderByConfig(); 40 void InsertThreadNode(pid_t tid, pid_t nsTid, bool attach = true); 41 42 void SetIsSignalDump(bool isSignalDump); 43 bool GetIsSignalDump() const; 44 pid_t GetPid() const; 45 uid_t GetUid() const; 46 pid_t GetNsPid() const; 47 bool GetNs() const; 48 int TidToNstid(const int tid, int& nstid); 49 std::string GetProcessName() const; 50 std::string GetFatalMessage() const; 51 std::shared_ptr<DfxElfMaps> GetMaps() const; 52 std::vector<std::shared_ptr<DfxThread>> GetThreads() const; 53 54 void SetPid(pid_t pid); 55 void SetUid(uid_t uid); 56 void SetRecycleTid(pid_t nstid); 57 void SetNsPid(pid_t pid); 58 void SetProcessName(const std::string &processName); 59 void SetFatalMessage(const std::string &msg); 60 void SetMaps(std::shared_ptr<DfxElfMaps> maps); 61 void SetThreads(const std::vector<std::shared_ptr<DfxThread>> &threads); 62 void Detach(); 63 64 private: 65 pid_t pid_ = 0; 66 pid_t nsPid_ = 0; 67 uid_t uid_ = 0; 68 pid_t recycleTid_ = 0; 69 bool isSignalDump_ = false; 70 std::string processName_ = ""; 71 std::string fatalMsg_ = ""; 72 std::shared_ptr<DfxElfMaps> maps_; 73 std::vector<std::shared_ptr<DfxThread>> threads_; 74 }; 75 } // namespace HiviewDFX 76 } // namespace OHOS 77 #endif 78