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