在监控的函数里添加下段代码
最终函数调用信息依照顺序存在NSMutableArray backtrace 中
还需要添加头文件
#include
#include
void* callstack[128];
int frames = backtrace(callstack, 128);
char **strs = backtrace_symbols(callstack, frames);
int i;
NSMutableArray *backtrace = [NSMutableArray arrayWithCapacity:frames];
for (i = 0;i < frames;i++){
[backtrace addObject:[NSString stringWithUTF8String:strs[i]]];
}
free(strs);
NSLog(@"====================堆栈\n %@ \n",backtrace);
网友评论