• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef DFX_FAULTLOGGERD_CLIENT_H
16 #define DFX_FAULTLOGGERD_CLIENT_H
17 
18 #include <inttypes.h>
19 
20 #include "dfx_socket_request.h"
21 #include <string>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief request file descriptor
29  * @param type type of resqust
30  * @return if succeed return file descriptor, otherwise return -1
31 */
32 int32_t RequestFileDescriptor(int32_t type);
33 
34 /**
35  * @brief request pipe file descriptor
36  * @param pid process id of request pipe
37  * @param pipeType type of request about pipe
38  * @param pipeFd pipeFd[0] to transfer call stack message and
39  *               pipeFd[1] to transfer backtrace result
40  * @return if succeed return 0, otherwise return -1
41 */
42 int32_t RequestPipeFd(int32_t pid, int32_t pipeType, int (&pipeFd)[2]);
43 
44 /**
45  * @brief request delete file descriptor
46  * @param pid process id of request pipe
47  * @return if succeed return 0, otherwise return the error code
48 */
49 int32_t RequestDelPipeFd(int32_t pid);
50 
51 /**
52  * @brief request file descriptor
53  * @param request struct of request information
54  * @return if succeed return file descriptor, otherwise return -1
55 */
56 int32_t RequestFileDescriptorEx(struct FaultLoggerdRequest* request);
57 
58 /**
59  * @brief request lipeperf pipe file descriptor
60  * @param pipeType type of request about pipe
61  * @param pipeFd pipeFd[0] to transfer call stack message and
62  *               pipeFd[1] to transfer backtrace result
63  * @return if succeed return 0, otherwise return -1
64 */
65 int32_t RequestLitePerfPipeFd(int32_t pipeType, int (&pipeFd)[2], int timeout);
66 
67 /**
68  * @brief request delete lite perf file descriptor
69  * @return if succeed return 0, otherwise return the error code
70 */
71 int32_t RequestLitePerfDelPipeFd();
72 
73 /**
74  * @brief request dump stack about process
75  * @param pid process id
76  * @param tid thread id, if equal 0 means dump all the threads in a process.
77  * @param pipeReadFd if pass sdkdump, will get pipeReadFd[0] to read call stack message and
78  *                   pipeReadFd[1] to read backtrace result
79  * @param isJson if set true, will get json format result, else get string result
80  * @return if succeed return 0 , otherwise return the error code
81 */
82 int32_t RequestSdkDump(int32_t pid, int32_t tid, int (&pipeReadFd)[2],
83     bool isjson = false, int timeout = 10000); // 10000 : dump timeout ms
84 
85 /**
86  * @brief report sdk dump result to faultloggerd for stats collection
87  * @param request dump request result
88  * @return if succeed return 0 , otherwise return the error code
89 */
90 int32_t ReportDumpStats(struct FaultLoggerdStatsRequest *request);
91 
92 /**
93  * @brief cancel coredump request
94  * @param targetPid target id
95  * @return if succeed return 0 , otherwise return the error code
96 */
97 int32_t CancelCoredump(int32_t targetPid);
98 
99 /**
100  * @brief start coredump request
101  * @param targetPid target id
102  * @param processDumpPid processdump id
103  * @return if succeed return 0 , otherwise return the error code
104 */
105 int32_t StartCoredumpCb(int32_t targetPid, int32_t processDumpPid);
106 
107 /**
108  * @brief finish coredump request
109  * @param targetPid target id
110  * @param fileName coredump file name
111  * @param ret coredump result
112  * @return if succeed return 0 , otherwise return the error code
113 */
114 int32_t FinishCoredumpCb(int32_t targetPid, std::string& fileName, int32_t ret);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 /**
120  * @brief do coredump request
121  * @param targetPid target id
122  * @param timeout timeout ms
123  * @return if succeed return fileName, otherwise return ""
124 */
125 std::string SaveCoredumpToFileTimeout(int32_t targetPid, int32_t timeout = 10000);
126 #endif
127