• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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_DUMP_H
17 #define HITRACE_DUMP_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "hitrace_define.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 namespace Hitrace {
27 constexpr uint64_t DEFAULT_TRACE_SLICE_DURATION = 10;
28 constexpr uint64_t DEFAULT_TOTAL_CACHE_FILE_SIZE = 800;
29 
30 #ifdef HITRACE_UNITTEST
31 void SetSysInitParamTags(uint64_t sysInitParamTags);
32 bool SetCheckParam();
33 #endif
34 
35 /**
36  * Get the current trace mode.
37 */
38 uint8_t GetTraceMode();
39 
40 /**
41  * Open trace with customized args.
42 */
43 TraceErrorCode OpenTrace(const std::string& args);
44 
45 /**
46  * Open trace by tag groups using default parameters.
47  * Default parameters: buffersize = 144MB, clockType = boot, overwrite = true.
48 */
49 TraceErrorCode OpenTrace(const std::vector<std::string>& tagGroups);
50 
51 /**
52  * Reading trace data once from ftrace ringbuffer in the kernel.
53  * Using child processes to process trace tasks.
54  * maxDuration: the maximum time(s) allowed for the trace task.
55  * ---- If maxDuration is 0, means that is no limit for the trace task.
56  * ---- If maxDuration is less than 0, it is illegal input parameter.
57  * utTraceEndTime: the retrospective starting time stamp of target trace.
58  * ----If utTraceEndTime = 0, it is not set.
59  * return TraceErrorCode::SUCCESS if any trace is captured between the designated interval
60  * return TraceErrorCode::OUT_OF_TIME otherwise.
61 */
62 TraceRetInfo DumpTrace(int maxDuration = 0, uint64_t utTraceEndTime = 0);
63 
64 /**
65  * Reading trace data once from ftrace ringbuffer in the kernel.
66  * Using child processes to process trace tasks.
67  * maxDuration: the maximum time(s) allowed for the trace task.
68  * ---- If maxDuration is 0, means that is no limit for the trace task.
69  * ---- If maxDuration is less than 0, it is illegal input parameter.
70  * utTraceEndTime: the retrospective starting time stamp of target trace.
71  * ----If utTraceEndTime = 0, it is not set.
72  * fileSizeLimit: the maximum size(bytes) of the trace file.
73  * ----If fileSizeLimit is 0, it is not set.
74  * asyncCallback: the callback function to handle the trace result.
75  * ----If asyncCallback is nullptr, it is not set.
76  * return TraceErrorCode::SUCCESS if any trace is captured between the designated interval
77  * return TraceErrorCode::OUT_OF_TIME otherwise.
78  */
79 TraceRetInfo DumpTraceAsync(int maxDuration = 0, uint64_t utTraceEndTime = 0, int64_t fileSizeLimit = 0,
80     std::function<void(TraceRetInfo)> asyncCallback = nullptr);
81 
82 /**
83  * Enable sub threads to periodically drop disk trace data.
84  * End the periodic disk drop task until the next call to RecordTraceOff().
85 */
86 TraceErrorCode RecordTraceOn();
87 
88 /**
89  * End the periodic disk drop task.
90 */
91 TraceRetInfo RecordTraceOff();
92 
93 /**
94  * Enable sub threads to periodically dump cache data
95  * End dumping with CacheTraceOff()
96  * CacheTraceOn() function call during the caching phase will return corresponding cache files.
97 */
98 TraceErrorCode CacheTraceOn(uint64_t totalFileSize = DEFAULT_TOTAL_CACHE_FILE_SIZE,
99     uint64_t sliceMaxDuration = DEFAULT_TRACE_SLICE_DURATION);
100 
101 /**
102  * End the periodic cache task.
103 */
104 TraceErrorCode CacheTraceOff();
105 
106 /**
107  * Turn off trace mode.
108 */
109 TraceErrorCode CloseTrace();
110 
111 /**
112  * Set Tracing On Node
113  */
114 TraceErrorCode SetTraceStatus(bool enable);
115 } // Hitrace
116 
117 }
118 }
119 
120 #endif // HITRACE_DUMP_H