iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.45k stars 3.86k forks source link

Tracing queries within transactions with dbslower #4256

Open km-134 opened 2 years ago

km-134 commented 2 years ago

I am trying to trace transactions for MySQL v8.0.28 but only START TRANSACTION and COMMIT are detected, while the queries in the transactions are not detected. As MySQL dropped support for Dtrace for v8.0+ I am using the alternative with uprobes. Is there a way to adapt the tracing to include the queries within a transaction aswell, e.g. by adapting the mysql_func_name?

Output: python3 dbslower.py -x /usr/local/mysql/bin/mysqld -m 0 mysql Tracing database queries for application /usr/local/mysql/bin/mysqld slower than 0 ms... TIME(s) PID MS QUERY 3.581273 14166 0.189 b'START TRANSACTION' 3.584225 14166 0.193 b'START TRANSACTION' 3.610867 14166 20.043 b'COMMIT' 3.611337 14166 22.350 b'COMMIT'

davemarchevsky commented 2 years ago

(I responded on the mailing list as well, here's a snippet of that response w/ relevant info)

The folks who did most of the implementation of dbslower (https://github.com/iovisor/bcc/pulls?q=is%3Apr+dbslower+is%3Aclosed) aren't particularly active in this repo these days. They might have the mysql expertise necessary to answer your question. Unfortunately I'm not sure if any of the current maintainers have experience tracing MySQL - myself included. Regardless, if you're willing to dig around in the MySQL source I do think your suggested approach of modifying which functions are uprobe'd is likely to work. If current tracing of 'dispatch_command' isn't catching the actual statements in the transaction, presumably there's some other function that is processing the text of those statements that should be fine to trace in lieu of / in addition to what's currently being traced.

If you do get this working we'd certainly appreciate a PR!