You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Diagnostics;
  26. use OCP\Diagnostics\IEventLogger;
  27. class EventLogger implements IEventLogger {
  28. /**
  29. * @var \OC\Diagnostics\Event[]
  30. */
  31. private $events = [];
  32. /**
  33. * @var bool - Module needs to be activated by some app
  34. */
  35. private $activated = false;
  36. /**
  37. * @inheritdoc
  38. */
  39. public function start($id, $description) {
  40. if ($this->activated) {
  41. $this->events[$id] = new Event($id, $description, microtime(true));
  42. }
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function end($id) {
  48. if ($this->activated && isset($this->events[$id])) {
  49. $timing = $this->events[$id];
  50. $timing->end(microtime(true));
  51. }
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. public function log($id, $description, $start, $end) {
  57. if ($this->activated) {
  58. $this->events[$id] = new Event($id, $description, $start);
  59. $this->events[$id]->end($end);
  60. }
  61. }
  62. /**
  63. * @inheritdoc
  64. */
  65. public function getEvents() {
  66. return $this->events;
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function activate() {
  72. $this->activated = true;
  73. }
  74. }