BugProfiler功能使用介绍

85 阅读2分钟

目前BugProfiler主要是用来定位lj_meta_cache函数的调用情况:

image.png

选项解释

enabled

是否启用bugProfiler功能

log save directory

log文件的保存目录

cpp filter

对c++的堆栈进行过滤,如果堆栈包含有指定的字符串,那么就会被保存到log文件中

  • 如果不需要过滤,填写空字符串即可

  • 如果有适配多个字符串,使用,分割(注意:如果字符串中包含空格也会参与过滤),比如:

    a,b,c

    只要c++堆栈中包含a、或者b、或者c、都认为是一个有效的结果

我们可以通过bugly,尽可能的找到崩溃相关的函数,通过cpp filter,我们会收集到有针对性的log,减少干扰项

watch

当watch启用时,BugProfiler就会开始收集相关log。

当watch禁用后,会自动生成日志文件。

image.png

watch属性后边会有一个数字,表示当前收集到的log数量,我们可以通过该数字很只管的观察到log的大致情况。

日志文件示例

call lj_meta_cache history:
#1 hash:66860401
  TextureTools::cppStack at E:\proj\tank5\client\frameworks\runtime-src\Classes\tools\TextureTools.cpp:145
  collectionCallStackInfo at E:\proj\tank5\client\frameworks\qt-editor\src\editor\module\ModuleBase.cpp:115
  emitHookFunction at E:\proj\tank5\client\frameworks\qt-editor\src\luajit\src\lib_hook.c:14
  lj_meta_cache at E:\proj\tank5\client\frameworks\qt-editor\src\luajit\src\lj_meta.c:53
  lj_meta_tset at E:\proj\tank5\client\frameworks\qt-editor\src\luajit\src\lj_meta.c:175
  lua_settable at E:\proj\tank5\client\frameworks\qt-editor\src\luajit\src\lj_api.c:967
  storeatubox at E:\proj\tank5\client\frameworks\cocos2d-x\external\lua\tolua\tolua_event.c:34
  class_newindex_event at E:\proj\tank5\client\frameworks\cocos2d-x\external\lua\tolua\tolua_event.c:377

  <__newindex> at =[C]:-1
  <func> at .\cocos/cocos2d/functions.lua:268
  <goLayer> at .\index.lua:152
  [Lua] at .\index.lua:129


#2 hash:66860401
  see details same by hash 

#3 hash:66860401
  see details same by hash 

#numer可以看到触发lj_meta_cache函数的次数,通过hash,精简了log,更加清楚的看到调用情况。

使用实例

  1. 尽可能多的获取c++堆栈的函数,比如bugly上报的崩溃堆栈,如果崩溃堆栈是符号地址,需要通过addr2line等相关工具换取相关的函数名字,相关工具推荐vscode插件-addr2line-assistant

  2. 最好确认一些c++堆栈的函数,在源码中是否存在,luajit源码参考,注意luajit的部分源码是编译生成的,昂库里面可能没有。

  3. 将获取到的c++堆栈函数,填写到cpp filter里面,这样可以过滤不符合堆栈信息的结果,比如:lj_meta_cache,rec_call_setup

    image.png

  4. 点击watch监听游戏,当完成相关游戏操作后,取消watch即可生成lj_meta_cache.log,此时的log是经过cpp filter过滤后的

  5. 分析log,排查定位问题