行业知识
5.52 BCC工具之dbslower.py解读
2026-11-17 01:24:14
来源:互联网转载
一,工具简介
dbslower工具用于追踪由 MySQL 或 PostgreSQL 服务器提供的查询,并打印出那些超过延迟(查询时间)阈值的查询。默认情况下,使用的阈值是 1 毫秒。
()二,代码示例
#!/usr/bin/env pythonfrom bcc import BPF, USDTimport argparseimport reimport subprocessexamples = """examples: dbslower postgres # trace PostgreSQL queries slower than 1ms dbslower postgres -p 188 322 # trace specific PostgreSQL processes dbslower mysql -p 480 -m 30 # trace MySQL queries slower than 30ms dbslower mysql -p 480 -v # trace MySQL queries & print the BPF program dbslower mysql -x $(which mysqld) # trace MySQL queries with uprobes"""parser = argparse.ArgumentParser( description="", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=examples)parser.add_argument("-v", "--verbose", action="store_true", help="print the BPF program")par()