1 /* 2 * Copyright (c) 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 16 #ifndef THERMAL_DFX_H 17 #define THERMAL_DFX_H 18 19 #include <atomic> 20 #include <fstream> 21 #include <map> 22 #include <memory> 23 #include <string> 24 #include <thread> 25 #include "thermal_hdf_config.h" 26 27 namespace OHOS { 28 namespace HDI { 29 namespace Thermal { 30 namespace V1_0 { 31 class ThermalDfx { 32 public: ThermalDfx()33 ThermalDfx() {} 34 ~ThermalDfx(); 35 36 int32_t Init(); 37 private: 38 void UpdateInterval(); 39 std::string CanonicalizeSpecPath(const char* src); 40 bool Compress(const std::string& dataFile, const std::string& destFile); 41 void GetTraceInfo(); 42 void StartThread(); 43 void CreateLogFile(); 44 void ProcessLogInfo(std::string& logFile, bool isEmpty); 45 void WriteToEmptyFile(std::ofstream& wStream, std::string& currentTime, uint32_t paramWidth); 46 void WriteToFile(std::ofstream& wStream, std::string& currentTime, uint32_t paramWidth); 47 void CompressFile(); 48 static void InfoChangedCallback(const char* key, const char* value, void* context); 49 bool PrepareWriteDfxLog(); 50 int32_t ParseValue(const std::string& path, std::string& value); 51 void LoopingThreadEntry(); 52 std::string GetFileNameIndex(const uint32_t index); 53 std::atomic_bool isRunning_ {true}; 54 std::unique_ptr<std::thread> logThread_ {nullptr}; 55 }; 56 } // V1_0 57 } // Thermal 58 } // HDI 59 } // OHOS 60 #endif // THERMAL_DFX_H 61