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