1 /* 2 * Copyright (C) 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 HITRACE_DUMP_H 17 #define HITRACE_DUMP_H 18 19 #include <string> 20 #include <vector> 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 namespace Hitrace { 25 26 enum TraceErrorCode : uint8_t { 27 SUCCESS = 0, 28 TRACE_NOT_SUPPORTED = 1, 29 TRACE_IS_OCCUPIED = 2, 30 TAG_ERROR = 3, 31 FILE_ERROR = 4, 32 WRITE_TRACE_INFO_ERROR = 5, 33 CALL_ERROR = 6, 34 }; 35 36 enum TraceMode : uint8_t { 37 CLOSE = 0, 38 CMD_MODE = 1, 39 SERVICE_MODE = 2, 40 RECORDING_MODE = CMD_MODE, 41 SNAPSHOT_MODE = SERVICE_MODE, 42 }; 43 44 struct TraceRetInfo { 45 TraceErrorCode errorCode; 46 std::vector<std::string> outputFiles; 47 }; 48 49 #ifdef HITRACE_UNITTEST 50 void SetSysInitParamTags(uint64_t sysInitParamTags); 51 bool SetCheckParam(); 52 #endif 53 54 /** 55 * Get the current trace mode. 56 */ 57 TraceMode GetTraceMode(); 58 59 /** 60 * Set trace parameters based on args for CMD_MODE. 61 */ 62 TraceErrorCode OpenTrace(const std::string &args); 63 64 /** 65 * Set trace tags based on tagGroups for SERVICE_MODE. 66 */ 67 TraceErrorCode OpenTrace(const std::vector<std::string> &tagGroups); 68 69 /** 70 * Reading trace data once from ftrace ringbuffer in the kernel. 71 * Using child processes to process trace tasks. 72 */ 73 TraceRetInfo DumpTrace(); 74 75 /** 76 * Reading trace data once from ftrace ringbuffer in the kernel. 77 * Using child processes to process trace tasks. 78 * timeLimit: the maximum time(s) allowed for the trace task. 79 */ 80 TraceRetInfo DumpTrace(int timeLimit); 81 82 /** 83 * Enable sub threads to periodically drop disk trace data. 84 * End the periodic disk drop task until the next call to DumpTraceOff(). 85 */ 86 TraceErrorCode DumpTraceOn(); 87 88 /** 89 * End the periodic disk drop task. 90 */ 91 TraceRetInfo DumpTraceOff(); 92 93 /** 94 * Turn off trace mode. 95 */ 96 TraceErrorCode CloseTrace(); 97 98 /** 99 * Get g_traceFilesTable. 100 */ 101 std::vector<std::pair<std::string, int>> GetTraceFilesTable(); 102 103 /** 104 * Set g_traceFilesTable. 105 */ 106 void SetTraceFilesTable(const std::vector<std::pair<std::string, int>>& traceFilesTable); 107 } // Hitrace 108 109 } 110 } 111 112 #endif // HITRACE_DUMP_H