一,工具简介
tcpconnlat工具追踪执行活动TCP连接的内核函数(例如,通过connect()系统调用),并显示本地测量的连接延迟(时间):从发送SYN到响应数据包的时间。
二,代码示例
#!/usr/bin/env pythonfrom __future__ import print_function
from bcc import BPF
from socket import inet_ntop, AF_INET, AF_INET6
from struct import pack
import argparse# arg校验
def positive_float(val):try:ival = float(val)except ValueError:raise argparse.ArgumentTypeError("must be a float")if ival < 0:raise argparse.ArgumentTypeError("must be positive")return ival# 参数
examples = """examples:./tcpconnlat # trace all TCP connect()s./tcpconnlat 1 # trace connection latency slower than 1 ms./tcpconnlat 0.1 # trace connection latency slower than 100 us./tcpconnlat -t # include timestamps./tcpconnlat -p 181 # only trace PID 181./tcpconnlat -L