|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Morris Jobke <[email protected]> |
|
4
|
|
|
* @author Robin Appelman <[email protected]> |
|
5
|
|
|
* @author Thomas Müller <[email protected]> |
|
6
|
|
|
* @author Piotr Mrowczynski <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright (c) 2017, ownCloud GmbH |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OC\Diagnostics; |
|
26
|
|
|
|
|
27
|
|
|
use OCP\Diagnostics\IQueryLogger; |
|
28
|
|
|
|
|
29
|
|
|
class QueryLogger implements IQueryLogger { |
|
30
|
|
|
/** |
|
31
|
|
|
* @var \OC\Diagnostics\Query |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $activeQuery; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \OC\Diagnostics\Query[] |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $queries = []; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var bool - Module needs to be activated by some app |
|
42
|
|
|
*/ |
|
43
|
|
|
private $activated = false; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function startQuery($sql, array $params = null, array $types = null) { |
|
49
|
|
|
if ($this->activated) { |
|
50
|
|
|
$this->activeQuery = new Query($sql, $params, microtime(true)); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritdoc |
|
56
|
|
|
*/ |
|
57
|
|
|
public function stopQuery() { |
|
58
|
|
|
if ($this->activated && $this->activeQuery) { |
|
59
|
|
|
$this->activeQuery->end(microtime(true)); |
|
60
|
|
|
$this->queries[] = $this->activeQuery; |
|
61
|
|
|
$this->activeQuery = null; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @inheritdoc |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getQueries() { |
|
69
|
|
|
return $this->queries; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @inheritdoc |
|
74
|
|
|
*/ |
|
75
|
|
|
public function activate() { |
|
76
|
|
|
$this->activated = true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.