1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 GETLOG_H 17 #define GETLOG_H 18 #include "sp_profiler.h" 19 #include "sp_log.h" 20 #include <string> 21 #include <filesystem> 22 namespace OHOS { 23 namespace SmartPerf { 24 class GetLog : public SpProfiler { 25 public: 26 std::map<std::string, std::string> ItemData() override; GetInstance()27 static GetLog &GetInstance() 28 { 29 static GetLog instance; 30 return instance; 31 } 32 int LogFileSocketConnect(); 33 int SendLogFile(); 34 void SetLogFileSocketPort(int port); 35 int GetLogFileSocketPort() const; 36 void SetLogFileSocket(int socket); 37 int GetLogFileSocket() const; 38 39 private: GetLog()40 GetLog() {}; 41 GetLog(const GetLog &); 42 GetLog &operator = (const GetLog &); 43 void RemoveLogFile(); 44 void TarLogFile(); 45 void CreateDir(const std::string &dirPath); 46 void RemoveDirOrFile(const std::string &dirPath); 47 void CopyFiles(std::string cpStr); 48 void TarFiles(std::string tarStr); 49 int GetCurrentPath(char *currentPath); 50 void GetHilogInMemory(std::vector<std::filesystem::path> &fileList); 51 void GetHilogInData(std::vector<std::filesystem::path> &otherFiles, std::vector<std::filesystem::path> &logFiles); 52 void GenerateHilogFile(); 53 void GenerateDaemonLogFile(); 54 55 int logFileSocket = -1; 56 int logFileSocketPort = -1; 57 const std::string systemHilogFileDir = "/data/log/hilog/"; 58 const std::string hilogFileDir = LOG_FILE_DIR + "hilog/"; 59 const std::string daemonLogFileDir = LOG_FILE_DIR + "daemonLog/"; 60 const std::string logFilePath = LOG_FILE_DIR + "logfile.tar.gz"; 61 static const int logSocketBufferSize = 4096; 62 static const uintmax_t logMaxSize = 52428800; // 50MB = 50 * 1024 * 1024 63 uintmax_t currentLogSize = 0; 64 char logSocketBuffer[logSocketBufferSize] = {}; 65 }; 66 } 67 } 68 #endif // NETWORK_H 69