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::shared_ptr<DfxElfMaps> GetMaps() const; 51 std::vector<std::shared_ptr<DfxThread>> GetThreads() const; 52 53 void SetPid(pid_t pid); 54 void SetUid(uid_t uid); 55 void SetRecycleTid(pid_t nstid); 56 void SetNsPid(pid_t pid); 57 void SetProcessName(const std::string &processName); 58 void SetMaps(std::shared_ptr<DfxElfMaps> maps); 59 void SetThreads(const std::vector<std::shared_ptr<DfxThread>> &threads); 60 void Detach(); 61 62 private: 63 pid_t pid_ = 0; 64 pid_t nsPid_ = 0; 65 uid_t uid_ = 0; 66 pid_t recycleTid_ = 0; 67 bool isSignalDump_ = false; 68 std::string processName_; 69 std::shared_ptr<DfxElfMaps> maps_; 70 std::vector<std::shared_ptr<DfxThread>> threads_; 71 }; 72 } // namespace HiviewDFX 73 } // namespace OHOS 74 #endif 75