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 #ifndef TRACE_FILE_UTILS_H 17 #define TRACE_FILE_UTILS_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 namespace Hitrace { 26 enum TRACE_TYPE : uint8_t { 27 TRACE_SNAPSHOT = 0, 28 TRACE_RECORDING = 1, 29 TRACE_CACHE = 2, 30 }; 31 struct FileWithTime { 32 std::string filename; 33 time_t ctime; 34 uint64_t fileSize; 35 }; 36 37 struct TraceFileInfo { 38 std::string filename; 39 uint64_t traceStartTime; 40 uint64_t traceEndTime; 41 uint64_t fileSize; 42 }; 43 44 bool RemoveFile(const std::string& fileName); 45 std::string GenerateTraceFileName(TRACE_TYPE traceType); 46 void DelSnapshotTraceFile(const int& keepFileCount, std::vector<TraceFileInfo>& traceFileVec); 47 void DelOldRecordTraceFile(const int& fileLimit); 48 void ClearOldTraceFile(std::vector<std::string>& fileLists, const int& fileLimit); 49 void DelSavedEventsFormat(); 50 void ClearCacheTraceFileByDuration(std::vector<TraceFileInfo>& cacheFileVec); 51 void ClearCacheTraceFileBySize(std::vector<TraceFileInfo>& cacheFileVec, const uint64_t& fileSizeLimit); 52 bool GetFileSize(const std::string& filePath, uint64_t& fileSize); 53 bool ConvertPageTraceTimeToUtTime(const uint64_t& pageTraceTime, time_t& utPageTraceTime); 54 bool RenameTraceFile(const std::string& fileName, std::string& newFileName, 55 const uint64_t& firstPageTraceTime, const uint64_t& lastPageTraceTime); 56 void RefreshTraceVec(std::vector<TraceFileInfo>& traceVec, const TRACE_TYPE traceType); 57 } // namespace HiTrace 58 } // namespace HiviewDFX 59 } // namespace OHOS 60 #endif // TRACE_FILE_UTILS_H