tippspiel/pfosten/app/MyClasses/TimeLogger.php

44 lines
No EOL
966 B
PHP

<?php
namespace App\MyClasses;
/* USAGE IN CLASS
--START OF FILE
use App\MyClasses\TimeLogger;
--START OF METHOD
$a=new TimeLogger("method XXX start");
Log::info($a->getStartMessage());
--END OF METHOD
Log::info($a->getEndMessage());
*/
class TimeLogger
{
public $startTime;
public $pkey;
public $functionName;
public function __construct($_functionName) {
$this->startTime = microtime(true);
$this->functionName =$_functionName;
$this->pkey="".rand(1000,9999);
}
public function getStartMessage() {
return "[CLOCK] [".$this->pkey."-".$this->functionName."] [started]";
}
public function getEndMessage() {
$time= ( microtime(true) - $this->startTime);
$timestr=number_format( $time, 4);
$retval="[CLOCK] [".$this->pkey."-". $this->functionName."] [ended] [elapsed: ".$timestr."]";
if ($time > 1.5) {
$retval=$retval." [PERFORMANCE_WARNING]";
}
return $retval;
}
}