Created
April 14, 2010 17:08
-
-
Save rysk92/366064 to your computer and use it in GitHub Desktop.
mysqldumpslowの結果をcsvにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#how to use, mysqldumpslow mysql-slow.log > hoge | |
# php MysqldumpslowResult2Csv hoge > hoge.csv | |
$log_filename = $argv[1]; | |
echo 'Count, Time, Time(total), Lock, Lock(total), Rows, Rows(total), Src, SQL'."\n"; | |
if (file_exists($log_filename)) | |
{ | |
$contents = file_get_contents($log_filename); | |
$queries = preg_split('/\n{2,}/', $contents); | |
foreach ($queries as $query) | |
{ | |
if (!$query) | |
{ | |
continue; | |
} | |
$line = array(); | |
$sql = preg_split('/\n /', $query); | |
$information = array_shift($sql); | |
preg_match('/^Count: (\d+) Time=(\d+\.\d{2})s \((\d+)s\) Lock=(\d+\.\d{2})s \((\d+)s\) Rows=(\d+\.\d) \((\d+)\), (.+)$/', $information, $line); | |
array_shift($line); | |
array_push($line, sprintf('"%s"', implode(' ', $sql))); | |
echo implode(',', $line)."\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment