1 /* 2 * Copyright (c) 2022-2023 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 26 #include "nocopyable.h" 27 #include "thermal_hdf_config.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace Thermal { 32 namespace V1_1 { 33 class ThermalDfx : public NoCopyable { 34 public: 35 ThermalDfx(); 36 ~ThermalDfx(); 37 38 void Init(); 39 void DoWork(); 40 uint32_t GetInterval(); 41 static ThermalDfx& GetInstance(); 42 static void DestroyInstance(); 43 44 private: 45 std::string CanonicalizeSpecPath(const char* src); 46 bool Compress(const std::string& dataFile, const std::string& destFile); 47 void CreateLogFile(); 48 void ProcessLogInfo(std::string& logFile, bool isEmpty); 49 void WriteToEmptyFile(std::ofstream& wStream, std::string& currentTime); 50 void WriteToFile(std::ofstream& wStream, std::string& currentTime); 51 void CompressFile(); 52 bool PrepareWriteDfxLog(); 53 std::string GetFileNameIndex(const uint32_t index); 54 int32_t GetIntParameter(const std::string& key, const int32_t def, const int32_t minValue); 55 bool GetBoolParameter(const std::string& key, const bool def); 56 void WidthWatchCallback(const std::string& value); 57 void IntervalWatchCallback(const std::string& value); 58 void EnableWatchCallback(const std::string& value); 59 static void InfoChangedCallback(const char* key, const char* value, void* context); 60 61 std::atomic_uint8_t width_; 62 std::atomic_uint32_t interval_; 63 std::atomic_bool enable_; 64 static std::mutex mutexInstance_; 65 static std::shared_ptr<ThermalDfx> instance_; 66 }; 67 } // V1_1 68 } // Thermal 69 } // HDI 70 } // OHOS 71 #endif // THERMAL_DFX_H 72