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 information. 35 * heaviestStack: the string to save the heaviest stack information. 36 * size: the length of stack. 37 * heaviestSize: the length of heaviestStack. 38 * treeFormat: collect stack infomation in tree format or not. 1 for tree format and 0 for not. 39 * return 0 for success and -1 for fail. 40 */ 41 int ThreadSamplerCollect(char* stack, char* heaviestStack, size_t stackSize, size_t heaviestSize, int treeFormat); 42 43 /* To deinitial thread sampler and unload the resources. */ 44 int ThreadSamplerDeinit(); 45 46 /* The signal handler function */ 47 void ThreadSamplerSigHandler(int sig, siginfo_t* si, void* context); 48 49 #ifdef __cplusplus 50 } 51 #endif 52 } // namespace HiviewDFX 53 } // namespace OHOS 54 #endif 55