1 /*
2  * Copyright (c) 2024 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 RELIABILITY_THREAD_SAMPLER_API_H
17 #define RELIABILITY_THREAD_SAMPLER_API_H
18 
19 #include "thread_sampler.h"
20 
21 namespace OHOS {
22 namespace HiviewDFX {
23 constexpr int SUCCESS = 0;
24 constexpr int FAIL = -1;
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* To initialize thread sampler, load resources needed, return 0 for success. */
31 int ThreadSamplerInit(int collectStackCount);
32 
33 /* To start sample stack with thread sampler. */
34 int32_t ThreadSamplerSample();
35 
36 /* To collect the stack infomation collected by thread sampler in string.
37  * stack: the string to save the stack infomation.
38  * size: the length of stack.
39  * treeFormat: collect stack infomation in tree format or not. 1 for tree format and 0 for not.
40  * return 0 for success and -1 for fail.
41  */
42 int ThreadSamplerCollect(char* stack, size_t size, int treeFormat = 1);
43 
44 /* To deinitial thread sampler and unload the resources. */
45 int ThreadSamplerDeinit();
46 
47 /* The signal handler function */
48 void ThreadSamplerSigHandler(int sig, siginfo_t* si, void* context);
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 }
54 }
55 #endif
56