From c3f11a4c66198156c81c265fcac1692c54987da1 Mon Sep 17 00:00:00 2001 From: xinatorus Date: Fri, 22 May 2020 22:15:49 +0200 Subject: [PATCH] Debugger --- app/Bootstrap.php | 25 +++++++++--------- library/Debugger.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ library/Router.php | 1 + 3 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 library/Debugger.php diff --git a/app/Bootstrap.php b/app/Bootstrap.php index 90828b0..7bdade6 100644 --- a/app/Bootstrap.php +++ b/app/Bootstrap.php @@ -1,6 +1,11 @@ load(); -} - +Debugger::flag('dbconnect'); //D B Conector Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); -// TODO: Přesunout do Login Pohledu -$userManager = new UserManager(); - +Debugger::flag('routes'); // import routes require_once '../app/Routes.php'; + +Debugger::flag('done'); +// echo Debugger::showFlags(false); diff --git a/library/Debugger.php b/library/Debugger.php new file mode 100644 index 0000000..204a66b --- /dev/null +++ b/library/Debugger.php @@ -0,0 +1,63 @@ + microtime(true), + 'stop' => 0 + ); + } + + public static function trackStop ($key){ + self::$tracker[$key]['stop'] = microtime(true); + } + + public static function showTracker(){ + $ret = ''; + + foreach(self::$tracker as $key => $track){ + $ret .= $key.': '.number_format($track['stop']-$track['start'], 4, '.', ' ') .' ms
'; + } + + return $ret; + } + + public static function flag ($text) { + $flag = array( + 'time' => microtime(true)*1000, + 'flag' => $text + ); + self::$flags[] = $flag; + } + + public static function showFlags($asHtml = true){ + $ret = ''; + $nl = $asHtml ? "
\n": "\n"; + + $size = count(self::$flags); + for($i=0; $i<$size - 1; $i++){ + $ret .= self::$flags[$i]['flag']; + $ret .= '-'; + $ret .= self::$flags[$i+1]['flag']; + $ret .= ' '. number_format(self::$flags[$i+1]['time'] - self::$flags[$i]['time'], 0, '.', ' ') .' ms'; + $ret .= $nl; + } + if($size > 1){ + $ret .= 'TOTAL: '.number_format(self::$flags[$size-1]['time'] - self::$flags[0]['time'], 0, '.' ,' ') .' ms'; + } + return $ret; + } + + public static function debug($backtrace){ + self::$backtrace = $backtrace; + } + + public static function showDebug(){ + return self::$backtrace; + } +} +?> diff --git a/library/Router.php b/library/Router.php index cced691..127ee3d 100644 --- a/library/Router.php +++ b/library/Router.php @@ -60,6 +60,7 @@ class Router{ } if($this->function !== NULL){ + Debugger::flag('execution'); if(is_string($this->function)){ if(strpos($this->function, '@') !== false){ list($class, $function) = explode('@', $this->function);