1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        BSBacktraceLoggeriOS 輕量級調(diào)用棧分析器

        聯(lián)合創(chuàng)作 · 2023-10-02 03:00

        BSBacktraceLogger,一款輕量級調(diào)用棧分析器,用于記錄線程的調(diào)用棧。它只有一個類,四百行代碼。它支持現(xiàn)有所有模擬器、真機的 CPU 架構(gòu),可以獲取任意線程的調(diào)用棧,因此可以在檢測到 runloop 檢測到卡頓時獲取卡頓處的代碼執(zhí)行情況。

        示例代碼:

        #import "BSBacktraceLogger.h"
        - (void)viewDidLoad {
            [super viewDidLoad];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
                BSLOG  // 打印當前線程的調(diào)用棧
                BSLOG_ALL  // 打印所有線程的調(diào)用棧
                BSLOG_MAIN  // 打印主線程調(diào)用棧
            });
            [self foo];
        }
        - (void)foo {
            [self bar];
        }
        - (void)bar {
            while (true) {
                ;
            }
        }

        定義了三個宏用于快速輸出,或者調(diào)用 [BSBacktraceLogger bs_backtraceOfCurrentThread] 等函數(shù)獲取字符串格式的調(diào)用棧。

        樣例

        上述代碼中,BSLOG_MAIN 這個宏的輸出結(jié)果如下:

        2016-08-27 18:33:20.017 BSBacktraceLogger[25215:862569] Backtrace of Thread 1803:
        KtBacktraceLogger               0x10b831f4c -[ViewController bar] + 12
        KtBacktraceLogger               0x10b831f2b -[ViewController foo] + 43
        KtBacktraceLogger               0x10b831fe0 -[ViewController viewDidLoad] + 128
        UIKit                           0x10c813984 -[UIViewController loadViewIfRequired] + 1198
        UIKit                           0x10c813cd3 -[UIViewController view] + 27
        UIKit                           0x10c6e9fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
        UIKit                           0x10c6ea69d -[UIWindow _setHidden:forced:] + 282
        UIKit                           0x10c6fc180 -[UIWindow makeKeyAndVisible] + 42
        UIKit                           0x10c670ed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
        UIKit                           0x10c677568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
        UIKit                           0x10c674714 -[UIApplication workspaceDidEndTransaction:] + 188
        FrontBoardServices              0x10f0e18c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
        FrontBoardServices              0x10f0e1741 -[FBSSerialQueue _performNext] + 178
        FrontBoardServices              0x10f0e1aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
        CoreFoundation                  0x10c1e8301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        CoreFoundation                  0x10c1de22c __CFRunLoopDoSources0 + 556
        CoreFoundation                  0x10c1dd6e3 __CFRunLoopRun + 867
        CoreFoundation                  0x10c1dd0f8 CFRunLoopRunSpecific + 488
        UIKit                           0x10c673f21 -[UIApplication _run] + 402
        UIKit                           0x10c678f09 UIApplicationMain + 171
        KtBacktraceLogger               0x10b8338ff main + 111
        libdyld.dylib                   0x10ea9c92d start + 1

        說明

        Xcode 的調(diào)試輸出不穩(wěn)定,有時候存在調(diào)用 NSLog() 但沒有輸出結(jié)果的情況,建議前往 控制臺 中根據(jù)設(shè)備的 UUID 查看完整輸出。

        真機調(diào)試和使用 Release 模式時,為了優(yōu)化,某些符號表并不在內(nèi)存中,而是存儲在磁盤上的 dSYM 文件中,無法在運行時解析,因此符號名稱顯示為

        瀏覽 22
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            强奸一区二区三区 | 欧美性猛交free性丰满 | 办公室荡乳欲伦交换bd电影 | 91国产在线播放 | 九九黄色 | 蜜桃精品在线 | 啊~我是sao货快cao我 三上悠亚精品二区 | 伊人夜夜| 女人大香蕉操逼网 | 爱干av麻豆 |