BMLT Root Server
Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
bdfProfiler Class Reference

Execution time/memory profiling class. More...

Static Public Member Functions

static mark ($msg=null)
 Marks a time. More...
 
static profile ()
 Returns profiling information as an array. More...
 
static output ($in_html=false)
 Return formatted profile information. More...
 
static html_output ()
 Return formatted profile information in HTML form. More...
 

Private Member Functions

 __construct ()
 Private constructor prevents direct creation of object. More...
 

Static Private Attributes

static $marks = array()
 This is an array that holds the markers. More...
 

Detailed Description

Execution time/memory profiling class.

This is a modification of the Solar_Debug_Timer class

Author
Paul M. Jones pmjon.nosp@m.es@s.nosp@m.olarp.nosp@m.hp.c.nosp@m.om

Singleton class accessed via static methods

Example:

Definition at line 458 of file comdef_utilityclasses.inc.php.

Constructor & Destructor Documentation

__construct ( )
private

Private constructor prevents direct creation of object.

Definition at line 467 of file comdef_utilityclasses.inc.php.

468  {
469  }

Member Function Documentation

static html_output ( )
static

Return formatted profile information in HTML form.

Returns
a string, containing an HTML table element with a series of rows; each containing the profile information for a marker. The table's class is "bdfProfiler_table".

Definition at line 548 of file comdef_utilityclasses.inc.php.

References sprintf().

549  {
550  //phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
551  $output = '<table class="bdfProfiler_table" cellpadding="0" cellspacing="0" summary="Profiling Information Report">';
552  $output .= '<thead><tr><td>Num</td><td>Diff/sec</td><td>Total/sec</td><td>Memory</td><td>Msg</td></tr></thead><tbody>';
553 
554  $profile = self::profile();
555 
556  foreach ($profile as $value) {
557  $output .= sprintf("<tr><td>%3.3s</td><td>%10F</td><td>%10F</td><td>%10d</td><td>%-500.500s</td></tr>", $value['num'], $value['diff'], $value['total'], $value['memory'], $value['msg']);
558  }
559 
560  $output .= '</tbody></table>';
561 
562  return $output;
563  }
function sprintf()
Definition: installer.js:873
static mark (   $msg = null)
static

Marks a time.

Parameters
$msgOptional string. A message to be displayed for this marker.

Definition at line 474 of file comdef_utilityclasses.inc.php.

476  {
477  // If possible, we see how the memory is being used.
478  if (function_exists('memory_get_usage')) {
479  $mem = memory_get_usage();
480  } else {
481  $mem = '-';
482  }
483  array_push(self::$marks, array('time' => microtime(true), 'memory' => $mem, 'msg' => $msg));
484  }
static output (   $in_html = false)
static

Return formatted profile information.

Returns
a string, with a series of tab-delimited lines; each containing the profile information for a marker.
Parameters
$in_htmlIf true, the output is html. Default is false.

Definition at line 523 of file comdef_utilityclasses.inc.php.

References sprintf().

525  {
526  if ($in_html) {
527  $output = self::html_output();
528  } else {
529  $output = sprintf("%-3.3s\t%10.10s\t%10.10s\t%10.10s\t%-500.500s\n", 'Num', 'Diff/sec', 'Total/sec', 'Memory', 'Msg');
530  $output .= sprintf("%-'-3.3s\t%'-10.10s\t%'-10.10s\t%'-10.10s\t%-'-500.500s\n", '', '', '', '', '');
531 
532  $profile = self::profile();
533 
534  foreach ($profile as $value) {
535  $output .= sprintf("%3.3s\t%10F\t%10F\t%10d\t%-500.500s\n", $value['num'], $value['diff'], $value['total'], $value['memory'], $value['msg']);
536  }
537  }
538 
539  return $output;
540  }
function sprintf()
Definition: installer.js:873
static profile ( )
static

Returns profiling information as an array.

Returns
an array of associative arrays that contain the profiling information. Each sub-array represents the information from one marker.
  • 'num' An integer. The marker ID number
  • 'diff' A floating-point number. The number of seconds (at a millisecond resolution) between the last marker and this one.
  • 'total' A floating-point number. The total number of seconds (at a millisecond resolution) since the start marker.
  • 'memory' If possible, the memory consumption at the marker's point in execution.
  • 'msg' Any text message that was associated with the marker.

Definition at line 496 of file comdef_utilityclasses.inc.php.

497  {
498  $diff = 0;
499  $prev = 0;
500  $total = 0;
501  $result = array();
502 
503  foreach (self::$marks as $k => $v) {
504  if ($prev > 0) {
505  $diff = $v['time'] - $prev;
506  }
507 
508  $total = $total + $diff;
509 
510  $result[] = array ( 'num' => $k, 'diff' => $diff, 'total' => $total, 'memory' => $v['memory'], 'msg' => $v['msg'] );
511 
512  $prev = $v['time'];
513  }
514 
515  return $result;
516  }

Member Data Documentation

$marks = array()
staticprivate

This is an array that holds the markers.

Definition at line 462 of file comdef_utilityclasses.inc.php.


The documentation for this class was generated from the following file: