Version Notes
Version 1.0.0
Download this release
Release Info
| Developer | Olivier Pepin |
| Extension | optaros-traceview |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/Optaros/TraceView/Block/Footer.php +26 -0
- app/code/community/Optaros/TraceView/Block/Head.php +26 -0
- app/code/community/Optaros/TraceView/Helper/Data.php +179 -0
- app/code/community/Optaros/TraceView/Model/Container/Render.php +34 -0
- app/code/community/Optaros/TraceView/Model/Observer.php +46 -0
- app/code/community/Optaros/TraceView/etc/cache.xml +17 -0
- app/code/community/Optaros/TraceView/etc/config.xml +46 -0
- app/code/community/Varien/Profiler.php +187 -0
- app/design/frontend/base/default/layout/traceview.xml +11 -0
- app/etc/modules/Optaros_TraceView.xml +18 -0
- app/etc/traceview.xml +55 -0
- package.xml +23 -0
app/code/community/Optaros/TraceView/Block/Footer.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
// Copyright (C) 2013 Optaros, Inc. All rights reserved.
|
| 3 |
+
|
| 4 |
+
class Optaros_TraceView_Block_Footer extends Mage_Core_Block_Text {
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Render the RUM JS footer
|
| 8 |
+
*/
|
| 9 |
+
protected function _toHtml() {
|
| 10 |
+
if (Optaros_TraceView_Helper_Data::isEnabled()
|
| 11 |
+
&& Optaros_TraceView_Helper_Data::isRumEnabled()) {
|
| 12 |
+
$this->addText(oboe_get_rum_footer());
|
| 13 |
+
}
|
| 14 |
+
return parent::_toHtml();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Method used to render the block in the applyWithoutApp()
|
| 19 |
+
* FPC method
|
| 20 |
+
*/
|
| 21 |
+
public function renderWithoutApp() {
|
| 22 |
+
return $this->_toHtml();
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* vim: set ts=4 sw=4 noexpandtab: */
|
app/code/community/Optaros/TraceView/Block/Head.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
// Copyright (C) 2013 Optaros, Inc. All rights reserved.
|
| 3 |
+
|
| 4 |
+
class Optaros_TraceView_Block_Head extends Mage_Core_Block_Text {
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Render the RUM JS header
|
| 8 |
+
*/
|
| 9 |
+
protected function _toHtml() {
|
| 10 |
+
if (Optaros_TraceView_Helper_Data::isEnabled()
|
| 11 |
+
&& Optaros_TraceView_Helper_Data::isRumEnabled()) {
|
| 12 |
+
$this->addText(oboe_get_rum_header());
|
| 13 |
+
}
|
| 14 |
+
return parent::_toHtml();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Method used to render the block in the applyWithoutApp()
|
| 19 |
+
* FPC method
|
| 20 |
+
*/
|
| 21 |
+
public function renderWithoutApp() {
|
| 22 |
+
return $this->_toHtml();
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* vim: set ts=4 sw=4 noexpandtab: */
|
app/code/community/Optaros/TraceView/Helper/Data.php
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
*
|
| 5 |
+
* TraceView helper functions dealing with config and adding layers to TraceLytics
|
| 6 |
+
*
|
| 7 |
+
* We're coding this class with static members since it's mostly going to be
|
| 8 |
+
* accessed from lib/Varien/Profiler.php where we (theoretically) don't use the
|
| 9 |
+
* Magento factory and we're not going to have a helper object, but we're going
|
| 10 |
+
* to use static access instead (Optaros_TraceView_Helper_Data::addLayer() instead
|
| 11 |
+
* of Mage::helper('traceview')->addLayer())
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Optaros_TraceView_Helper_Data
|
| 16 |
+
{
|
| 17 |
+
/* config xpath to enable/disable traceview monitoring */
|
| 18 |
+
const XML_PATH_CONFIG_ENABLED = 'global/traceview/enabled';
|
| 19 |
+
|
| 20 |
+
/* config xpath for timer layers */
|
| 21 |
+
const XML_PATH_CONFIG_LAYERS = 'global/traceview/layers';
|
| 22 |
+
|
| 23 |
+
/* config xpath for use_rum */
|
| 24 |
+
const XML_PATH_CONFIG_USE_RUM = 'global/traceview/use_rum';
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
/* "cached" enabled setting from config */
|
| 28 |
+
static protected $_enabled = NULL;
|
| 29 |
+
|
| 30 |
+
/* "cached" use_rum config */
|
| 31 |
+
static protected $_use_rum = NULL;
|
| 32 |
+
|
| 33 |
+
/* "cached" layers node from config */
|
| 34 |
+
static protected $_layers = NULL;
|
| 35 |
+
|
| 36 |
+
/* static layer mapping, not loaded from config */
|
| 37 |
+
static protected $_staticLayers = array (
|
| 38 |
+
'config' => 'mage_init',
|
| 39 |
+
'system_config' => 'mage_init'
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
protected static function _getTimerPattern($timer) {
|
| 44 |
+
return substr($timer , strrpos($timer, '::') + 2);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* get the proper layer to log the timer into
|
| 49 |
+
*
|
| 50 |
+
* @param String $timerName timer name
|
| 51 |
+
*
|
| 52 |
+
* @return Layer name on success
|
| 53 |
+
* @return NULL if no configured layer was found
|
| 54 |
+
*/
|
| 55 |
+
public static function getTimerLayer($timerName) {
|
| 56 |
+
|
| 57 |
+
if (self::$_layers === NULL) {
|
| 58 |
+
self::$_layers =
|
| 59 |
+
self::_getConfigNode(self::XML_PATH_CONFIG_LAYERS, TRUE);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
$pkey = self::_getTimerPattern($timerName);
|
| 63 |
+
if (!empty(self::$_layers) && isset(self::$_layers[$pkey])) {
|
| 64 |
+
/* layer found in config */
|
| 65 |
+
return self::$_layers[$pkey];
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
return NULL;
|
| 69 |
+
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* check to see if we have a layer that we're always logging
|
| 74 |
+
*
|
| 75 |
+
* @param String $timerName timer name
|
| 76 |
+
*
|
| 77 |
+
* @return Layer name on success
|
| 78 |
+
* @return NULL if no configured layer was found
|
| 79 |
+
*/
|
| 80 |
+
public static function getStaticTimerLayer($timerName) {
|
| 81 |
+
|
| 82 |
+
$pkey = self::_getTimerPattern($timerName);
|
| 83 |
+
|
| 84 |
+
/* check the static mapping */
|
| 85 |
+
if (isset(self::$_staticLayers[$pkey]))
|
| 86 |
+
return self::$_staticLayers[$pkey];
|
| 87 |
+
|
| 88 |
+
return NULL;
|
| 89 |
+
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* add layer in TraceLytics
|
| 96 |
+
*
|
| 97 |
+
* @param String $timerName timer name used in Varien_Profiler
|
| 98 |
+
* @param String $label usually 'entry'/'exit'
|
| 99 |
+
*/
|
| 100 |
+
public static function addLayer($timerName, $label) {
|
| 101 |
+
|
| 102 |
+
$layer = self::getStaticTimerLayer($timerName);
|
| 103 |
+
|
| 104 |
+
if ($layer !== NULL || self::isEnabled()) {
|
| 105 |
+
|
| 106 |
+
if (empty($layer))
|
| 107 |
+
$layer = self::getTimerLayer($timerName);
|
| 108 |
+
|
| 109 |
+
if (!empty($layer)) {
|
| 110 |
+
oboe_log($layer, $label, array( "timer" => $timerName));
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Check whether the functionality is enabled or npt
|
| 119 |
+
*
|
| 120 |
+
* @return TRUE if it is
|
| 121 |
+
* @return FALSE otherwise
|
| 122 |
+
*/
|
| 123 |
+
public static function isEnabled() {
|
| 124 |
+
|
| 125 |
+
if (self::$_enabled === NULL) {
|
| 126 |
+
|
| 127 |
+
$cfg = self::_getConfigNode(self::XML_PATH_CONFIG_ENABLED);
|
| 128 |
+
if ($cfg === NULL) {
|
| 129 |
+
/* Config is not loaded at this point, simply return FALSE
|
| 130 |
+
* but DON'T cache the result, leave it NULL
|
| 131 |
+
* instead, to recompute it once the config is loaded.
|
| 132 |
+
*/
|
| 133 |
+
return FALSE;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
self::$_enabled =
|
| 137 |
+
(
|
| 138 |
+
($cfg === '1')
|
| 139 |
+
&& extension_loaded('oboe')
|
| 140 |
+
&& function_exists('oboe_log')
|
| 141 |
+
);
|
| 142 |
+
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
return self::$_enabled;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Check whether using rum is enabled or not
|
| 150 |
+
*
|
| 151 |
+
* @return TRUE if it is
|
| 152 |
+
* @return FALSE otherwise
|
| 153 |
+
*/
|
| 154 |
+
public static function isRumEnabled() {
|
| 155 |
+
if (self::$_use_rum === NULL) {
|
| 156 |
+
self::$_use_rum =
|
| 157 |
+
self::_getConfigNode(self::XML_PATH_CONFIG_USE_RUM);
|
| 158 |
+
}
|
| 159 |
+
return (self::$_use_rum === '1');
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
protected static function _getConfigNode($xpath, $asArray = FALSE) {
|
| 164 |
+
|
| 165 |
+
$config = Mage::getConfig();
|
| 166 |
+
if (empty($config)) {
|
| 167 |
+
return NULL;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
$node = $config->getNode($xpath);
|
| 171 |
+
if (empty($node))
|
| 172 |
+
return NULL;
|
| 173 |
+
|
| 174 |
+
return ($asArray?$node->asCanonicalArray():(string)$node);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* vim: set ts=4 sw=4 noexpandtab: */
|
app/code/community/Optaros/TraceView/Model/Container/Render.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
// Copyright (C) 2013 Optaros, Inc. All rights reserved.
|
| 3 |
+
|
| 4 |
+
class Optaros_Traceview_Model_Container_Render extends Enterprise_PageCache_Model_Container_Abstract
|
| 5 |
+
{
|
| 6 |
+
|
| 7 |
+
public function applyWithoutApp(&$content)
|
| 8 |
+
{
|
| 9 |
+
$blockContent = $this->_renderBlock();
|
| 10 |
+
if ($blockContent === false) {
|
| 11 |
+
return false;
|
| 12 |
+
}
|
| 13 |
+
$this->_applyToContent($content, $blockContent);
|
| 14 |
+
return true;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
public function applyInApp(&$content)
|
| 18 |
+
{
|
| 19 |
+
return $this->applyWithoutApp($content);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
protected function _renderBlock()
|
| 23 |
+
{
|
| 24 |
+
$blockName = $this->_placeholder->getAttribute('block');
|
| 25 |
+
$block = new $blockName;
|
| 26 |
+
return $block->renderWithoutApp();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
protected function _getCacheId()
|
| 30 |
+
{
|
| 31 |
+
return false;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
}
|
app/code/community/Optaros/TraceView/Model/Observer.php
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* TraceView for Magento
|
| 4 |
+
* @copyright Copyright(c) 2013 Optaros
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
class Optaros_TraceView_Model_Observer {
|
| 8 |
+
|
| 9 |
+
public function preDispatch($observer) {
|
| 10 |
+
|
| 11 |
+
/* bail out if oboe not available or module disbled */
|
| 12 |
+
if (!Optaros_TraceView_Helper_Data::isEnabled()) {
|
| 13 |
+
return;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
/* fetch request info (controller/action) */
|
| 17 |
+
$request =
|
| 18 |
+
$observer->getEvent()
|
| 19 |
+
->getControllerAction()
|
| 20 |
+
->getRequest();
|
| 21 |
+
$controller = $request->getControllerName();
|
| 22 |
+
$action = $request->getActionName();
|
| 23 |
+
|
| 24 |
+
/* log request info */
|
| 25 |
+
oboe_log('info',
|
| 26 |
+
array(
|
| 27 |
+
'Controller' => $controller,
|
| 28 |
+
'Action' => $action
|
| 29 |
+
)
|
| 30 |
+
);
|
| 31 |
+
|
| 32 |
+
$session = Mage::getSingleton('customer/session');
|
| 33 |
+
|
| 34 |
+
/* Partitioning based on whether the
|
| 35 |
+
* customer is logged in or not */
|
| 36 |
+
if ($session && $session->getCustomer()
|
| 37 |
+
&& ($session->getCustomer()->getId() !== NULL)) {
|
| 38 |
+
oboe_log('info', array('Partition' => 'LoggedIn'));
|
| 39 |
+
} else {
|
| 40 |
+
oboe_log('info', array('Partition' => 'Anonymous'));
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
/* vim: set ts=4 sw=4 noexpandtab: */
|
app/code/community/Optaros/TraceView/etc/cache.xml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<placeholders>
|
| 4 |
+
<traceview_head>
|
| 5 |
+
<block>traceview/head</block>
|
| 6 |
+
<placeholder>TRACEVIEW_HEAD</placeholder>
|
| 7 |
+
<container>Optaros_TraceView_Model_Container_Render</container>
|
| 8 |
+
<cache_lifetime>1</cache_lifetime>
|
| 9 |
+
</traceview_head>
|
| 10 |
+
<traceview_footer>
|
| 11 |
+
<block>traceview/footer</block>
|
| 12 |
+
<placeholder>TRACEVIEW_FOOTER</placeholder>
|
| 13 |
+
<container>Optaros_TraceView_Model_Container_Render</container>
|
| 14 |
+
<cache_lifetime>1</cache_lifetime>
|
| 15 |
+
</traceview_footer>
|
| 16 |
+
</placeholders>
|
| 17 |
+
</config>
|
app/code/community/Optaros/TraceView/etc/config.xml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<Optaros_TraceView>
|
| 4 |
+
<version>0.1</version>
|
| 5 |
+
</Optaros_TraceView>
|
| 6 |
+
</modules>
|
| 7 |
+
|
| 8 |
+
<global>
|
| 9 |
+
<blocks>
|
| 10 |
+
<traceview>
|
| 11 |
+
<class>Optaros_TraceView_Block</class>
|
| 12 |
+
</traceview>
|
| 13 |
+
</blocks>
|
| 14 |
+
<helpers>
|
| 15 |
+
<traceview>
|
| 16 |
+
<class>Optaros_TraceView_Helper</class>
|
| 17 |
+
</traceview>
|
| 18 |
+
</helpers>
|
| 19 |
+
<models>
|
| 20 |
+
<traceview>
|
| 21 |
+
<class>Optraos_TraceView_Model</class>
|
| 22 |
+
</traceview>
|
| 23 |
+
</models>
|
| 24 |
+
<events>
|
| 25 |
+
<controller_action_predispatch>
|
| 26 |
+
<observers>
|
| 27 |
+
<traceview_controller_action_predispatch>
|
| 28 |
+
<type>singleton</type>
|
| 29 |
+
<class>Optaros_TraceView_Model_Observer</class>
|
| 30 |
+
<method>preDispatch</method>
|
| 31 |
+
</traceview_controller_action_predispatch>
|
| 32 |
+
</observers>
|
| 33 |
+
</controller_action_predispatch>
|
| 34 |
+
</events>
|
| 35 |
+
</global>
|
| 36 |
+
|
| 37 |
+
<frontend>
|
| 38 |
+
<layout>
|
| 39 |
+
<updates>
|
| 40 |
+
<traceview>
|
| 41 |
+
<file>traceview.xml</file>
|
| 42 |
+
</traceview>
|
| 43 |
+
</updates>
|
| 44 |
+
</layout>
|
| 45 |
+
</frontend>
|
| 46 |
+
</config>
|
app/code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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento Enterprise Edition
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Magento Enterprise Edition License
|
| 8 |
+
* that is bundled with this package in the file LICENSE_EE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://www.magentocommerce.com/license/enterprise-edition
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category Varien
|
| 22 |
+
* @package Varien_Profiler
|
| 23 |
+
* @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://www.magentocommerce.com/license/enterprise-edition
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Varien_Profiler
|
| 29 |
+
{
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Timers for code profiling
|
| 33 |
+
*
|
| 34 |
+
* @var array
|
| 35 |
+
*/
|
| 36 |
+
static private $_timers = array();
|
| 37 |
+
static private $_enabled = false;
|
| 38 |
+
static private $_memory_get_usage = false;
|
| 39 |
+
|
| 40 |
+
public static function enable()
|
| 41 |
+
{
|
| 42 |
+
self::$_enabled = true;
|
| 43 |
+
self::$_memory_get_usage = function_exists('memory_get_usage');
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public static function disable()
|
| 47 |
+
{
|
| 48 |
+
self::$_enabled = false;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
public static function reset($timerName)
|
| 52 |
+
{
|
| 53 |
+
self::$_timers[$timerName] = array(
|
| 54 |
+
'start'=>false,
|
| 55 |
+
'count'=>0,
|
| 56 |
+
'sum'=>0,
|
| 57 |
+
'realmem'=>0,
|
| 58 |
+
'emalloc'=>0,
|
| 59 |
+
);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public static function resume($timerName)
|
| 63 |
+
{
|
| 64 |
+
if (!self::$_enabled) {
|
| 65 |
+
return;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if (empty(self::$_timers[$timerName])) {
|
| 69 |
+
self::reset($timerName);
|
| 70 |
+
}
|
| 71 |
+
if (self::$_memory_get_usage) {
|
| 72 |
+
self::$_timers[$timerName]['realmem_start'] = memory_get_usage(true);
|
| 73 |
+
self::$_timers[$timerName]['emalloc_start'] = memory_get_usage();
|
| 74 |
+
}
|
| 75 |
+
self::$_timers[$timerName]['start'] = microtime(true);
|
| 76 |
+
self::$_timers[$timerName]['count'] ++;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
public static function start($timerName) {
|
| 80 |
+
Optaros_TraceView_Helper_Data::addLayer($timerName, 'entry');
|
| 81 |
+
self::resume($timerName);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
public static function pause($timerName)
|
| 85 |
+
{
|
| 86 |
+
if (!self::$_enabled) {
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
$time = microtime(true); // Get current time as quick as possible to make more accurate calculations
|
| 91 |
+
|
| 92 |
+
if (empty(self::$_timers[$timerName])) {
|
| 93 |
+
self::reset($timerName);
|
| 94 |
+
}
|
| 95 |
+
if (false!==self::$_timers[$timerName]['start']) {
|
| 96 |
+
self::$_timers[$timerName]['sum'] += $time-self::$_timers[$timerName]['start'];
|
| 97 |
+
self::$_timers[$timerName]['start'] = false;
|
| 98 |
+
if (self::$_memory_get_usage) {
|
| 99 |
+
self::$_timers[$timerName]['realmem'] += memory_get_usage(true)-self::$_timers[$timerName]['realmem_start'];
|
| 100 |
+
self::$_timers[$timerName]['emalloc'] += memory_get_usage()-self::$_timers[$timerName]['emalloc_start'];
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
public static function stop($timerName)
|
| 106 |
+
{
|
| 107 |
+
Optaros_TraceView_Helper_Data::addLayer($timerName, 'exit');
|
| 108 |
+
self::pause($timerName);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public static function fetch($timerName, $key='sum')
|
| 112 |
+
{
|
| 113 |
+
if (empty(self::$_timers[$timerName])) {
|
| 114 |
+
return false;
|
| 115 |
+
} elseif (empty($key)) {
|
| 116 |
+
return self::$_timers[$timerName];
|
| 117 |
+
}
|
| 118 |
+
switch ($key) {
|
| 119 |
+
case 'sum':
|
| 120 |
+
$sum = self::$_timers[$timerName]['sum'];
|
| 121 |
+
if (self::$_timers[$timerName]['start']!==false) {
|
| 122 |
+
$sum += microtime(true)-self::$_timers[$timerName]['start'];
|
| 123 |
+
}
|
| 124 |
+
return $sum;
|
| 125 |
+
|
| 126 |
+
case 'count':
|
| 127 |
+
$count = self::$_timers[$timerName]['count'];
|
| 128 |
+
return $count;
|
| 129 |
+
|
| 130 |
+
case 'realmem':
|
| 131 |
+
if (!isset(self::$_timers[$timerName]['realmem'])) {
|
| 132 |
+
self::$_timers[$timerName]['realmem'] = -1;
|
| 133 |
+
}
|
| 134 |
+
return self::$_timers[$timerName]['realmem'];
|
| 135 |
+
|
| 136 |
+
case 'emalloc':
|
| 137 |
+
if (!isset(self::$_timers[$timerName]['emalloc'])) {
|
| 138 |
+
self::$_timers[$timerName]['emalloc'] = -1;
|
| 139 |
+
}
|
| 140 |
+
return self::$_timers[$timerName]['emalloc'];
|
| 141 |
+
|
| 142 |
+
default:
|
| 143 |
+
if (!empty(self::$_timers[$timerName][$key])) {
|
| 144 |
+
return self::$_timers[$timerName][$key];
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
return false;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
public static function getTimers()
|
| 151 |
+
{
|
| 152 |
+
return self::$_timers;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* Output SQl Zend_Db_Profiler
|
| 157 |
+
*
|
| 158 |
+
*/
|
| 159 |
+
public static function getSqlProfiler($res) {
|
| 160 |
+
if(!$res){
|
| 161 |
+
return '';
|
| 162 |
+
}
|
| 163 |
+
$out = '';
|
| 164 |
+
$profiler = $res->getProfiler();
|
| 165 |
+
if($profiler->getEnabled()) {
|
| 166 |
+
$totalTime = $profiler->getTotalElapsedSecs();
|
| 167 |
+
$queryCount = $profiler->getTotalNumQueries();
|
| 168 |
+
$longestTime = 0;
|
| 169 |
+
$longestQuery = null;
|
| 170 |
+
|
| 171 |
+
foreach ($profiler->getQueryProfiles() as $query) {
|
| 172 |
+
if ($query->getElapsedSecs() > $longestTime) {
|
| 173 |
+
$longestTime = $query->getElapsedSecs();
|
| 174 |
+
$longestQuery = $query->getQuery();
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
$out .= 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "<br>";
|
| 179 |
+
$out .= 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "<br>";
|
| 180 |
+
$out .= 'Queries per second: ' . $queryCount / $totalTime . "<br>";
|
| 181 |
+
$out .= 'Longest query length: ' . $longestTime . "<br>";
|
| 182 |
+
$out .= 'Longest query: <br>' . $longestQuery . "<hr>";
|
| 183 |
+
}
|
| 184 |
+
return $out;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
app/design/frontend/base/default/layout/traceview.xml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<layout version="0.1.0">
|
| 3 |
+
<default>
|
| 4 |
+
<reference name="head">
|
| 5 |
+
<block type="traceview/head" before="-" name="traceview.head" />
|
| 6 |
+
</reference>
|
| 7 |
+
<reference name="before_body_end">
|
| 8 |
+
<block type="traceview/footer" after="-" name="traceview.footer" />
|
| 9 |
+
</reference>
|
| 10 |
+
</default>
|
| 11 |
+
</layout>
|
app/etc/modules/Optaros_TraceView.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* AppNeta Traceview Module
|
| 5 |
+
*
|
| 6 |
+
* @author Olivier PEPIN
|
| 7 |
+
* @copyright Copyright (c) 2013 www.optaros.com
|
| 8 |
+
*/
|
| 9 |
+
-->
|
| 10 |
+
|
| 11 |
+
<config>
|
| 12 |
+
<modules>
|
| 13 |
+
<Optaros_TraceView>
|
| 14 |
+
<active>true</active>
|
| 15 |
+
<codePool>community</codePool>
|
| 16 |
+
</Optaros_TraceView>
|
| 17 |
+
</modules>
|
| 18 |
+
</config>
|
app/etc/traceview.xml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!-- Copyright (C) 2010 Optaros, Inc. All rights reserved. -->
|
| 3 |
+
<config>
|
| 4 |
+
<global>
|
| 5 |
+
<traceview>
|
| 6 |
+
|
| 7 |
+
<!-- enable/disable (1/0) reporting to tracelytics -->
|
| 8 |
+
<enabled>1</enabled>
|
| 9 |
+
|
| 10 |
+
<!-- whether to use RUM or not -->
|
| 11 |
+
<use_rum>1</use_rum>
|
| 12 |
+
|
| 13 |
+
<!-- timer <=> layer association -->
|
| 14 |
+
<layers>
|
| 15 |
+
|
| 16 |
+
<!--
|
| 17 |
+
Timers that end in the given pattern are matched
|
| 18 |
+
<PATTERN>layer</PATTERN>
|
| 19 |
+
-->
|
| 20 |
+
|
| 21 |
+
<!-- mage_init -->
|
| 22 |
+
<system_config>mage_init</system_config>
|
| 23 |
+
<config>mage_init</config>
|
| 24 |
+
<load_cache>mage_init</load_cache>
|
| 25 |
+
<stores>mage_init</stores>
|
| 26 |
+
<init_front_controller>mage_init</init_front_controller>
|
| 27 |
+
<apply_db_schema_updates>mage_init</apply_db_schema_updates>
|
| 28 |
+
|
| 29 |
+
<!-- mage_url_rewrite -->
|
| 30 |
+
<db_url_rewrite>mage_url_rewrite</db_url_rewrite>
|
| 31 |
+
<config_url_rewrite>mage_url_rewrite</config_url_rewrite>
|
| 32 |
+
|
| 33 |
+
<!-- mage_routers_match -->
|
| 34 |
+
<routers_match>mage_routers_match</routers_match>
|
| 35 |
+
|
| 36 |
+
<!-- mage_predispatch -->
|
| 37 |
+
<pre-dispatch>mage_predispatch</pre-dispatch>
|
| 38 |
+
|
| 39 |
+
<!-- mage_layout_load -->
|
| 40 |
+
<layout_load>mage_layout_load</layout_load>
|
| 41 |
+
<layout_generate_xml>mage_layout_load</layout_generate_xml>
|
| 42 |
+
<layout_generate_blocks>mage_layout_load</layout_generate_blocks>
|
| 43 |
+
|
| 44 |
+
<!-- mage_layout_render -->
|
| 45 |
+
<layout_render>mage_layout_render</layout_render>
|
| 46 |
+
|
| 47 |
+
<!-- mage_postdispatch -->
|
| 48 |
+
<postdispatch>mage_postdispatch</postdispatch>
|
| 49 |
+
|
| 50 |
+
</layers>
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
</traceview>
|
| 54 |
+
</global>
|
| 55 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>optaros-traceview</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/OSL-3.0">OSL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>TraceView profiling through Varien_Profiler</summary>
|
| 10 |
+
<description>The module enables profiling with AppNeta TraceView through calls to the Varien_Profiler API.
|
| 11 |
+

|
| 12 |
+
Varien_Profiler::start() and stop() methods will
|
| 13 |
+
send info to specific TraceView layers based on 
|
| 14 |
+
predefined set of configured timers that are to be
|
| 15 |
+
logged on TraceView.</description>
|
| 16 |
+
<notes>Version 1.0.0</notes>
|
| 17 |
+
<authors><author><name>Olivier Pepin</name><user>opepin</user><email>opepin@gmail.com</email></author><author><name>Florin Mihalache</name><user>mflorin</user><email>florin.mihalache@gmail.com</email></author></authors>
|
| 18 |
+
<date>2013-07-11</date>
|
| 19 |
+
<time>15:27:57</time>
|
| 20 |
+
<contents><target name="magecommunity"><dir name="Optaros"><dir name="TraceView"><dir name="Block"><file name="Footer.php" hash="69a83ed5c3712daac4acdd19fe775693"/><file name="Head.php" hash="e0f9e47277a2ff60aab7a111d4605d81"/></dir><dir name="Helper"><file name="Data.php" hash="4654b173436bf653d59b7e4d7845499f"/></dir><dir name="Model"><dir name="Container"><file name="Render.php" hash="1eb73a8921e138968c1bb74d186376e7"/></dir><file name="Observer.php" hash="adc785cb8697f498e98c37a80e174666"/></dir><dir name="etc"><file name="cache.xml" hash="b554551e3ed76906c25547aae93bc790"/><file name="config.xml" hash="a4b954756115563f2a91b58d84abddac"/></dir></dir></dir><dir name="Varien"><file name="Profiler.php" hash="6ad63be6f7bc3832cf173d03ea3976ac"/></dir></target><target name="mageetc"><dir name="."><file name="traceview.xml" hash="2beb4bcc172e58de68325b2207ef2ab3"/></dir><dir name="modules"><file name="Optaros_TraceView.xml" hash="4fa79e646dd10ac82884abd00f6ed26c"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="traceview.xml" hash="cd54d6c24fb24a0774adbe0f02870aea"/></dir></dir></dir></dir></target></contents>
|
| 21 |
+
<compatible/>
|
| 22 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 23 |
+
</package>
|
