Skip to content

Commit

Permalink
Refactor to reuse Piwik components.
Browse files Browse the repository at this point in the history
  • Loading branch information
czolnowski committed Dec 4, 2014
1 parent dd2d931 commit ba8640b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
11 changes: 5 additions & 6 deletions core/ArchiveProcessor/PluginsArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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 {
Expand Down
33 changes: 0 additions & 33 deletions core/Piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}

0 comments on commit ba8640b

Please sign in to comment.