本文整理汇总了PHP中Magento\Framework\Profiler类的典型用法代码示例。如果您正苦于以下问题:PHP Profiler类的具体用法?PHP Profiler怎么用?PHP Profiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Returns block content depends on ajax request
*
* @return void
*/
public function execute()
{
if (!$this->getRequest()->isAjax()) {
$this->_forward('noroute');
return;
}
// disable profiling during private content handling AJAX call
\Magento\Framework\Profiler::reset();
$currentRoute = $this->getRequest()->getRouteName();
$currentControllerName = $this->getRequest()->getControllerName();
$currentActionName = $this->getRequest()->getActionName();
$currentRequestUri = $this->getRequest()->getRequestUri();
$origRequest = $this->getRequest()->getParam('originalRequest');
$origRequest = json_decode($origRequest, true);
$this->getRequest()->setRouteName($origRequest['route']);
$this->getRequest()->setControllerName($origRequest['controller']);
$this->getRequest()->setActionName($origRequest['action']);
$this->getRequest()->setRequestUri($origRequest['uri']);
/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
$blocks = $this->_getBlocks();
$data = [];
foreach ($blocks as $blockName => $blockInstance) {
$data[$blockName] = $blockInstance->toHtml();
}
$this->getRequest()->setRouteName($currentRoute);
$this->getRequest()->setControllerName($currentControllerName);
$this->getRequest()->setActionName($currentActionName);
$this->getRequest()->setRequestUri($currentRequestUri);
$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
$this->translateInline->processResponseBody($data);
$this->getResponse()->appendBody(json_encode($data));
}
示例2: logStats
/**
*
* {@inheritdoc}
*/
public function logStats($type, $sql, $bind = [], $result = null)
{
$log = [];
//Change approach to "around" and then break return string into MySQL columns
// as right now we cannot get time of query execution
//Problem remains how to pass the YES/NO on time and full backtrace
// maybe its best to simply record all and then remove it from __destruct
// as in __destruct we have access to helper
// trace log and all log simply kill the database size, thus we need them as config
self::$counter++;
\Magento\Framework\Profiler::start('foggyline_sentinel_logStats_' . self::$counter);
$log['type'] = $type;
$log['time'] = sprintf('%.4f', microtime(true) - $this->timer);
$log['sql'] = $sql;
$log['bind'] = var_export($bind, true);
if ($result instanceof \Zend_Db_Statement_Pdo) {
$log['row_count'] = $result->rowCount();
}
/**
* When backtrace is assigned, it consumes roughly:
* - 0.3 seconds on homepage,
* - 0.5 seconds on admin product page
*
* Problem here is that we cannot control Debug::backtrace via Magento admin config, so we have to leave it
* either running or comment it out. If we leave it running, we can add some minor tome to overhead but we
* can then use $this->helper->getQueryLogCallStack(); to either save it in database or not.
*
* Backtrace adds enormous amount of data to database. We are talking MB of data just in 3-4 page requests.
* Thus it is highly important be very careful with full log stack (backtrace) loging to dataabse.
*/
$log['backtrace'] = \Magento\Framework\Debug::backtrace(true, false);
$this->queryLogs[] = $log;
\Magento\Framework\Profiler::stop('foggyline_sentinel_logStats_' . self::$counter);
}
示例3: execute
public function execute()
{
$resultPage = $this->resultPageFactory->create();
\Magento\Framework\Profiler::start('foggyline:office');
$this->logger->log(\Monolog\Logger::DEBUG, 'debug msg');
$this->logger->log(\Monolog\Logger::INFO, 'info msg');
$this->logger->log(\Monolog\Logger::NOTICE, 'notice msg');
$this->logger->log(\Monolog\Logger::WARNING, 'warning msg');
$this->logger->log(\Monolog\Logger::ERROR, 'error msg');
$this->logger->log(\Monolog\Logger::CRITICAL, 'critical msg');
$this->logger->log(\Monolog\Logger::ALERT, 'alert msg');
$this->logger->log(\Monolog\Logger::EMERGENCY, 'emergency msg');
$this->logger->debug('debug msg');
$this->logger->info('info msg');
$this->logger->notice('notice msg');
$this->logger->warning('warning msg');
$this->logger->error('error msg');
$this->logger->critical('critical msg');
$this->logger->alert('alert msg');
$this->logger->emergency('emergency msg');
sleep(2);
/* code block or single expression here */
\Magento\Framework\Profiler::stop('foggyline:office');
return $resultPage;
}
示例4: _registerDriver
/**
* Register profiler driver to involve it into the results processing
*/
protected function _registerDriver()
{
if (!$this->_isDriverRegistered) {
$this->_isDriverRegistered = true;
\Magento\Framework\Profiler::add($this->_driver);
}
}
示例5: _toHtml
/**
* Get html code
*
* @return string
*/
protected function _toHtml()
{
/* @var $template \Magento\Newsletter\Model\Template */
$template = $this->_templateFactory->create();
if ($id = (int) $this->getRequest()->getParam('id')) {
$template->load($id);
} else {
$template->setTemplateType($this->getRequest()->getParam('type'));
$template->setTemplateText($this->getRequest()->getParam('text'));
$template->setTemplateStyles($this->getRequest()->getParam('styles'));
}
$storeId = (int) $this->getRequest()->getParam('store_id');
if (!$storeId) {
$storeId = $this->_storeManager->getDefaultStoreView()->getId();
}
\Magento\Framework\Profiler::start("newsletter_template_proccessing");
$vars = array();
$vars['subscriber'] = $this->_subscriberFactory->create();
if ($this->getRequest()->getParam('subscriber')) {
$vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
}
$template->emulateDesign($storeId);
$templateProcessed = $this->_appState->emulateAreaCode(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, array($template, 'getProcessedTemplate'), array($vars, true));
$template->revertDesign();
if ($template->isPlain()) {
$templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
}
\Magento\Framework\Profiler::stop("newsletter_template_proccessing");
return $templateProcessed;
}
示例6: _toHtml
/**
* Prepare html output
*
* @return string
*/
protected function _toHtml()
{
/** @var $template \Magento\Email\Model\Template */
$template = $this->_emailFactory->create(['data' => ['area' => \Magento\Framework\App\Area::AREA_FRONTEND]]);
$id = (int) $this->getRequest()->getParam('id');
if ($id) {
$template->load($id);
} else {
$template->setTemplateType($this->getRequest()->getParam('type'));
$template->setTemplateText($this->getRequest()->getParam('text'));
$template->setTemplateStyles($this->getRequest()->getParam('styles'));
}
$template->setTemplateText($this->_maliciousCode->filter($template->getTemplateText()));
\Magento\Framework\Profiler::start("email_template_proccessing");
$vars = [];
$store = $this->getAnyStoreView();
$storeId = $store ? $store->getId() : null;
$template->setDesignConfig(['area' => $this->_design->getArea(), 'store' => $storeId]);
$templateProcessed = $template->getProcessedTemplate($vars, true);
if ($template->isPlain()) {
$templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
}
\Magento\Framework\Profiler::stop("email_template_proccessing");
return $templateProcessed;
}
示例7: dispatch
/**
* Perform action and generate response
*
* @param RequestInterface $request
* @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \LogicException
*/
public function dispatch(RequestInterface $request)
{
\Magento\Framework\Profiler::start('routers_match');
$routingCycleCounter = 0;
$result = null;
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
/** @var \Magento\Framework\App\RouterInterface $router */
foreach ($this->_routerList as $router) {
try {
$actionInstance = $router->match($request);
if ($actionInstance) {
$request->setDispatched(true);
$this->response->setNoCacheHeaders();
if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
$result = $actionInstance->dispatch($request);
} else {
$result = $actionInstance->execute();
}
break;
}
} catch (\Magento\Framework\Exception\NotFoundException $e) {
$request->initForward();
$request->setActionName('noroute');
$request->setDispatched(false);
break;
}
}
}
\Magento\Framework\Profiler::stop('routers_match');
if ($routingCycleCounter > 100) {
throw new \LogicException('Front controller reached 100 router match iterations');
}
return $result;
}
示例8: _toHtml
/**
* Get html code
*
* @return string
*/
protected function _toHtml()
{
/* @var $template \Magento\Newsletter\Model\Template */
$template = $this->_templateFactory->create();
if ($id = (int) $this->getRequest()->getParam('id')) {
$this->loadTemplate($template, $id);
} else {
$previewData = $this->getPreviewData();
$template->setTemplateType($previewData['type']);
$template->setTemplateText($previewData['text']);
$template->setTemplateStyles($previewData['styles']);
}
\Magento\Framework\Profiler::start($this->profilerName);
$vars = [];
$vars['subscriber'] = $this->_subscriberFactory->create();
if ($this->getRequest()->getParam('subscriber')) {
$vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
}
$template->emulateDesign($this->getStoreId());
$templateProcessed = $this->_appState->emulateAreaCode(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, [$template, 'getProcessedTemplate'], [$vars]);
$template->revertDesign();
if ($template->isPlain()) {
$templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
}
\Magento\Framework\Profiler::stop($this->profilerName);
return $templateProcessed;
}
示例9: applyRewrites
/**
* Apply rewrites to current request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return void
*/
public function applyRewrites(\Magento\Framework\App\RequestInterface $request)
{
// URL rewrite
if (!$request->isStraight()) {
\Magento\Framework\Profiler::start('db_url_rewrite');
/** @var $urlRewrite \Magento\UrlRewrite\Model\UrlRewrite */
$urlRewrite = $this->_rewriteFactory->create();
$urlRewrite->rewrite($request);
\Magento\Framework\Profiler::stop('db_url_rewrite');
}
}
示例10: query
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*
* {@inheritdoc}
*/
public function query(RequestInterface $request)
{
\Magento\Framework\Profiler::start('ES:Execute Search Query');
try {
$searchResponse = $this->doSearch($request);
} catch (\Exception $e) {
$searchResponse = [];
$this->logger->error($e->getMessage());
}
\Magento\Framework\Profiler::stop('ES:Execute Search Query');
return $this->responseFactory->create(['searchResponse' => $searchResponse]);
}
示例11: dispatch
/**
* Perform action and generate response
*
* @param RequestInterface $request
* @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \LogicException
*/
public function dispatch(RequestInterface $request)
{
\Magento\Framework\Profiler::start('routers_match');
$routingCycleCounter = 0;
$result = null;
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
$result = $this->processRequest($request);
}
\Magento\Framework\Profiler::stop('routers_match');
if ($routingCycleCounter > 100) {
throw new \LogicException('Front controller reached 100 router match iterations');
}
return $result;
}
示例12: setUp
protected function setUp()
{
$this->_eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
$this->_actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
$this->_redirectMock = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface', [], [], '', false);
$this->_requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
$this->_responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false);
$this->pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', ['getConfig'], [], '', false);
$this->viewMock = $this->getMock('Magento\\Framework\\App\\ViewInterface');
$this->viewMock->expects($this->any())->method('getPage')->will($this->returnValue($this->pageConfigMock));
$this->pageConfigMock->expects($this->any())->method('getConfig')->will($this->returnValue(1));
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->action = $this->objectManagerHelper->getObject('Magento\\Framework\\App\\Test\\Unit\\Action\\ActionFake', ['request' => $this->_requestMock, 'response' => $this->_responseMock, 'eventManager' => $this->_eventManagerMock, 'redirect' => $this->_redirectMock, 'actionFlag' => $this->_actionFlagMock, 'view' => $this->viewMock]);
\Magento\Framework\Profiler::disable();
}
示例13: dispatch
public function dispatch($eventName, array $data = [])
{
\Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
$event = new \Magento\Framework\Event($data);
$event->setName($eventName);
$wrapper = new \Magento\Framework\Event\Observer();
$wrapper->setData(array_merge(['event' => $event], $data));
\Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
$this->_invoker->dispatch($observerConfig, $wrapper);
$observerConfig['method'] = 'execute';
$this->_devHelper->setObserverDetails($observerConfig, $eventName);
\Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
}
\Magento\Framework\Profiler::stop('EVENT:' . $eventName);
}
示例14: dispatch
/**
* Dispatches an event to observer's callback
*
* @param Event $event
* @return $this
*/
public function dispatch(Event $event)
{
if (!$this->isValidFor($event)) {
return $this;
}
$callback = $this->getCallback();
$this->setEvent($event);
$_profilerKey = 'OBSERVER: ';
if (is_object($callback[0])) {
$_profilerKey .= get_class($callback[0]);
} else {
$_profilerKey .= (string) $callback[0];
}
$_profilerKey .= ' -> ' . $callback[1];
\Magento\Framework\Profiler::start($_profilerKey);
call_user_func($callback, $this);
\Magento\Framework\Profiler::stop($_profilerKey);
return $this;
}
示例15: execute
/**
* Reindex all data what process is responsible
*
* @return void
*/
public function execute()
{
/** @var $process \Magento\Index\Model\Process */
$process = $this->_initProcess();
if ($process) {
try {
\Magento\Framework\Profiler::start('__INDEX_PROCESS_REINDEX_ALL__');
$process->reindexEverything();
\Magento\Framework\Profiler::stop('__INDEX_PROCESS_REINDEX_ALL__');
$this->messageManager->addSuccess(__('%1 index was rebuilt.', $process->getIndexer()->getName()));
} catch (\Magento\Framework\Model\Exception $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('There was a problem with reindexing process.'));
}
} else {
$this->messageManager->addError(__('Cannot initialize the indexer process.'));
}
$this->_redirect('adminhtml/*/list');
}