diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php index c12a79a239e..74871287280 100644 --- a/core/ArchiveProcessor/PluginsArchiver.php +++ b/core/ArchiveProcessor/PluginsArchiver.php @@ -14,9 +14,9 @@ use Piwik\DataAccess\ArchiveWriter; use Piwik\DataTable\Manager; use Piwik\Metrics; -use Piwik\Piwik; use Piwik\Plugin\Archiver; use Piwik\Log; +use Piwik\Timer; /** * This class creates the Archiver objects found in plugins and will trigger aggregation, @@ -102,7 +102,7 @@ public function callAggregateAllPlugins($visits, $visitsConverted) } if ($this->shouldProcessReportsForPlugin($pluginName)) { - $memoryUsageBeforePluginArchiving = memory_get_usage(true); + $timer = new Timer(); if ($this->isSingleSiteDayArchive) { Log::debug("PluginsArchiver::%s: Archiving day reports for plugin '%s'.", __FUNCTION__, $pluginName); @@ -113,11 +113,10 @@ public function callAggregateAllPlugins($visits, $visitsConverted) $archiver->aggregateMultipleReports(); } - $memoryUsageInArchiving = memory_get_usage(true) - $memoryUsageBeforePluginArchiving; - Log::debug("PluginsArchiver::%s: Used %s memory while archiving %s reports for plugin '%s'.", + Log::debug("PluginsArchiver::%s: %s while archiving %s reports for plugin '%s'.", __FUNCTION__, - Piwik::bytesToSize($memoryUsageInArchiving), - $this->isSingleSiteDayArchive ? 'day' : 'period', + $timer->getMemoryLeak(), + $this->params->getPeriod()->getLabel(), $pluginName ); } else { diff --git a/core/Piwik.php b/core/Piwik.php index 829ac1ec6c8..625a7cf9f8f 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -765,37 +765,4 @@ public static function doAsSuperUser($function) return $result; } - - /** - * Convert bytes to human readable format - * - * @param int $bytes Size in bytes to convert - * @param int $precision Precision value, default 2. - * @return string - */ - public static function bytesToSize($bytes, $precision = 2) - { - $kilobyte = 1024; - $megabyte = $kilobyte * 1024; - $gigabyte = $megabyte * 1024; - $terabyte = $gigabyte * 1024; - - if (($bytes >= 0) && ($bytes < $kilobyte)) { - return $bytes . ' B'; - - } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { - return round($bytes / $kilobyte, $precision) . ' KB'; - - } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { - return round($bytes / $megabyte, $precision) . ' MB'; - - } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { - return round($bytes / $gigabyte, $precision) . ' GB'; - - } elseif ($bytes >= $terabyte) { - return round($bytes / $terabyte, $precision) . ' TB'; - } else { - return $bytes . ' B'; - } - } }