diff options
author | Marcin Czołnowski <marcin@czolnowski.net> | 2014-12-03 19:20:18 +0300 |
---|---|---|
committer | Marcin Czołnowski <marcin@czolnowski.net> | 2014-12-03 19:20:18 +0300 |
commit | dd2d931e60124586e29b96d19b98b6b1b3ebd35b (patch) | |
tree | 28fedf8df767eacb2d378414f0c9eb269fd3594c /core | |
parent | c6a737bb0cfe6656288c39f1ff2d079354a7d21b (diff) |
Add debug log which print amount of used memory.
Diffstat (limited to 'core')
-rw-r--r-- | core/ArchiveProcessor/PluginsArchiver.php | 10 | ||||
-rw-r--r-- | core/Piwik.php | 33 |
2 files changed, 43 insertions, 0 deletions
diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php index e0618f8343..c12a79a239 100644 --- a/core/ArchiveProcessor/PluginsArchiver.php +++ b/core/ArchiveProcessor/PluginsArchiver.php @@ -14,6 +14,7 @@ use Piwik\ArchiveProcessor; use Piwik\DataAccess\ArchiveWriter; use Piwik\DataTable\Manager; use Piwik\Metrics; +use Piwik\Piwik; use Piwik\Plugin\Archiver; use Piwik\Log; @@ -101,6 +102,7 @@ class PluginsArchiver } if ($this->shouldProcessReportsForPlugin($pluginName)) { + $memoryUsageBeforePluginArchiving = memory_get_usage(true); if ($this->isSingleSiteDayArchive) { Log::debug("PluginsArchiver::%s: Archiving day reports for plugin '%s'.", __FUNCTION__, $pluginName); @@ -110,6 +112,14 @@ class PluginsArchiver $archiver->aggregateMultipleReports(); } + + $memoryUsageInArchiving = memory_get_usage(true) - $memoryUsageBeforePluginArchiving; + Log::debug("PluginsArchiver::%s: Used %s memory while archiving %s reports for plugin '%s'.", + __FUNCTION__, + Piwik::bytesToSize($memoryUsageInArchiving), + $this->isSingleSiteDayArchive ? 'day' : 'period', + $pluginName + ); } else { Log::debug("PluginsArchiver::%s: Not archiving reports for plugin '%s'.", __FUNCTION__, $pluginName); } diff --git a/core/Piwik.php b/core/Piwik.php index 625a7cf9f8..829ac1ec6c 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -765,4 +765,37 @@ class Piwik 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'; + } + } } |