一,工具简介
dbstat用于追踪由MySQL或PostgreSQL数据库进程执行的查询,并显示查询延迟的直方图。
二,代码示例
#!/usr/bin/env pythonfrom bcc import BPF, USDT
import argparse
import subprocess
from time import sleep, strftimeexamples = """dbstat postgres # display a histogram of PostgreSQL query latenciesdbstat mysql -v # display MySQL latencies and print the BPF programdbstat mysql -u # display query latencies in microseconds (default: ms)dbstat mysql -m 5 # trace only queries slower than 5msdbstat mysql -p 408 # trace queries in a specific process
"""
parser = argparse.ArgumentParser(description="",formatter_class=argparse.RawDescriptionHelpFormatter,epilog=examples)
parser.add_argument("-v", "--verbose", action="store_true",help="print the BPF program")
parser.add_argument("db", choices=["mysql", &