| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
4 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
5 |
*
|
|
|
6 |
* Licensed under The MIT License
|
|
|
7 |
* Redistributions of files must retain the above copyright notice.
|
|
|
8 |
*
|
|
|
9 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
10 |
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
11 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
App::uses('DebugPanel', 'DebugKit.Lib');
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Provides debug information on the SQL logs and provides links to an ajax explain interface.
|
|
|
18 |
*
|
|
|
19 |
*/
|
|
|
20 |
class SqlLogPanel extends DebugPanel {
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Minimum number of Rows Per Millisecond that must be returned by a query before an explain
|
|
|
24 |
* is done.
|
|
|
25 |
*
|
|
|
26 |
* @var integer
|
|
|
27 |
*/
|
|
|
28 |
public $slowRate = 20;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Gets the connection names that should have logs + dumps generated.
|
|
|
32 |
*
|
|
|
33 |
* @param \Controller|string $controller
|
|
|
34 |
* @return array
|
|
|
35 |
*/
|
|
|
36 |
public function beforeRender(Controller $controller) {
|
|
|
37 |
if (!class_exists('ConnectionManager')) {
|
|
|
38 |
return array();
|
|
|
39 |
}
|
|
|
40 |
$connections = array();
|
|
|
41 |
|
|
|
42 |
$dbConfigs = ConnectionManager::sourceList();
|
|
|
43 |
foreach ($dbConfigs as $configName) {
|
|
|
44 |
$driver = null;
|
|
|
45 |
$db = ConnectionManager::getDataSource($configName);
|
|
|
46 |
if (
|
|
|
47 |
(empty($db->config['driver']) && empty($db->config['datasource'])) ||
|
|
|
48 |
!method_exists($db, 'getLog')
|
|
|
49 |
) {
|
|
|
50 |
continue;
|
|
|
51 |
}
|
|
|
52 |
if (isset($db->config['datasource'])) {
|
|
|
53 |
$driver = $db->config['datasource'];
|
|
|
54 |
}
|
|
|
55 |
$explain = false;
|
|
|
56 |
$isExplainable = (preg_match('/(Mysql|Postgres)$/', $driver));
|
|
|
57 |
if ($isExplainable) {
|
|
|
58 |
$explain = true;
|
|
|
59 |
}
|
|
|
60 |
$connections[$configName] = $explain;
|
|
|
61 |
}
|
|
|
62 |
return array('connections' => $connections, 'threshold' => $this->slowRate);
|
|
|
63 |
}
|
|
|
64 |
}
|