| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Counter |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
* @version 4.5.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace MainWP\Dashboard; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class MainWP_Execution_Helper |
| 13 |
* |
| 14 |
* @package MainWP\Dashboard |
| 15 |
*/ |
| 16 |
class MainWP_Execution_Helper { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 17 |
|
| 18 |
|
| 19 |
/** |
| 20 |
* Private variable to hold time start. |
| 21 |
* |
| 22 |
* @var int |
| 23 |
*/ |
| 24 |
private static $exec_start = null; |
| 25 |
|
| 26 |
/** |
| 27 |
* Private static varibale to hold the instance. |
| 28 |
* |
| 29 |
* @var mixed Default null |
| 30 |
*/ |
| 31 |
public static $instance = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* Method instance() |
| 35 |
* |
| 36 |
* Returns new MainWP_Logger instance. |
| 37 |
* |
| 38 |
* @return self MainWP_Logger |
| 39 |
* |
| 40 |
* @uses \MainWP\Dashboard\MainWP_Logger |
| 41 |
*/ |
| 42 |
public static function instance() { |
| 43 |
if ( null === static::$instance ) { |
| 44 |
static::$instance = new self(); |
| 45 |
} |
| 46 |
return static::$instance; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* MainWP_Logger constructor. |
| 51 |
* |
| 52 |
* Run each time the class is called. |
| 53 |
*/ |
| 54 |
public function __construct() { |
| 55 |
if ( null === static::$exec_start ) { |
| 56 |
static::$exec_start = microtime( true ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Method init_exec_time(). |
| 62 |
* |
| 63 |
* Init execution time start value. |
| 64 |
*/ |
| 65 |
public function init_exec_time() { |
| 66 |
if ( null === static::$exec_start ) { |
| 67 |
static::$exec_start = microtime( true ); |
| 68 |
} |
| 69 |
MainWP_Logger::instance()->init_execution_time(); // compatible. |
| 70 |
return static::$exec_start; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Method get_exec_time(). |
| 75 |
* |
| 76 |
* Get execution time start value. |
| 77 |
*/ |
| 78 |
public function get_exec_time() { |
| 79 |
if ( null === static::$exec_start ) { |
| 80 |
static::$exec_start = microtime( true ); |
| 81 |
} |
| 82 |
|
| 83 |
$sec = microtime( true ) - static::$exec_start; // seconds. |
| 84 |
MainWP_Logger::instance()->log_action( 'execution time :: [value=' . round( $sec, 4 ) . '](seconds)', MainWP_Logger::EXECUTION_TIME_LOG_PRIORITY ); |
| 85 |
return $sec; |
| 86 |
} |
| 87 |
} |
| 88 |
|