protected function __construct() { if (Application::getProfiler()) { Benchmark::getInstance('router')->startTime()->startRam(); } Logger::getInstance()->addGroup('router', 'Router Benchmark and Informations', true); }
public function stop() { if ($this->_isInit && $this->_isRun) { // run caches gc $caches = Cache::getCaches(); foreach ($caches as $cache) { $cache->runGc(); } //profiling if (self::getProfiler()) { // Caches foreach ($caches as $cache) { Logger::getInstance()->debug('Adaptater : "' . get_class($cache) . '"', 'cache' . $cache->getName()); } // Databases $databases = Database::getDatabases(); foreach ($databases as $database) { Logger::getInstance()->debug('Type : ' . $database->getType(), 'database' . $database->getName()); Logger::getInstance()->debug('Adaptater : ' . get_class($database->getAdaptater()), 'database' . $database->getName()); $stats = $database->getStats(); Logger::getInstance()->debug('Queries : ' . (string) $database->getQueryCount() . ' (Aproximately memory used : ' . $stats['ram'] . ' KB in aproximately ' . $stats['time'] . ' ms)', 'database' . $database->getName()); Logger::getInstance()->debug('Servers : ' . $database->countServers() . ' (Masters : ' . $database->countServers(Server::TYPE_MASTER) . ' Slaves : ' . $database->countServers(Server::TYPE_SLAVE) . ')', 'database' . $database->getName()); } // Templates $templates = Template::getTemplates(); foreach ($templates as $template) { Logger::getInstance()->debug('Adaptater : ' . get_class($template), 'template' . $template->getName()); } // Language Logger::getInstance()->debug('Language default is : "' . Language::getInstance()->getDefaultLanguage() . '"', 'language'); Logger::getInstance()->debug(Language::getInstance()->countVars() . ' vars defined', 'language'); // Router Logger::getInstance()->debug('Current url : ' . Http::getCurrentUrl(), 'router'); Logger::getInstance()->debug('Current route : ' . Router::getInstance()->getCurrentRoute(), 'router'); Logger::getInstance()->debug('Current route rule : ' . Router::getInstance()->getCurrentRule(), 'router'); Logger::getInstance()->debug('Ajax request : ' . (int) Http::isAjax(), 'router'); Logger::getInstance()->debug('Ssl request : ' . (int) Http::isHttps(), 'router'); Logger::getInstance()->debug('Request dispatched in aproximately : ' . Benchmark::getInstance('router')->stopTime()->getStatsTime() . ' ms', 'router'); Logger::getInstance()->debug('Aproximately memory used : ' . Benchmark::getInstance('router')->stopRam()->getStatsRam() . ' KB', 'router'); // Logger debug informations and benchmark Logger::getInstance()->addGroup('logger', 'Logger Benchmark and Informations', true); Logger::getInstance()->debug(Logger::getInstance()->countObservers() . ' observers registered', 'logger'); Logger::getInstance()->debug(Logger::getInstance()->countGroups() . ' groups and ' . (Logger::getInstance()->countLogs() + 3) . ' logs', 'logger'); Logger::getInstance()->debug('In aproximately ' . Benchmark::getInstance('logger')->stopTime()->getStatsTime() . ' ms', 'logger'); Logger::getInstance()->debug('Aproximately memory used : ' . Benchmark::getInstance('logger')->stopRam()->getStatsRam() . ' KB', 'logger'); // Autoloader Logger::getInstance()->addGroup('autoloader', 'Autoloader report', true); $logs = Autoloader::getLogs(); foreach ($logs as &$log) { Logger::getInstance()->debug($log, 'autoloader'); } Logger::getInstance()->debug(count(Autoloader::getAutoloaders()) . ' autoloader adaptaters, ' . count(Autoloader::getDirectories()) . ' directories and ' . count(Autoloader::getNamespaces()) . ' namespaces registered', 'autoloader'); Logger::getInstance()->debug('Loading ' . count(Autoloader::getClasses()) . ' classes (' . Autoloader::countGlobalizedClasses() . ' globalized classes) in aproximately ' . round(Autoloader::getBenchmark('time') * 1000, 4) . ' ms', 'autoloader'); Logger::getInstance()->debug('Aproximately memory used : ' . round(Autoloader::getBenchmark('memory') / 1024, 4) . ' KB', 'autoloader'); Autoloader::purgeLogs(); Autoloader::purgeBenchmark(); // Global informations && Benchmark Logger::getInstance()->addGroup('global', 'Global Benchmark and Informations', true); Logger::getInstance()->debug('Page generated in aproximately : ' . Benchmark::getInstance('global')->stopTime()->getStatsTime() . ' ms', 'global'); Logger::getInstance()->debug('Aproximately memory used : ' . Benchmark::getInstance('global')->stopRam()->getStatsRam() . ' KB - Memory allocated : ' . memory_get_peak_usage(true) / 1024 . ' KB', 'global'); } //notify logger Logger::getInstance()->notify(); // Stop managers ExceptionManager::getInstance()->stop(); ErrorManager::getInstance()->stop(); // avoid multi call $this->_isInit = false; $this->_isRun = false; } }
protected function __construct() { $this->_observers = new \SplObjectStorage(); Benchmark::getInstance('logger')->startTime()->startRam(); }
public function logQuery($query, $params = array(), $bindParamType = null, $lastError = null) { if (!is_array($params)) { throw new \Exception('Params must be an array'); } // Query Logger::getInstance()->debug('Query : ' . $query, 'database' . $this->getName()); if (count($params) > 0) { // Parameters Logger::getInstance()->debug('Params (' . count($params) . ') bind by ' . $this->_getBindParamType($bindParamType), 'database' . $this->getName()); if ($bindParamType == self::PARAM_BIND_POSITIONAL) { $i = 0; } foreach ($params as &$param) { $key = $bindParamType == self::PARAM_BIND_POSITIONAL ? $i : $param['key']; Logger::getInstance()->debug('Key : ' . $key . ', Value : ' . $param['value'] . ', Type : ' . (int) $param['type'] . ' (' . self::$_paramTypeName[$param['type']] . '), IsParam : ' . (int) $param['isParam'], 'database' . $this->getName()); if ($bindParamType == self::PARAM_BIND_POSITIONAL) { $i++; } } } // Benchmark $time = Benchmark::getInstance($this->getName())->stopTime()->getStatsTime(); $ram = Benchmark::getInstance($this->getName())->stopRam()->getStatsRam(); Logger::getInstance()->debug('Benchmark time : ' . $time . ' ms Ram : ' . $ram, 'database' . $this->getName()); // Error if (!is_null($lastError)) { Logger::getInstance()->debug('Error : ' . $lastError, 'database' . $this->getName()); } // increment stats $this->setStats($time, $ram); $this->incrementQueryCount(); }
public function execute($checkBindNumber = true) { if (Application::getDebug()) { Benchmark::getInstance($this->_configName)->startTime()->startRam(); } if (is_null($this->_query) || !$this->_statement) { throw new \Exception('Prepare query before execute'); } if ($checkBindNumber) { if (count($this->_params) < $this->_paramsNumberNecesary) { throw new \Exception('Miss bind parameters'); } } // Bind parameters $i = 0; foreach ($this->_params as $param) { $bindName = $this->_bindParamType === Database::PARAM_BIND_POSITIONAL ? $i + 1 : ':' . $this->_namedParamOrder[$i]; if ($param['isParam']) { $this->_statement->bindParam($bindName, $param['value'], $param['type']); } else { $this->_statement->bindValue($bindName, $param['value'], $param['type']); } $i++; } // Execute $this->_execute = $this->_statement->execute(); //check error $lastError = $this->getLastError(true); if (!is_null($lastError)) { Logger::getInstance()->error('Sql query : ' . $this->_query . ' has error : ' . $lastError); } // Debug if (Application::getDebug()) { Database::getDatabase($this->_configName)->logQuery($this->_query, $this->_params, $this->_bindParamType, $lastError); } return $this->_execute; }