-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslow_csvreader.php
More file actions
56 lines (48 loc) · 1.33 KB
/
slow_csvreader.php
File metadata and controls
56 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Read mysql slow query log in csv format (as of mysql 5.1 it by default)
*
*/
class slow_csvreader extends filereader implements query_fetcher
{
/**
* Fetch next query from csv file
*
* @return string - or FALSE on file end
*/
public function get_query ()
{
while (false !== ($data = fgetcsv($this->fp)))
{
if (!isset($data[10]))
continue;
$query_time = self::time_to_int($data[2]);
$lock_time = self::time_to_int($data[3]);
$rows_sent = $data[4];
$rows_examined = $data[5];
$statement = str_replace(array("\\\\", '\\"'), array("\\", '"'), $data[10]);
// cut statement id from prefix of prepared statement
return array(
'qt'=> $query_time,
'lt'=> $lock_time,
'rs'=> $rows_sent,
're'=> $rows_examined, $statement
);
}
return false;
}
/**
* Converts time value in format H:i:s into integer
* representation of number of total seconds
*
* @param string $time
*
* @return integer
*/
protected static function time_to_int ($time)
{
list($h, $m, $s) = explode(':', $time);
return ($h * 3600 + $m * 60 + $s);
}
}
?>