Skip to content

Instantly share code, notes, and snippets.

@vdubyna
Last active November 1, 2016 14:32
Show Gist options
  • Select an option

  • Save vdubyna/6609575 to your computer and use it in GitHub Desktop.

Select an option

Save vdubyna/6609575 to your computer and use it in GitHub Desktop.
Analize magento mysql log
<?php
/**
* @author [email protected]
*/
$c = file_get_contents('pdo_mysql-2.log');
$qs = explode("\n\n", $c);
array_pop($qs);
$res = 0;
$dups = array();
$tdups = array();
foreach ($qs as $q) {
$q = explode("\n", $q);
$t = explode(" ", end($q));
if (isset($dups[$q[2]])) {
$dups[$q[2]] += 1;
$tdups[$q[2]] += $t[1];
} else {
$dups[$q[2]] = 1;
$tdups[$q[2]] = $t[1];
}
$res += $t[1];
}
$rdups = array_filter($dups, function ($i) { return ($i > 1);} );
echo $res . PHP_EOL;
foreach ($rdups as $k => $v) {
echo str_pad($v, 5, " ") . " = "
. str_pad($tdups[$k], 8, " ")
. " =" . substr($k, 0 , 100) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment