美文网首页
iOS 获取堆栈信息2022-02-23

iOS 获取堆栈信息2022-02-23

作者: iOS打怪升级 | 来源:发表于2022-02-23 17:45 被阅读0次
    #include <libkern/OSAtomic.h>
    #include <execinfo.h>
    tatic void getStackList()
    {
        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 < 4;i++){
            [backtrace addObject:[NSString stringWithUTF8String:strs[i]]];
        }
        free(strs);
        DDLogDebug(@"=====>>>>>堆栈<<<<<=====\n%@",backtrace);
    }
    //测试代码
    [NSTimer timerWithTimeInterval:5 repeats:YES block:^(NSTimer * _Nonnull timer) {
            getStackList();
        }];

    相关文章

      网友评论

          本文标题:iOS 获取堆栈信息2022-02-23

          本文链接:https://www.haomeiwen.com/subject/huaolrtx.html