1 /* 2 * Copyright (c) 2025 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 FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_DUMP_TRACE_CONTROLLER_H 17 #define FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_DUMP_TRACE_CONTROLLER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <vector> 22 23 #include "trace_caller.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 struct CpuThresholdItem { 28 bool hasOverThreshold = false; 29 UCollect::TraceCaller caller; 30 uint32_t dumpTraceInterval = 0; 31 uint64_t lastDumpTraceTime = 0; 32 double cpuLoadThreshold = 0.0; 33 std::string processName; 34 }; 35 36 class DumpTraceController { 37 public: DumpTraceController(std::vector<CpuThresholdItem> cpuThresholdItems)38 DumpTraceController(std::vector<CpuThresholdItem> cpuThresholdItems) : cpuThresholdItems_(cpuThresholdItems) {} ~DumpTraceController()39 ~DumpTraceController() {} 40 void CheckAndDumpTrace(); 41 42 private: 43 bool IsTimeOver(const CpuThresholdItem& item); 44 bool IsCpuLoadBackToNormal(CpuThresholdItem& item); 45 void DumpTrace(CpuThresholdItem& item); 46 47 private: 48 std::vector<CpuThresholdItem> cpuThresholdItems_; 49 }; 50 } // namespace HiviewDFX 51 } // namespace OHOS 52 #endif // FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_DUMP_TRACE_CONTROLLER_H 53