美文网首页
使用systemtap调试软件技巧

使用systemtap调试软件技巧

作者: mqddb | 来源:发表于2017-08-09 14:49 被阅读0次

技巧一

获取函数运行时间。编写协议类的软件,很多问题往往和某个函数体的运行时间有关,获取耗时长的函数,往往是解决问题的关键。如何用systemtap快速定位问题函数?

#!/usr/bin/env stap

probe process("target_solftware").function("target_function").call {
    printf("%s << %s\n", thread_indent(1), ppfunc());
}

probe process("target_solftware").function("target_function").return {
    printf("%s >> %s\n", thread_indent(-1), ppfunc());
}

获取的打印如下:

  5027 gkappsession(9364): >>cpy_frame 
     0 gkappsession(9364): <<cpy_frame 
  3917 gkappsession(9364): >>cpy_frame 
     0 gkappsession(9364): <<cpy_frame 
  3587 gkappsession(9364): >>cpy_frame 
     0 gkappsession(9364): <<cpy_frame 
  4156 gkappsession(9364): >>cpy_frame 
     0 gkappsession(9364): <<cpy_frame 
  3615 gkappsession(9364): >>cpy_frame 

第一行是函数运行时间,单位为us。这个是获取整个函数的调用时间,如果这个函数里面又调用了其他的函数,如何确定调用的函数中,哪个耗时比较多呢?

#!/usr/bin/env stap

global switcher

probe begin {
    switcher = 0
}

probe process("target_solftware").library("target_library").function("target_function").call {
    switcher = 1
}

probe process("target_solftware").library("target_library").function("target_function").return {
    switcher = 0
    printf("%s >>%s\n", thread_indent(-1), ppfunc())
}

probe process("target_solftware").library("target_library").function("*").call {
    if (switcher == 1) {
        printf("%s <<%s\n", thread_indent(1), ppfunc())
    }
}

probe process("target_solftware").library("target_library").function("*").return {
    if (switcher == 1 ) {
        printf("%s >>%s\n", thread_indent(-1), ppfunc())
    }
}

这个脚本可以具体到函数里面的子函数的调用时间。可以快速定位到问题函数。

技巧二

获取帧率,协议类软件性能的体现就是帧率。数据包的发送频率越高,终端体验越好。如何快速查看某个函数的调用帧率:

#!/usr/bin/env stap

global rate2
global rate1
global rate3
probe process("/usr/bin/idv-channel").library("libgkapp.so.1").function("gkapp_enc_engine_encode_frame") {
        rate3 ++
}

probe process("/usr/bin/gkappsession").library("libgkapp.so.1").function("encode_handle_worker") {
        rate2 ++
}
probe process("/usr/bin/gkappsession").library("libgkapp.so.1").function("do_grab_data") {
       rate1 ++
}

probe timer.s(1) {
        printf("%d, %d, %d\n",  rate1, rate2, rate3);
        rate1 = 0;
        rate2 = 0;
        rate3 = 0;

}

相关文章

  • 使用systemtap调试软件技巧

    技巧一 获取函数运行时间。编写协议类的软件,很多问题往往和某个函数体的运行时间有关,获取耗时长的函数,往往是解决问...

  • stap环境搭建

    使用systemtap之前,要现安装systemtap,我用的是ubuntu16.04,内核Linux ubu...

  • 安装systemtap生成openresty的火焰图

    SystemTap 简单介绍 systemtap是一个诊断linux系统性能和功能问题的开源软件,并且允许开发人员...

  • systemtap使用笔记

    安装 使用之前需要安装一些内核调试包安装systemtap 可以用这个命令看下需要的包 正常的安装流程.假设之前相...

  • 使用 Fuse 来进行 I/O 错误注入

    在之前介绍 SystemTap 的文章中,我提到了我们使用 SystemTap 做了很多 I/O 错误注入的工作,...

  • 火焰图生成

    上篇介绍了systemtap的使用。承接上篇,这篇接着纪录后续,用systemtap统计了信息,如何更加直观的观察...

  • 软件调试的技巧

    这篇文章是《调试九法:软硬件错误的排查之道》的阅读笔记。这本书的主旨,是介绍如何修复bug:找出bug发生的原因、...

  • 调试技巧

    Android Studio 掌握这些调试技巧,Debug 能力不能再高啦 Debug断点跟踪调试是软件开发过程中...

  • python高级调试技巧(一)原生态的pdb调试(内含学习路线和

    python高级调试技巧(一)——原生态的pdb调试 目录 一 使用系统自带的pdb模式模块进行单 步调试 二 使...

  • Xcode中LLDB使用CheatSheet

    使用LLDB可以减少使用NSLog大大提高调试的效率,尤其是使用下面提及的断点设置选项、界面调试技巧的时候。 基础...

网友评论

      本文标题:使用systemtap调试软件技巧

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