• 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 };
42 
43 struct TraceRetInfo {
44     TraceErrorCode errorCode;
45     std::vector<std::string> outputFiles;
46 };
47 
48 /**
49  * Get the current trace mode.
50 */
51 TraceMode GetTraceMode();
52 
53 /**
54  * Set trace parameters based on args for CMD_MODE.
55 */
56 TraceErrorCode OpenTrace(const std::string &args);
57 
58 /**
59  * Set trace tags based on tagGroups for SERVICE_MODE.
60 */
61 TraceErrorCode OpenTrace(const std::vector<std::string> &tagGroups);
62 
63 /**
64  * Reading trace data once from ftrace ringbuffer in the kernel.
65 */
66 TraceRetInfo DumpTrace();
67 
68 /**
69  * Enable sub threads to periodically drop disk trace data.
70  * End the periodic disk drop task until the next call to DumpTraceOff().
71 */
72 TraceErrorCode DumpTraceOn();
73 
74 /**
75  * End the periodic disk drop task.
76 */
77 TraceRetInfo DumpTraceOff();
78 
79 /**
80  * Turn off trace mode.
81 */
82 TraceErrorCode CloseTrace();
83 
84 /**
85  * Get g_traceFilesTable.
86 */
87 std::vector<std::pair<std::string, int>> GetTraceFilesTable();
88 
89 /**
90  * Set g_traceFilesTable.
91 */
92 void SetTraceFilesTable(std::vector<std::pair<std::string, int>>& traceFilesTable);
93 } // Hitrace
94 
95 }
96 }
97 
98 #endif // HITRACE_DUMP_H