Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4e191ed
start
Denitz Sep 24, 2021
9734bd5
phpcs fix
Denitz Sep 24, 2021
685368d
docblock fix
Denitz Sep 24, 2021
77e9418
docblocks fix
Denitz Sep 24, 2021
69d7bb4
custom memory collector
Denitz Sep 24, 2021
d8e5286
cs fix
Denitz Sep 24, 2021
8eded10
fix cs
Denitz Sep 24, 2021
1bb0fe6
even more cs
Denitz Sep 24, 2021
ed1ff10
Update plugins/system/cache/cache.php
Denitz Sep 24, 2021
3bc7922
Update plugins/system/debug/src/DataCollector/MemoryCollector.php
Denitz Sep 24, 2021
c6e7a8a
Update plugins/system/debug/src/DataCollector/MemoryCollector.php
Denitz Sep 24, 2021
d0a74f1
Update plugins/system/debug/src/DataCollector/ProfileCollector.php
Denitz Sep 24, 2021
204f4ab
Update plugins/system/debug/src/DataCollector/ProfileCollector.php
Denitz Sep 24, 2021
08e4b04
cs
Denitz Sep 24, 2021
a1d274a
cs
Denitz Sep 24, 2021
14f7884
revert ProfileCollector constructor.
Denitz Sep 27, 2021
031c3e7
Merge branch '4.1-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Feb 22, 2022
d61018d
fix
Denitz Feb 23, 2022
a72a7d2
Merge branch '4.1-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Feb 23, 2022
0ff9593
Merge branch '4.1-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Feb 23, 2022
b49d4ed
Remove 'afterRespond' mark
Denitz Feb 25, 2022
d58a325
Merge branch '_4.0]_Wrong_timings_in_debug_plugin' of github.com:Deni…
Denitz Feb 25, 2022
0cd14a7
Merge branch '4.1-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Feb 26, 2022
ba57d16
Merge remote-tracking branch 'joomla/4.1-dev' into _4.0]_Wrong_timing…
Denitz May 25, 2022
3f63817
fix
Denitz May 25, 2022
f53faae
Merge tag 'psr12anchor' into psr12/merge/35655
joomla-bot Jun 27, 2022
5858c86
Phase 1 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
9ad58a5
Phase 2 convert BRANCH to PSR-12
joomla-bot Jun 27, 2022
b550afe
Merge tag 'psr12final' into psr12/merge/35655
joomla-bot Jun 27, 2022
b5f705b
Merge branch '4.2-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Jul 2, 2022
8f70e54
Merge remote-tracking branch 'joomla/4.3-dev' into _4.0]_Wrong_timing…
Denitz Mar 27, 2023
2c6d66d
fix
Denitz Mar 27, 2023
62b6185
Merge branch '4.3-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Mar 27, 2023
2c79078
fix CS
Denitz Mar 27, 2023
ede994c
Merge branch '4.3-dev' into _4.0]_Wrong_timings_in_debug_plugin
laoneo Jun 9, 2023
91dddba
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Jun 12, 2023
2c1373f
fix
Denitz Jun 12, 2023
f0241da
short Event, try to re-start drone
Denitz Jun 13, 2023
48be548
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
laoneo Jun 29, 2023
18ca831
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Jul 13, 2023
880d983
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
laoneo Aug 17, 2023
aa4cd73
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
Denitz Aug 23, 2023
6a5d9ea
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
MacJoom Sep 8, 2023
d190f10
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
MacJoom Sep 9, 2023
31f19d4
Merge branch '4.4-dev' into _4.0]_Wrong_timings_in_debug_plugin
MacJoom Sep 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions plugins/system/debug/src/DataCollector/MemoryCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.Debug
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Plugin\System\Debug\DataCollector;

