EventLogger.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  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. namespace OC\Diagnostics;
  25. use OCP\Diagnostics\IEventLogger;
  26. class EventLogger implements IEventLogger {
  27. /**
  28. * @var \OC\Diagnostics\Event[]
  29. */
  30. private $events = [];
  31. /**
  32. * @var bool - Module needs to be activated by some app
  33. */
  34. private $activated = false;
  35. /**
  36. * @inheritdoc
  37. */
  38. public function start($id, $description) {
  39. if ($this->activated){
  40. $this->events[$id] = new Event($id, $description, microtime(true));
  41. }
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function end($id) {
  47. if ($this->activated && isset($this->events[$id])) {
  48. $timing = $this->events[$id];
  49. $timing->end(microtime(true));
  50. }
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function log($id, $description, $start, $end) {
  56. if ($this->activated) {
  57. $this->events[$id] = new Event($id, $description, $start);
  58. $this->events[$id]->end($end);
  59. }
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function getEvents() {
  65. return $this->events;
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function activate() {
  71. $this->activated = true;
  72. }
  73. }