YiiDebugToolbarResourceUsage.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * YiiDebugToolbarResourceUsage class file.
  4. *
  5. * @author Sergey Malyshev <malyshev@zfort.net>
  6. */
  7. /**
  8. * YiiDebugToolbarResourceUsage represents an ...
  9. *
  10. * Description of YiiDebugToolbarResourceUsage
  11. *
  12. * @author Sergey Malyshev <malyshev@zfort.net>
  13. * @package
  14. * @since 1.1.7
  15. */
  16. class YiiDebugToolbarResourceUsage extends CWidget
  17. {
  18. public $htmlOptions = array();
  19. private $_loadTime;
  20. public function getLoadTime()
  21. {
  22. if (null === $this->_loadTime) {
  23. $this->_loadTime = $this->owner->owner->getLoadTime();
  24. }
  25. return $this->_loadTime;
  26. }
  27. public function getRequestLoadTime()
  28. {
  29. return ($this->owner->owner->getEndTime() - $_SERVER['REQUEST_TIME']);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function run()
  35. {
  36. $data = array();
  37. $data[] = array(
  38. 'i' => 'b',
  39. 'value' => sprintf('%0.4F', $this->getLoadTime()),
  40. 'unit' => 'seconds'
  41. );
  42. $data[] = array(
  43. 'i' => 'a',
  44. 'value' => sprintf('%0.4F', $this->getRequestLoadTime()),
  45. 'unit' => 'seconds'
  46. );
  47. $memoryUsage = number_format(Yii::getLogger()->getMemoryUsage() / 1024 / 1024, 2);
  48. if (function_exists('memory_get_peak_usage')) {
  49. $memoryUsage .= '/' . number_format(memory_get_peak_usage() / 1024 / 1024, 2);
  50. }
  51. $data[] = array(
  52. 'i' => 'p',
  53. 'value' => $memoryUsage,
  54. 'unit' => 'megabytes'
  55. );
  56. $this->render('resources', array(
  57. 'data' => $data
  58. ));
  59. }
  60. }