我從來沒有見過你想要的。但你可以完成你想要的東西。 開發程序,監視慢日誌並立即重新運行慢查詢並打印show profile
輸出。
我寫了PHP僞代碼,我查了show profile
在PHP中也很好用。但如何監控慢日誌和解析日誌內容未經測試。下面只是僞代碼。它不會工作。
$conn = mysql_connect("localhost", "user", "passwd");
monitor_slow_log($conn);
function monitor_slow_log($conn)
{
$res = mysql_query("set profiling = 1");
$fp = fopen("/path/to/slow_log", "r");
while (($str = fgets($fp, 10000)) !== false)
{
$query = parse_and_extract_query($str);
get_profile_result($str);
}
}
function parse_and_extract_query($str)
{
// I'm not sure how to parse it.
// as you know there are more than slow query.
}
function get_profile_result($query)
{
$res = mysql_query($query);
while ($row = mysql_fetch_array($res))
{
// fetch all record
}
mysql_free_result($res);
// print show profile result
$res = mysql_query("show profile");
while ($row = mysql_fetch_assoc($res))
{
echo $row["Status"]." ===> ".$row['Duration']."\n";
}
mysql_free_result($res);
// print SHOW PROCESSLIST
mysql_query("show processlist") and print
// print SHOW ENGINE INNODB STATUS
mysql_query("show engine innodb status") and print
// print SHOW GLOBAL STATUS
mysql_query("show global status") and print
// print `top` output
system('top -n 1');
}
另外,不僅show profile
,但也需要一些信息如下。
- SHOW PROCESSLIST
- SHOW ENGINE INNODB STATUS
- SHOW全球地位
top
輸出
謝謝,@ jungsu-HEO,但我不只是想重新運行查詢和得到他們的個人資料,我想在他們運行時得到他們的個人資料*。 –
@TolaOdejayi是的。所以我建議polloing每1秒慢日誌並重新運行查詢和顯示配置文件。 –