1 /* 2 * Copyright (c) 2024 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 #include "hidebug_app_thread_cpu.h" 17 18 #include <unistd.h> 19 20 #include "hilog/log.h" 21 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 #undef LOG_DOMAIN 26 #define LOG_DOMAIN 0xD002D0A 27 #undef LOG_TAG 28 #define LOG_TAG "HiDebug_App_Thread_Cpu" 29 HidebugAppThreadCpu()30HidebugAppThreadCpu::HidebugAppThreadCpu() 31 { 32 InitThreadCpuCollector(); 33 } 34 InitThreadCpuCollector()35void HidebugAppThreadCpu::InitThreadCpuCollector() 36 { 37 int32_t pid = getprocpid(); 38 threadStatInfoCollector_ = UCollectUtil::ThreadCpuCollector::Create(pid); 39 if (!threadStatInfoCollector_) { 40 HILOG_ERROR(LOG_CORE, "InitThreadCpuCollector fail, CreateThreadStatInfoCollector fail!"); 41 } 42 } 43 CollectThreadStatInfos() const44CollectResult<std::vector<ThreadCpuStatInfo>> HidebugAppThreadCpu::CollectThreadStatInfos() const 45 { 46 if (!threadStatInfoCollector_) { 47 CollectResult<std::vector<ThreadCpuStatInfo>> threadCollectResult; 48 return threadCollectResult; 49 } 50 return threadStatInfoCollector_->CollectThreadStatInfos(true); 51 } 52 53 } 54 }