SystemTap

13 篇文章 0 订阅
安装
sudo apt-get install build-essential
sudo apt-get install elfutils
sudo apt-get install libdw-dev
wget wget https://sourceware.org/systemtap/ftp/releases/systemtap-2.4.tar.gz
tar -xzvf systemtap-2.4.tar.gz
cd systemtap-2.4
./configure
sudo make
sudo make install

测试语句
sudo stap --all-modules -ve 'probe begin { log("hello world") exit () }'
sudo stap -ve 'probe begin { log("hello world") exit () }'
sudo stap -ve 'probe kernel.function("sys_open") {log("hello world") exit()}'
sudo stap -ve 'probe module("libiscsi").function("iscsi_queuecommand") {log("hello world") exit()}'
打印堆栈
print_backtrace
--all-modules加载所有模块,显示堆栈信息

在Ubuntu上使用SystemTap
http://www.ningoo.net/html/2010/use_systemtap_on_ubuntu.html

ubuntu+systemtap进行Linux内核和用户空间开发测试
http://blog.csdn.net/sailor_8318/article/details/25076745

SystemTap在Ubuntu 12.04上的安装 Build-id mismatch
http://www.it165.net/os/html/201310/6486.html

使用systemtap调试linux内核
http://blog.csdn.net/heli007/article/details/7187748

利用systemtap定位ifconfig dropped数据包的原因
http://www.it165.net/os/html/201308/5944.html

范例
https://sourceware.org/systemtap/wiki

System语言详解
http://blog.csdn.net/linyt/article/details/5204841

#! /usr/bin/env stap 

global host_no = 17
global channel = 0
global targetid = 0
global lunid = 15

# 判断io是否下发到iscsi
probe module("libiscsi").function("iscsi_queuecommand")
{
    if ( $host!=0 && $sc!=0 )
    {
        if ( $host->host_no==host_no && $sc->device->channel==channel && $sc->device->id==targetid && $sc->device->lun==lunid )
        {
            printf("====================send scsi=======================\n")
            printf("tag = %d\n", $sc->tag)
            printf("serial_number = %lu\n", $sc->serial_number)
            printf("jiffies_at_alloc = %lu\n", $sc->jiffies_at_alloc)
            print_backtrace()        
            printf("\n")
        }
    }
}


probe kernel.function("do_sync_read")
{
    if ($filp!=0)
    {
        if ($filp->f_inode!=0)
        {
            if ($filp->f_inode->i_ino == 3978543828)
            {
                printf("===========================================do_sync_read\n\n")
            }
        }
    }
}

# 判断IO在iscsi被正确下发
probe module("libiscsi").statement("iscsi_queuecommand@libiscsi.c:1690")
{
    if ( $host!=0 && $sc!=0 )
    {
        if ( $host->host_no==host_no && $sc->device->channel==channel && $sc->device->id==targetid && $sc->device->lun==lunid )
        {
            printf("====================cmd sended=======================\n")
            printf("reason=%d\n", $reason)
            printf("\n")
        }
    }
}

# 判断IO是否返回
probe module("libiscsi").function("__iscsi_put_task")
{
    if ($task != 0)
    {

        if ($task->sc != 0)
        {
            if ( $task->sc->device->host->host_no==host_no && $task->sc->device->channel==channel && $task->sc->device->id==targetid && $task->sc->device->lun==lunid )
            {
                printf("*************************recv scsi********************\n")
                printf("tag = %d\n", $task->sc->tag)
                printf("serial_number = %lu\n", $task->sc->serial_number)
                printf("jiffies_at_alloc = %lu\n", $task->sc->jiffies_at_alloc)
                print_backtrace()
                printf("\n")
           }
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值