From 1181f7da01538dd95087b1d9da47214439cbbc41 Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Tue, 31 Jul 2018 11:21:48 +0400 Subject: [PATCH 1/2] add subdef building duration in task log --- lib/Alchemy/Phrasea/Media/SubdefGenerator.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index 94631fd03d..eb1db11777 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -169,6 +169,8 @@ class SubdefGenerator private function generateSubdef(\record_adapter $record, \databox_subdef $subdef_class, $pathdest) { + $start = microtime(true); + try { if (null === $record->get_hd_file()) { $this->logger->info('No HD file found, aborting'); @@ -203,8 +205,24 @@ class SubdefGenerator } } catch (MediaAlchemystException $e) { + $start = 0; $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage())); } + + $stop = microtime(true); + if($start){ + $duration = $stop - $start; + + $this->logger->info(sprintf('Subdef %s generated, duration = %s / sbasid=%s / databox=%s / recordid=%s', + $subdef_class->get_name(), + date('H:i:s', $duration), + $record->getDatabox()->get_sbas_id(), + $record->getDatabox()->get_dbname(), + $record->getRecordId() + ) + ); + } + } private function generatePdfSubdef($source, $pathdest) From 57a8612e92c1e030618798be8509c7b92269959c Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Thu, 9 Aug 2018 16:08:15 +0400 Subject: [PATCH 2/2] add duration and file size --- lib/Alchemy/Phrasea/Media/SubdefGenerator.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index eb1db11777..842a437a65 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -213,9 +213,15 @@ class SubdefGenerator if($start){ $duration = $stop - $start; - $this->logger->info(sprintf('Subdef %s generated, duration = %s / sbasid=%s / databox=%s / recordid=%s', + $originFileSize = $this->sizeHumanReadable($record->get_hd_file()->getSize()); + $generatedFileSize = $this->sizeHumanReadable(filesize($pathdest)); + + $this->logger->info(sprintf('*** Generated *** %s , duration=%s / source size=%s / %s size=%s / sbasid=%s / databox=%s / recordid=%s', $subdef_class->get_name(), - date('H:i:s', $duration), + date('H:i:s', mktime(0,0, $duration)), + $originFileSize, + $subdef_class->get_name(), + $generatedFileSize, $record->getDatabox()->get_sbas_id(), $record->getDatabox()->get_dbname(), $record->getRecordId() @@ -249,4 +255,9 @@ class SubdefGenerator } } + + private function sizeHumanReadable($bytes) { + $i = floor(log($bytes, 1024)); + return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','kB','MB','GB'][$i]; + } }