Skip to content

Commit 54e24bc

Browse files
committed
Added current mailbox runtime in seconds to debug mode when show memory usage is enabled
Changed errors formatting
1 parent e010573 commit 54e24bc

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

core/Mail/Parser.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ERP_Mail_Parser
1212
private $_debug = FALSE;
1313
private $_show_mem_usage = FALSE;
1414
private $_memory_limit = FALSE;
15+
private $_mailbox_starttime = NULL;
1516

1617
private $_file;
1718
private $_content;
@@ -52,12 +53,13 @@ class ERP_Mail_Parser
5253
'us-ascii' => 'ASCII',
5354
);
5455

55-
public function __construct( $options )
56+
public function __construct( $options, $mailbox_starttime )
5657
{
5758
$this->_parse_html = $options[ 'parse_html' ];
5859
$this->_add_attachments = $options[ 'add_attachments' ];
5960
$this->_debug = $options[ 'debug' ];
6061
$this->_show_mem_usage = $options[ 'show_mem_usage' ];
62+
$this->_mailbox_starttime = $mailbox_starttime;
6163

6264
$this->prepare_mb_list_encodings();
6365

@@ -539,12 +541,14 @@ private function show_memory_usage( $p_location )
539541
{
540542
if ( $this->_debug && $this->_show_mem_usage )
541543
{
544+
$t_current_runtime = ( ( $this->_mailbox_starttime !== NULL ) ? round( ERP_get_timestamp() - $this->_mailbox_starttime, 4 ) : 0 );
542545
echo 'Debug output memory usage' . "\n" .
543546
'Location: Mail Parser - ' . $p_location . "\n" .
547+
'Runtime in seconds: ' . $t_current_runtime . "\n" .
544548
'Current memory usage: ' . ERP_formatbytes( memory_get_usage( FALSE ) ) . ' / ' . $this->_memory_limit . "\n" .
545549
'Peak memory usage: ' . ERP_formatbytes( memory_get_peak_usage( FALSE ) ) . ' / ' . $this->_memory_limit . "\n" .
546550
'Current real memory usage: ' . ERP_formatbytes( memory_get_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n" .
547-
'Peak real memory usage: ' . ERP_formatbytes( memory_get_peak_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n";
551+
'Peak real memory usage: ' . ERP_formatbytes( memory_get_peak_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n\n";
548552
}
549553
}
550554
}

core/mail_api.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ERP_mailbox_api
2727
{
2828
private $_functionality_enabled = FALSE;
2929
private $_test_only = FALSE;
30+
private $_mailbox_starttime = NULL;
3031

3132
public $_mailbox = array( 'description' => 'INITIALIZATION PHASE' );
3233

@@ -166,6 +167,8 @@ public function __construct( $p_test_only = FALSE )
166167
# return a boolean for whether the mailbox was successfully processed
167168
public function process_mailbox( $p_mailbox )
168169
{
170+
$this->_mailbox_starttime = ERP_get_timestamp();
171+
169172
$this->_mailbox = $p_mailbox + ERP_get_default_mailbox();
170173

171174
if ( $this->_functionality_enabled )
@@ -217,6 +220,7 @@ public function process_mailbox( $p_mailbox )
217220
if ( !$this->_test_only && $this->_mail_debug )
218221
{
219222
var_dump( $this->_mailbox );
223+
echo "\n";
220224
}
221225

222226
$this->show_memory_usage( 'Start process mailbox' );
@@ -263,7 +267,7 @@ private function pear_error( $p_location, &$p_pear )
263267

264268
if ( !$this->_test_only )
265269
{
266-
echo "\n\n" . 'Mailbox: ' . $this->_mailbox[ 'description' ] . "\n" . 'Location: ' . $p_location . "\n" . $p_pear->toString() . "\n";
270+
echo 'Mailbox: ' . $this->_mailbox[ 'description' ] . "\n" . 'Location: ' . $p_location . "\n" . $p_pear->toString() . "\n\n";
267271
}
268272

269273
return( TRUE );
@@ -291,7 +295,7 @@ private function custom_error( $p_error_text, $p_is_error = TRUE )
291295

292296
if ( !$this->_test_only )
293297
{
294-
echo "\n\n" . 'Mailbox: ' . $this->_mailbox[ 'description' ] . "\n" . $t_error_text;
298+
echo 'Mailbox: ' . $this->_mailbox[ 'description' ] . "\n" . $t_error_text . "\n\n";
295299
}
296300
}
297301

@@ -593,7 +597,7 @@ private function parse_content( &$p_msg )
593597
{
594598
$this->show_memory_usage( 'Start Mail Parser' );
595599

596-
$t_mp = new ERP_Mail_Parser( $this->_mp_options );
600+
$t_mp = new ERP_Mail_Parser( $this->_mp_options, $this->_mailbox_starttime );
597601

598602
$t_mp->setInputString( $p_msg );
599603

@@ -1492,12 +1496,14 @@ private function show_memory_usage( $p_location )
14921496
{
14931497
if ( !$this->_test_only && $this->_mail_debug && $this->_mail_debug_show_memory_usage )
14941498
{
1499+
$t_current_runtime = ( ( $this->_mailbox_starttime !== NULL ) ? round( ERP_get_timestamp() - $this->_mailbox_starttime, 4 ) : 0 );
14951500
echo 'Debug output memory usage' . "\n" .
14961501
'Location: Mail API - ' . $p_location . "\n" .
1502+
'Runtime in seconds: ' . $t_current_runtime . "\n" .
14971503
'Current memory usage: ' . ERP_formatbytes( memory_get_usage( FALSE ) ) . ' / ' . $this->_memory_limit . "\n" .
14981504
'Peak memory usage: ' . ERP_formatbytes( memory_get_peak_usage( FALSE ) ) . ' / ' . $this->_memory_limit . "\n" .
14991505
'Current real memory usage: ' . ERP_formatbytes( memory_get_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n" .
1500-
'Peak real memory usage: ' . ERP_formatbytes( memory_get_peak_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n";
1506+
'Peak real memory usage: ' . ERP_formatbytes( memory_get_peak_usage( TRUE ) ) . ' / ' . $this->_memory_limit . "\n\n";
15011507
}
15021508
}
15031509

@@ -1624,4 +1630,13 @@ function ERP_formatbytes( $p_bytes )
16241630

16251631
return( round( $t_bytes, 2 ) . $t_units[ $i ] );
16261632
}
1633+
1634+
# --------------------
1635+
# Returns the current timestamp
1636+
function ERP_get_timestamp()
1637+
{
1638+
$t_time = explode( ' ', microtime() );
1639+
return( $t_time[1] + $t_time[0] );
1640+
}
1641+
16271642
?>

doc/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Jun 2016 - EmailReporting-0.9.2-DEV
44
- Modified the user option list to also check user accessible projects
55
- Show missing user id behind the error in the user option list
66
- user_is_realname_valid function does not exist in MantisBT 1.3.x
7+
- Changed errors formatting
8+
- Added current mailbox runtime in seconds to debug mode when show memory usage is enabled
79

810
May 2016 - EmailReporting-0.9.1
911
- Modified error message incase no valid reporter could be found

0 commit comments

Comments
 (0)