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 HITRACE_DEFINE_H 17 #define HITRACE_DEFINE_H 18 19 #include <inttypes.h> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 namespace Hitrace { 26 constexpr int TRACE_FILE_LEN = 128; 27 28 enum TraceMode : uint8_t { 29 CLOSE = 0, 30 OPEN = 1 << 0, 31 RECORD = 1 << 1, 32 CACHE = 1 << 2, 33 }; 34 35 enum TraceDumpType : uint8_t { 36 TRACE_SNAPSHOT = 0, 37 TRACE_RECORDING = 1, 38 TRACE_CACHE = 2, 39 }; 40 41 enum TraceErrorCode : uint8_t { 42 SUCCESS = 0, 43 TRACE_NOT_SUPPORTED = 1, 44 TRACE_IS_OCCUPIED = 2, 45 TAG_ERROR = 3, 46 FILE_ERROR = 4, 47 WRITE_TRACE_INFO_ERROR = 5, 48 WRONG_TRACE_MODE = 6, 49 OUT_OF_TIME = 7, 50 FORK_ERROR = 8, 51 INVALID_MAX_DURATION = 9, 52 EPOLL_WAIT_ERROR = 10, 53 PIPE_CREATE_ERROR = 11, 54 ASYNC_DUMP = 12, 55 TRACE_TASK_SUBMIT_ERROR = 13, 56 TRACE_TASK_DUMP_TIMEOUT = 14, 57 UNSET = 255, 58 }; 59 60 struct TraceDumpRequest { 61 TraceDumpType type; 62 int fileSize; // bytes 63 bool limitFileSz; 64 uint64_t traceStartTime; 65 uint64_t traceEndTime; 66 uint64_t taskId; 67 }; 68 69 struct TraceRetInfo { 70 TraceErrorCode errorCode; 71 uint8_t mode = 0; 72 bool isOverflowControl = false; 73 std::vector<std::string> outputFiles; 74 int64_t fileSize = 0; 75 int32_t coverRatio = 0; 76 int32_t coverDuration = 0; 77 std::vector<std::string> tags; 78 }; 79 80 enum class TraceDumpStatus : uint8_t { 81 START = 0, 82 READ_DONE, 83 WAIT_WRITE, 84 WRITE_DONE, 85 FINISH 86 }; 87 88 struct TraceDumpTask { 89 uint64_t time = 0; 90 uint64_t traceStartTime = 0; 91 uint64_t traceEndTime = 0; 92 char outputFile[TRACE_FILE_LEN] = { 0 }; 93 int64_t fileSize = 0; 94 int64_t fileSizeLimit = 0; 95 bool hasSyncReturn = false; 96 TraceErrorCode code = TraceErrorCode::UNSET; 97 bool isFileSizeOverLimit = false; 98 TraceDumpStatus status = TraceDumpStatus::START; 99 }; 100 101 struct AgeingParam { 102 bool rootEnable = true; 103 int64_t fileNumberLimit = 0; 104 int64_t fileSizeKbLimit = 0; 105 }; 106 } // namespace Hitrace 107 } // namespace HiviewDFX 108 } // namespace OHOS 109 #endif // HITRACE_DEFINE_H