From b384f982b98e6e3458766ab3ea909f552cc59254 Mon Sep 17 00:00:00 2001 From: yunwei37 <1067852565@qq.com> Date: Mon, 2 Sep 2024 06:40:19 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20eunomia-?= =?UTF-8?q?bpf/bpf-developer-tutorial@2f3ed55972ed23f71dd78225eb9e4d0d8a3e?= =?UTF-8?q?613a=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 40-mysql/dispatch_command.bt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 40-mysql/dispatch_command.bt diff --git a/40-mysql/dispatch_command.bt b/40-mysql/dispatch_command.bt new file mode 100644 index 0000000..e42e378 --- /dev/null +++ b/40-mysql/dispatch_command.bt @@ -0,0 +1,30 @@ +#!/usr/bin/env bpftrace + + +// Trace the dispatch_command function in MySQL +uprobe:/usr/sbin/mysqld:dispatch_command +{ + // Store the start time of the command execution in the map + @start_times[tid] = nsecs; + + // Print the process ID and command string + printf("MySQL command executed by PID %d: ", pid); + + // The third argument to dispatch_command is the SQL query string + printf("%s\n", str(arg3)); +} + +uretprobe:/usr/sbin/mysqld:dispatch_command +{ + // Retrieve the start time from the map + $start = @start_times[tid]; + + // Calculate the latency in milliseconds + $delta = (nsecs - $start) / 1000000; + + // Print the latency + printf("Latency: %u ms\n", $delta); + + // Delete the entry from the map to avoid memory leaks + delete(@start_times[tid]); +}