print("Tracing MySQL server mgr apply_data_packet function")
print("%-14s %-6s %-6s" % ("SINCE_UP_TIME(s)", "PID", "THREAD"))
def print_event(cpu, data, size):
event = b["events"].event(data)
print("%-14s %-6s %-6s" % (event.ts/1000000000, event.tgid, event.pid))
b["events"].open_perf_buffer(print_event)
while 1:
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
首先输出的两行头部信息。接着是输出单次观测数据的回调函数,而 open_perf_buffer 则是将这个回调函数注册到 events 表中。最后就是不断从 perl 缓冲中获取检测数据,然后通过回调函数输出结果。