use Joomla\Plugin\System\Debug\AbstractDataCollector;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Collects info about the request duration as well as providing
* a way to log duration of any operations
*
* @since __DEPLOY_VERSION__
*/
class MemoryCollector extends AbstractDataCollector
{
/**
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $realUsage = false;

/**
* @var float
* @since __DEPLOY_VERSION__
*/
protected $peakUsage = 0;

/**
* @param Registry $params Parameters.
* @param float $peakUsage
* @param boolean $realUsage
*
* @since __DEPLOY_VERSION__
*/
public function __construct(Registry $params, $peakUsage = null, $realUsage = null)
{
parent::__construct($params);

if ($peakUsage !== null) {
$this->peakUsage = $peakUsage;
}

if ($realUsage !== null) {
$this->realUsage = $realUsage;
}
}

/**
* Returns whether total allocated memory page size is used instead of actual used memory size
* by the application. See $real_usage parameter on memory_get_peak_usage for details.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function getRealUsage()
{
return $this->realUsage;
}

/**
* Sets whether total allocated memory page size is used instead of actual used memory size
* by the application. See $real_usage parameter on memory_get_peak_usage for details.
*
* @param boolean $realUsage
*
* @since __DEPLOY_VERSION__
*/
public function setRealUsage($realUsage)
{
$this->realUsage = $realUsage;
}

/**
* Returns the peak memory usage
*
* @return integer
*
* @since __DEPLOY_VERSION__
*/
public function getPeakUsage()
{
return $this->peakUsage;
}

/**
* Updates the peak memory usage value
*
* @since __DEPLOY_VERSION__
*/
public function updatePeakUsage()
{
if ($this->peakUsage === null) {
$this->peakUsage = memory_get_peak_usage($this->realUsage);
}
}

/**
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function collect()
{
$this->updatePeakUsage();

return [
'peak_usage' => $this->peakUsage,
'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->peakUsage, 3),
];
}

/**
* @return string
*
* @since __DEPLOY_VERSION__
*/
public function getName()
{
return 'memory';
}

/**
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function getWidgets()
{
return [
'memory' => [
'icon' => 'cogs',
'tooltip' => 'Memory Usage',
'map' => 'memory.peak_usage_str',
'default' => "'0B'",
],
];
}
}
63 changes: 43 additions & 20 deletions plugins/system/debug/src/DataCollector/ProfileCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public function __construct(Registry $params)
* @param string|null $label Public name
* @param string|null $collector The source of the collector
*
* @since 4.0.0
* @return void
*
* @since 4.0.0
*/
public function startMeasure($name, $label = null, $collector = null)
{
Expand All @@ -103,8 +104,9 @@ public function startMeasure($name, $label = null, $collector = null)
*
* @param string $name Group name.
*
* @since 4.0.0
* @return bool
*
* @since 4.0.0
*/
public function hasStartedMeasure($name): bool
{
Expand All @@ -117,9 +119,11 @@ public function hasStartedMeasure($name): bool
* @param string $name Measurement name.
* @param array $params Parameters
*
* @return void
*
* @since 4.0.0
*
* @throws DebugBarException
* @return void
*/
public function stopMeasure($name, array $params = [])
{
Expand All @@ -129,13 +133,7 @@ public function stopMeasure($name, array $params = [])
throw new DebugBarException("Failed stopping measure '$name' because it hasn't been started");
}

$this->addMeasure(
$this->startedMeasures[$name]['label'],
$this->startedMeasures[$name]['start'],
$end,
$params,
$this->startedMeasures[$name]['collector']
);
$this->addMeasure($this->startedMeasures[$name]['label'], $this->startedMeasures[$name]['start'], $end, $params, $this->startedMeasures[$name]['collector']);

unset($this->startedMeasures[$name]);
}
Expand All @@ -149,8 +147,9 @@ public function stopMeasure($name, array $params = [])
* @param array $params Parameters.
* @param string|null $collector A collector.
*
* @since 4.0.0
* @return void
*
* @since 4.0.0
*/
public function addMeasure($label, $start, $end, array $params = [], $collector = null)
{
Expand All @@ -174,8 +173,9 @@ public function addMeasure($label, $start, $end, array $params = [], $collector
* @param \Closure $closure A closure.
* @param string|null $collector A collector.
*
* @since 4.0.0
* @return void
*
* @since 4.0.0
*/
public function measure($label, \Closure $closure, $collector = null)
{
Expand All @@ -189,8 +189,9 @@ public function measure($label, \Closure $closure, $collector = null)
/**
* Returns an array of all measures
*
* @since 4.0.0
* @return array
*
* @since 4.0.0
*/
public function getMeasures(): array
{
Expand All @@ -200,8 +201,9 @@ public function getMeasures(): array
/**
* Returns the request start time
*
* @since 4.0.0
* @return float
*
* @since 4.0.0
*/
public function getRequestStartTime(): float
{
Expand All @@ -211,8 +213,9 @@ public function getRequestStartTime(): float
/**
* Returns the request end time
*
* @since 4.0.0
* @return float
*
* @since 4.0.0
*/
public function getRequestEndTime(): float
{
Expand All @@ -222,8 +225,9 @@ public function getRequestEndTime(): float
/**
* Returns the duration of a request
*
* @since 4.0.0
* @return float
*
* @since 4.0.0
*/
public function getRequestDuration(): float
{
Expand All @@ -234,15 +238,32 @@ public function getRequestDuration(): float
return microtime(true) - $this->requestStartTime;
}

/**
* Sets request end time.
*
* @param float $time Request end time.
*
* @return $this
*
* @since __DEPLOY_VERSION__
*/
public function setRequestEndTime($time): self
{
$this->requestEndTime = $time;

return $this;
}

/**
* Called by the DebugBar when data needs to be collected
*
* @since 4.0.0
* @return array Collected data
*
* @since 4.0.0
*/
public function collect(): array
{
$this->requestEndTime = microtime(true);
$this->requestEndTime = $this->requestEndTime ?? microtime(true);

$start = $this->requestStartTime;

Expand Down Expand Up @@ -284,8 +305,9 @@ function ($a, $b) {
/**
* Returns the unique name of the collector
*
* @since 4.0.0
* @return string
*
* @since 4.0.0
*/
public function getName(): string
{
Expand All @@ -296,8 +318,9 @@ public function getName(): string
* Returns a hash where keys are control names and their values
* an array of options as defined in {@see \DebugBar\JavascriptRenderer::addControl()}
*
* @since 4.0.0
* @return array
*
* @since 4.0.0
*/
public function getWidgets(): array
{
Expand Down
Loading