Yireo_NewRelic - Version 1.2.0

Version Notes

No notes

Download this release

Release Info

Developer Yireo
Extension Yireo_NewRelic
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.0 to 1.2.0

app/code/community/Varien/Profiler.php ADDED
@@ -0,0 +1,19 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo
7
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
8
+ * @license Open Software License
9
+ */
10
+
11
+ if(class_exists('Yireo_NewRelic_Model_Profiler')) {
12
+ class Varien_Profiler extends Yireo_NewRelic_Model_Profiler
13
+ {
14
+ /*
15
+ * this is just to have the extended profiler class
16
+ * everything else is in the yireo profiler
17
+ */
18
+ }
19
+ }
app/code/community/Yireo/NewRelic/Block/Rum/Timing/Abstract.php ADDED
@@ -0,0 +1,41 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
+ */
10
+
11
+ /**
12
+ * Abstract block for RUM timing blocks
13
+ *
14
+ */
15
+ abstract class Yireo_NewRelic_Block_Rum_Timing_Abstract extends Mage_Core_Block_Template {
16
+
17
+ public abstract function getContentHtml();
18
+
19
+ /**
20
+ * @return Yireo_NewRelic_Helper_Data
21
+ */
22
+ protected function _getHelper()
23
+ {
24
+ return Mage::helper('newrelic');
25
+ }
26
+
27
+ protected function _canShow()
28
+ {
29
+ return $this->_getHelper()->isEnabled()
30
+ && $this->_getHelper()->isUseRUM();
31
+ }
32
+
33
+ protected function _toHtml()
34
+ {
35
+ if (!$this->_canShow()) {
36
+ return '';
37
+ }
38
+
39
+ return parent::_toHtml();
40
+ }
41
+ }
app/code/community/Yireo/NewRelic/Block/Rum/Timing/Footer.php ADDED
@@ -0,0 +1,22 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
+ */
10
+
11
+ /**
12
+ * Timing head block adding the rum track html
13
+ */
14
+ class Yireo_NewRelic_Block_Rum_Timing_Footer extends Yireo_NewRelic_Block_Rum_Timing_Abstract
15
+ {
16
+ public function getContentHtml()
17
+ {
18
+ return (function_exists('newrelic_get_browser_timing_footer'))
19
+ ? newrelic_get_browser_timing_footer(true)
20
+ : '';
21
+ }
22
+ }
app/code/community/Yireo/NewRelic/Block/Rum/Timing/Header.php ADDED
@@ -0,0 +1,22 @@
1
+ <?php
2
+ /**
3
+ * NewRelic plugin for Magento
4
+ *
5
+ * @package Yireo_NewRelic
6
+ * @author Yireo (http://www.yireo.com/)
7
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
8
+ * @license Open Source License
9
+ */
10
+
11
+ /**
12
+ * Timing head block adding the rum init html
13
+ */
14
+ class Yireo_NewRelic_Block_Rum_Timing_Header extends Yireo_NewRelic_Block_Rum_Timing_Abstract
15
+ {
16
+ public function getContentHtml()
17
+ {
18
+ return (function_exists('newrelic_get_browser_timing_header'))
19
+ ? newrelic_get_browser_timing_header(true)
20
+ : '';
21
+ }
22
+ }
app/code/community/Yireo/NewRelic/Helper/Data.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * NewRelic plugin for Magento
4
*
5
* @package Yireo_NewRelic
6
* @author Yireo (http://www.yireo.com/)
@@ -8,7 +8,7 @@
8
* @license Open Source License
9
*/
10
11
- class Yireo_NewRelic_Helper_Data extends Mage_Core_Helper_Abstract
12
{
13
/*
14
* Check whether this module can be used
@@ -17,19 +17,106 @@ class Yireo_NewRelic_Helper_Data extends Mage_Core_Helper_Abstract
17
* @param null
18
* @return bool
19
*/
20
- public function isEnabled()
21
{
22
- if(!extension_loaded('newrelic')) {
23
return false;
24
}
25
26
- return true;
27
}
28
29
- public function getConfigValue($key = null, $default_value = null)
30
{
31
- $value = Mage::getStoreConfig('newrelic/settings/'.$key);
32
- if(empty($value)) $value = $default_value;
33
return $value;
34
}
35
}
1
<?php
2
/**
3
+ * NewRelic plugin for Magento
4
*
5
* @package Yireo_NewRelic
6
* @author Yireo (http://www.yireo.com/)
8
* @license Open Source License
9
*/
10
11
+ class Yireo_NewRelic_Helper_Data extends Mage_Core_Helper_Abstract
12
{
13
/*
14
* Check whether this module can be used
17
* @param null
18
* @return bool
19
*/
20
+ public function isEnabled()
21
{
22
+ if (!extension_loaded('newrelic')) {
23
return false;
24
}
25
26
+ return $this->getConfigFlag('enabled');
27
}
28
29
+ /*
30
+ * Return the appname
31
+ *
32
+ * @access public
33
+ * @param null
34
+ * @return string
35
+ */
36
+ public function getAppName()
37
+ {
38
+ return $this->getConfigValue('appname');
39
+ }
40
+
41
+ /*
42
+ * Return the New Relic license
43
+ *
44
+ * @access public
45
+ * @param null
46
+ * @return string
47
+ */
48
+ public function getLicense()
49
+ {
50
+ return $this->getConfigValue('license');
51
+ }
52
+
53
+ /*
54
+ * Return whether to use the xmit flag
55
+ *
56
+ * @access public
57
+ * @param null
58
+ * @return bool
59
+ */
60
+ public function isUseXmit()
61
+ {
62
+ return $this->getConfigFlag('xmit');
63
+ }
64
+
65
+ /*
66
+ * Return whether to track the controller
67
+ *
68
+ * @access public
69
+ * @param null
70
+ * @return bool
71
+ */
72
+ public function isTrackController()
73
{
74
+ return $this->getConfigFlag('track_controller');
75
+ }
76
+
77
+ /*
78
+ * Return whether to use Real User Monitoring
79
+ *
80
+ * @access public
81
+ * @param null
82
+ * @return bool
83
+ */
84
+ public function isUseRUM()
85
+ {
86
+ return $this->getConfigFlag('real_user_monitoring');
87
+ }
88
+
89
+ /*
90
+ * Return a value from the configuration
91
+ *
92
+ * @access public
93
+ * @param null
94
+ * @return bool
95
+ */
96
+ public function getConfigValue($key = null, $default_value = null)
97
+ {
98
+ $value = Mage::getStoreConfig('newrelic/settings/' . $key);
99
+ if (empty($value)) {
100
+ $value = $default_value;
101
+ }
102
return $value;
103
}
104
+
105
+ /*
106
+ * Return a boolean flag for the configuration
107
+ *
108
+ * @access public
109
+ * @param null
110
+ * @return bool
111
+ */
112
+ public function getConfigFlag($key = null, $defaultValue = false)
113
+ {
114
+ $result = Mage::getStoreConfigFlag('newrelic/settings/' . $key);
115
+ if (empty($result)) {
116
+ $result = $defaultValue;
117
+ }
118
+
119
+ return $result;
120
+ }
121
+
122
}
app/code/community/Yireo/NewRelic/Model/Observer.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * NewRelic plugin for Magento
4
*
5
* @package Yireo_NewRelic
6
* @author Yireo (http://www.yireo.com/)
@@ -8,54 +8,83 @@
8
* @license Open Source License
9
*/
10
11
- class Yireo_NewRelic_Model_Observer
12
{
13
- /*
14
* Listen to the event controller_action_predispatch
15
- *
16
* @access public
17
- * @parameter Varien_Event_Observer $observer
18
* @return $this
19
*/
20
- public function controllerActionPredispatch($observer)
21
{
22
- // Check whether NewRelic can be used
23
- if(Mage::helper('newrelic')->isEnabled() == true) {
24
25
- // Set the app-name
26
- $appname = trim(Mage::helper('newrelic')->getConfigValue('appname'));
27
- $license = trim(Mage::helper('newrelic')->getConfigValue('license'));
28
- $xmit = true; // @warning: This gives a slight performance overhead - check the NewRelic docs for details
29
- if(!empty($appname)) newrelic_set_appname($appname, $license, $xmit);
30
31
- // Common settings
32
- newrelic_capture_params(true);
33
}
34
-
35
return $this;
36
}
37
38
- /*
39
- * Listen to the event core_block_abstract_to_html_after
40
- *
41
* @access public
42
- * @parameter Varien_Event_Observer $observer
43
* @return $this
44
*/
45
- public function coreBlockAbstractToHtmlAfter($observer)
46
{
47
- // Only for the frontend
48
- if(Mage::app()->getStore()->isAdmin() == true) {
49
return $this;
50
}
51
52
- // Check whether NewRelic can be used
53
- if(Mage::helper('newrelic')->isEnabled() == false) {
54
- return $this;
55
}
56
57
- // Check whether NewRelic Real User Monitoring is active
58
- if(Mage::helper('newrelic')->getConfigValue('real_user_monitoring') == false) {
59
return $this;
60
}
61
@@ -64,18 +93,22 @@ class Yireo_NewRelic_Model_Observer
64
newrelic_add_custom_parameter('magento_request', Mage::getModel('core/url')->getRequest()->getRequestUri());
65
newrelic_add_custom_parameter('magento_store_id', Mage::app()->getStore()->getId());
66
67
- // Get and set customer-data
68
$customer = Mage::getSingleton('customer/session')->getCustomer();
69
$customerName = trim($customer->getName());
70
- if(empty($customerName)) $customerName = 'guest';
71
$customerEmail = trim($customer->getEmail());
72
- if(empty($customerEmail)) $customerEmail = 'guest';
73
newrelic_add_custom_parameter('magento_customer_email', $customerEmail);
74
newrelic_add_custom_parameter('magento_customer_name', $customerName);
75
76
// Get and set product-data
77
$product = Mage::registry('current_product');
78
- if(!empty($product)) {
79
$productSku = $product->getSku();
80
newrelic_add_custom_parameter('magento_product_name', $product->getName());
81
newrelic_add_custom_parameter('magento_product_sku', $product->getSku());
@@ -84,67 +117,84 @@ class Yireo_NewRelic_Model_Observer
84
$productSku = null;
85
}
86
87
- // Set user attributes
88
- newrelic_set_user_attributes($customerEmail, $customerName, $productSku);
89
-
90
- // Fetch objects from this event
91
- $transport = $observer->getEvent()->getTransport();
92
- $block = $observer->getEvent()->getBlock();
93
-
94
- // Add JavaScript to the header
95
- if($block->getNameInLayout() == 'head') {
96
- $extraHtml = newrelic_get_browser_timing_header();
97
- $html = $transport->getHtml()."\n".$extraHtml;
98
- $transport->setHtml($html);
99
}
100
101
- // Add JavaScript to the footer
102
- if($block->getNameInLayout() == 'root') {
103
- $extraHtml = newrelic_get_browser_timing_footer();
104
- $html = str_replace('</body>', $extraHtml."\n".'</body>', $transport->getHtml());
105
- $transport->setHtml($html);
106
- }
107
108
return $this;
109
}
110
111
- /*
112
* Listen to the event model_save_after
113
- *
114
* @access public
115
- * @parameter Varien_Event_Observer $observer
116
* @return $this
117
*/
118
- public function modelSaveAfter($observer)
119
{
120
- // Check whether NewRelic can be used
121
- if(Mage::helper('newrelic')->isEnabled() == false) {
122
return $this;
123
}
124
125
$object = $observer->getEvent()->getObject();
126
- newrelic_custom_metric('Magento/'.get_class($object).'_Save', 1);
127
128
return $this;
129
}
130
131
- /*
132
* Listen to the event model_delete_after
133
- *
134
* @access public
135
- * @parameter Varien_Event_Observer $observer
136
* @return $this
137
*/
138
- public function modelDeleteAfter($observer)
139
{
140
- // Check whether NewRelic can be used
141
- if(Mage::helper('newrelic')->isEnabled() == false) {
142
return $this;
143
}
144
145
$object = $observer->getEvent()->getObject();
146
- newrelic_custom_metric('Magento/'.get_class($object).'_Delete', 1);
147
148
return $this;
149
}
150
}
1
<?php
2
/**
3
+ * NewRelic plugin for Magento
4
*
5
* @package Yireo_NewRelic
6
* @author Yireo (http://www.yireo.com/)
8
* @license Open Source License
9
*/
10
11
+ class Yireo_NewRelic_Model_Observer
12
{
13
+ /**
14
* Listen to the event controller_action_predispatch
15
+ *
16
* @access public
17
+ * @param Varien_Event_Observer $observer
18
* @return $this
19
*/
20
+ public function controllerActionPredispatch($observer)
21
{
22
+ if (!$this->_isEnabled()) {
23
+ return $this;
24
+ }
25
+
26
+ $this->_setupAppName();
27
+ $this->_trackControllerAction($observer->getEvent()->getControllerAction());
28
29
+ // Common settings
30
+ newrelic_capture_params(true);
31
+
32
+ return $this;
33
+ }
34
+
35
+ /**
36
+ * Method to setup the app-name
37
+ *
38
+ * @access public
39
+ * @param null
40
+ * @return $this
41
+ */
42
+ protected function _setupAppName()
43
+ {
44
+ $helper = $this->_getHelper();
45
+ $appname = trim($helper->getAppName());
46
+ $license = trim($helper->getLicense());
47
+ $xmit = $helper->isUseXmit();
48
49
+ if (!empty($appname) && function_exists('newrelic_set_appname')) {
50
+ newrelic_set_appname($appname, $license, $xmit);
51
}
52
+
53
return $this;
54
}
55
56
+ /**
57
+ * Method to track the controller-action
58
+ *
59
* @access public
60
+ * @param Mage_Core_Controller_Front_Action $action
61
* @return $this
62
*/
63
+ protected function _trackControllerAction($action)
64
{
65
+ if (!$this->_getHelper()->isTrackController()) {
66
return $this;
67
}
68
69
+ $actionName = $action->getFullActionName('/');
70
+ if (function_exists('newrelic_name_transaction')) {
71
+ newrelic_name_transaction($actionName);
72
}
73
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Post dispatch observer for user tracking
79
+ *
80
+ * @access public
81
+ * @param Varien_Event_Observer $observer
82
+ * @return $this
83
+ */
84
+ public function controllerActionPostdispatch($observer)
85
+ {
86
+ if (!$this->_isEnabled()
87
+ || !$this->_getHelper()->isUseRUM()){
88
return $this;
89
}
90
93
newrelic_add_custom_parameter('magento_request', Mage::getModel('core/url')->getRequest()->getRequestUri());
94
newrelic_add_custom_parameter('magento_store_id', Mage::app()->getStore()->getId());
95
96
+ // Get customer-data
97
$customer = Mage::getSingleton('customer/session')->getCustomer();
98
$customerName = trim($customer->getName());
99
$customerEmail = trim($customer->getEmail());
100
+
101
+ // Correct empty values
102
+ if (empty($customerName)) $customerName = 'guest';
103
+ if (empty($customerEmail)) $customerEmail = 'guest';
104
+
105
+ // Set customer-data
106
newrelic_add_custom_parameter('magento_customer_email', $customerEmail);
107
newrelic_add_custom_parameter('magento_customer_name', $customerName);
108
109
// Get and set product-data
110
$product = Mage::registry('current_product');
111
+ if (!empty($product)) {
112
$productSku = $product->getSku();
113
newrelic_add_custom_parameter('magento_product_name', $product->getName());
114
newrelic_add_custom_parameter('magento_product_sku', $product->getSku());
117
$productSku = null;
118
}
119
120
+ $category = Mage::registry('current_category');
121
+ if ($category) {
122
+ newrelic_add_custom_parameter('magento_category_name', $category->getName());
123
+ newrelic_add_custom_parameter('magento_category_id', $category->getId());
124
}
125
126
+ // Set user attributes
127
+ newrelic_set_user_attributes($customerEmail, $customerName, $productSku);
128
129
return $this;
130
}
131
132
+ /**
133
* Listen to the event model_save_after
134
+ *
135
* @access public
136
+ * @param Varien_Event_Observer $observer
137
* @return $this
138
*/
139
+ public function modelSaveAfter($observer)
140
{
141
+ if ($this->_isEnabled()) {
142
return $this;
143
}
144
145
+ if (!function_exists('newrelic_custom_metric')) {
146
+ return $this;
147
+ }
148
$object = $observer->getEvent()->getObject();
149
+ newrelic_custom_metric('Magento/' . get_class($object) . '_Save', 1);
150
151
return $this;
152
}
153
154
+ /**
155
* Listen to the event model_delete_after
156
+ *
157
* @access public
158
+ * @param Varien_Event_Observer $observer
159
* @return $this
160
*/
161
+ public function modelDeleteAfter($observer)
162
{
163
+ if (!$this->_isEnabled()) {
164
+ return $this;
165
+ }
166
+
167
+ if (!function_exists('newrelic_custom_metric')) {
168
return $this;
169
}
170
171
$object = $observer->getEvent()->getObject();
172
+ newrelic_custom_metric('Magento/' . get_class($object) . '_Delete', 1);
173
174
return $this;
175
}
176
+
177
+ /**
178
+ * Method to check wether this module can be used or not
179
+ *
180
+ * @access public
181
+ * @param null
182
+ * @return bool
183
+ */
184
+ protected function _isEnabled()
185
+ {
186
+ return $this->_getHelper()->isEnabled();
187
+ }
188
+
189
+ /**
190
+ * Method to return the helper
191
+ *
192
+ * @access public
193
+ * @param null
194
+ * @return Yireo_NewRelic_Helper_Data
195
+ */
196
+ protected function _getHelper()
197
+ {
198
+ return Mage::helper('newrelic');
199
+ }
200
}
app/code/community/Yireo/NewRelic/Model/Profiler.php CHANGED
@@ -2,7 +2,6 @@
2
/**
3
* NewRelic plugin for Magento
4
*
5
- * @category design_default
6
* @package Yireo_NewRelic
7
* @author Yireo (http://www.yireo.com/)
8
* @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
@@ -11,13 +10,25 @@
11
12
class Yireo_NewRelic_Model_Profiler
13
{
14
public static function init()
15
{
16
- // Only continue when the PHP-extension "newrelic" is found
17
if(!extension_loaded('newrelic')) {
18
return;
19
}
20
21
// Add generic NewRelic calls that don't have dependancies on Magento
22
static $initialized = false;
23
if($initialized == false) {
@@ -38,10 +49,12 @@ class Yireo_NewRelic_Model_Profiler
38
// Register the Magento request (once it is loaded in Magento) with NewRelic
39
static $request_logged = false;
40
if($request_logged == false) {
41
- $request_logged = true;
42
$request = Mage::app()->getRequest();
43
- if(!empty($request) && function_exists('newrelic_name_transaction')) {
44
- newrelic_name_transaction($request->getRequestUri());
45
}
46
}
47
}
@@ -64,7 +77,6 @@ class Yireo_NewRelic_Model_Profiler
64
{
65
self::$_enabled = true;
66
self::$_memory_get_usage = function_exists('memory_get_usage');
67
- self::init();
68
}
69
70
public static function disable()
@@ -75,11 +87,11 @@ class Yireo_NewRelic_Model_Profiler
75
public static function reset($timerName)
76
{
77
self::$_timers[$timerName] = array(
78
- 'start'=>false,
79
- 'count'=>0,
80
- 'sum'=>0,
81
- 'realmem'=>0,
82
- 'emalloc'=>0,
83
);
84
}
85
@@ -89,12 +101,14 @@ class Yireo_NewRelic_Model_Profiler
89
return;
90
}
91
92
if (empty(self::$_timers[$timerName])) {
93
self::reset($timerName);
94
}
95
if (self::$_memory_get_usage) {
96
- self::$_timers[$timerName]['realmem_start'] = memory_get_usage(true);
97
- self::$_timers[$timerName]['emalloc_start'] = memory_get_usage();
98
}
99
self::$_timers[$timerName]['start'] = microtime(true);
100
self::$_timers[$timerName]['count'] ++;
@@ -110,7 +124,9 @@ class Yireo_NewRelic_Model_Profiler
110
if (!self::$_enabled) {
111
return;
112
}
113
-
114
$time = microtime(true); // Get current time as quick as possible to make more accurate calculations
115
116
if (empty(self::$_timers[$timerName])) {
@@ -120,8 +136,8 @@ class Yireo_NewRelic_Model_Profiler
120
self::$_timers[$timerName]['sum'] += $time-self::$_timers[$timerName]['start'];
121
self::$_timers[$timerName]['start'] = false;
122
if (self::$_memory_get_usage) {
123
- self::$_timers[$timerName]['realmem'] += memory_get_usage(true)-self::$_timers[$timerName]['realmem_start'];
124
- self::$_timers[$timerName]['emalloc'] += memory_get_usage()-self::$_timers[$timerName]['emalloc_start'];
125
}
126
}
127
}
@@ -151,16 +167,16 @@ class Yireo_NewRelic_Model_Profiler
151
return $count;
152
153
case 'realmem':
154
- if (!isset(self::$_timers[$timerName]['realmem'])) {
155
- self::$_timers[$timerName]['realmem'] = -1;
156
- }
157
- return self::$_timers[$timerName]['realmem'];
158
159
case 'emalloc':
160
- if (!isset(self::$_timers[$timerName]['emalloc'])) {
161
- self::$_timers[$timerName]['emalloc'] = -1;
162
- }
163
- return self::$_timers[$timerName]['emalloc'];
164
165
default:
166
if (!empty(self::$_timers[$timerName][$key])) {
@@ -179,7 +195,8 @@ class Yireo_NewRelic_Model_Profiler
179
* Output SQl Zend_Db_Profiler
180
*
181
*/
182
- public static function getSqlProfiler($res) {
183
if(!$res){
184
return '';
185
}
2
/**
3
* NewRelic plugin for Magento
4
*
5
* @package Yireo_NewRelic
6
* @author Yireo (http://www.yireo.com/)
7
* @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
10
11
class Yireo_NewRelic_Model_Profiler
12
{
13
+ /**
14
+ * Method to initialize the profiler
15
+ *
16
+ * @access public
17
+ * @param null
18
+ * @return null
19
+ */
20
public static function init()
21
{
22
+ // Do not continue when the PHP-extension "newrelic" is not found
23
if(!extension_loaded('newrelic')) {
24
return;
25
}
26
27
+ // Do not continue when the proper functions are not loaded
28
+ if(!function_exists('newrelic_add_custom_tracer')) {
29
+ return;
30
+ }
31
+
32
// Add generic NewRelic calls that don't have dependancies on Magento
33
static $initialized = false;
34
if($initialized == false) {
49
// Register the Magento request (once it is loaded in Magento) with NewRelic
50
static $request_logged = false;
51
if($request_logged == false) {
52
$request = Mage::app()->getRequest();
53
+ if (!empty($request)) {
54
+ $request_logged = true;
55
+ if (function_exists('newrelic_name_transaction')) {
56
+ newrelic_name_transaction($request->getRequestUri());
57
+ }
58
}
59
}
60
}
77
{
78
self::$_enabled = true;
79
self::$_memory_get_usage = function_exists('memory_get_usage');
80
}
81
82
public static function disable()
87
public static function reset($timerName)
88
{
89
self::$_timers[$timerName] = array(
90
+ 'start'=>false,
91
+ 'count'=>0,
92
+ 'sum'=>0,
93
+ 'realmem'=>0,
94
+ 'emalloc'=>0,
95
);
96
}
97
101
return;
102
}
103
104
+ self::init();
105
+
106
if (empty(self::$_timers[$timerName])) {
107
self::reset($timerName);
108
}
109
if (self::$_memory_get_usage) {
110
+ self::$_timers[$timerName]['realmem_start'] = memory_get_usage(true);
111
+ self::$_timers[$timerName]['emalloc_start'] = memory_get_usage();
112
}
113
self::$_timers[$timerName]['start'] = microtime(true);
114
self::$_timers[$timerName]['count'] ++;
124
if (!self::$_enabled) {
125
return;
126
}
127
+
128
+ self::init();
129
+
130
$time = microtime(true); // Get current time as quick as possible to make more accurate calculations
131
132
if (empty(self::$_timers[$timerName])) {
136
self::$_timers[$timerName]['sum'] += $time-self::$_timers[$timerName]['start'];
137
self::$_timers[$timerName]['start'] = false;
138
if (self::$_memory_get_usage) {
139
+ self::$_timers[$timerName]['realmem'] += memory_get_usage(true)-self::$_timers[$timerName]['realmem_start'];
140
+ self::$_timers[$timerName]['emalloc'] += memory_get_usage()-self::$_timers[$timerName]['emalloc_start'];
141
}
142
}
143
}
167
return $count;
168
169
case 'realmem':
170
+ if (!isset(self::$_timers[$timerName]['realmem'])) {
171
+ self::$_timers[$timerName]['realmem'] = -1;
172
+ }
173
+ return self::$_timers[$timerName]['realmem'];
174
175
case 'emalloc':
176
+ if (!isset(self::$_timers[$timerName]['emalloc'])) {
177
+ self::$_timers[$timerName]['emalloc'] = -1;
178
+ }
179
+ return self::$_timers[$timerName]['emalloc'];
180
181
default:
182
if (!empty(self::$_timers[$timerName][$key])) {
195
* Output SQl Zend_Db_Profiler
196
*
197
*/
198
+ public static function getSqlProfiler($res)
199
+ {
200
if(!$res){
201
return '';
202
}
app/code/community/Yireo/NewRelic/etc/config.xml CHANGED
@@ -1,7 +1,7 @@
1
<?xml version="1.0"?>
2
<!--
3
/**
4
- * NewRelic plugin for Magento
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo
@@ -12,7 +12,7 @@
12
<config>
13
<modules>
14
<Yireo_NewRelic>
15
- <version>1.1.0</version>
16
</Yireo_NewRelic>
17
</modules>
18
@@ -32,25 +32,30 @@
32
<class>Yireo_NewRelic_Model</class>
33
</newrelic>
34
</models>
35
<events>
36
<controller_action_predispatch>
37
<observers>
38
<magebridge_controller_action_predispatch>
39
<type>singleton</type>
40
- <class>Yireo_NewRelic_Model_Observer</class>
41
<method>controllerActionPredispatch</method>
42
</magebridge_controller_action_predispatch>
43
</observers>
44
</controller_action_predispatch>
45
- <core_block_abstract_to_html_after>
46
<observers>
47
- <newrelic_core_block_abstract_to_html_after>
48
<type>singleton</type>
49
- <class>Yireo_NewRelic_Model_Observer</class>
50
- <method>coreBlockAbstractToHtmlAfter</method>
51
- </newrelic_core_block_abstract_to_html_after>
52
</observers>
53
- </core_block_abstract_to_html_after>
54
<model_save_after>
55
<observers>
56
<newrelic_model_save_after>
@@ -60,6 +65,7 @@
60
</newrelic_model_save_after>
61
</observers>
62
</model_save_after>
63
<model_delete_after>
64
<observers>
65
<newrelic_model_delete_after>
@@ -70,7 +76,15 @@
70
</observers>
71
</model_delete_after>
72
</events>
73
- </global>
74
75
<adminhtml>
76
<acl>
@@ -93,4 +107,15 @@
93
</resources>
94
</acl>
95
</adminhtml>
96
</config>
1
<?xml version="1.0"?>
2
<!--
3
/**
4
+ * NewRelic plugin for Magento
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo
12
<config>
13
<modules>
14
<Yireo_NewRelic>
15
+ <version>1.2.0</version>
16
</Yireo_NewRelic>
17
</modules>
18
32
<class>Yireo_NewRelic_Model</class>
33
</newrelic>
34
</models>
35
+ </global>
36
+
37
+ <frontend>
38
<events>
39
<controller_action_predispatch>
40
<observers>
41
<magebridge_controller_action_predispatch>
42
<type>singleton</type>
43
+ <class>newrelic/observer</class>
44
<method>controllerActionPredispatch</method>
45
</magebridge_controller_action_predispatch>
46
</observers>
47
</controller_action_predispatch>
48
+
49
+ <controller_action_postdispatch>
50
<observers>
51
+ <newrelic_controller_action_postdispatch>
52
<type>singleton</type>
53
+ <class>newrelic/observer</class>
54
+ <method>controllerActionPostdispatch</method>
55
+ </newrelic_controller_action_postdispatch>
56
</observers>
57
+ </controller_action_postdispatch>
58
+
59
<model_save_after>
60
<observers>
61
<newrelic_model_save_after>
65
</newrelic_model_save_after>
66
</observers>
67
</model_save_after>
68
+
69
<model_delete_after>
70
<observers>
71
<newrelic_model_delete_after>
76
</observers>
77
</model_delete_after>
78
</events>
79
+
80
+ <layout>
81
+ <updates>
82
+ <newrelic module="newrelic">
83
+ <file>newrelic.xml</file>
84
+ </newrelic>
85
+ </updates>
86
+ </layout>
87
+ </frontend>
88
89
<adminhtml>
90
<acl>
107
</resources>
108
</acl>
109
</adminhtml>
110
+
111
+ <default>
112
+ <newrelic>
113
+ <settings>
114
+ <enabled>1</enabled>
115
+ <track_controller>1</track_controller>
116
+ <real_user_monitoring>0</real_user_monitoring>
117
+ <xmit>1</xmit>
118
+ </settings>
119
+ </newrelic>
120
+ </default>
121
</config>
app/code/community/Yireo/NewRelic/etc/system.xml CHANGED
@@ -1,7 +1,7 @@
1
<?xml version="1.0"?>
2
<!--
3
/**
4
- * NewRelic plugin for Magento
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo
@@ -28,11 +28,20 @@
28
<show_in_website>1</show_in_website>
29
<show_in_store>1</show_in_store>
30
<fields>
31
<appname translate="label">
32
<label>Application Name</label>
33
<comment><![CDATA[Appears in New Relic application-overview]]></comment>
34
<frontend_type>text</frontend_type>
35
- <sort_order>1</sort_order>
36
<show_in_default>1</show_in_default>
37
<show_in_website>1</show_in_website>
38
<show_in_store>1</show_in_store>
@@ -41,17 +50,38 @@
41
<label>License Key</label>
42
<comment><![CDATA[Override of New Relic license-key]]></comment>
43
<frontend_type>text</frontend_type>
44
- <sort_order>2</sort_order>
45
<show_in_default>1</show_in_default>
46
<show_in_website>1</show_in_website>
47
<show_in_store>1</show_in_store>
48
</license>
49
<real_user_monitoring translate="label">
50
<label>Real User Monitoring</label>
51
<comment><![CDATA[Enable when your New Relic subscription includes this feature]]></comment>
52
<frontend_type>select</frontend_type>
53
<source_model>adminhtml/system_config_source_yesno</source_model>
54
- <sort_order>99</sort_order>
55
<show_in_default>1</show_in_default>
56
<show_in_website>1</show_in_website>
57
<show_in_store>1</show_in_store>
1
<?xml version="1.0"?>
2
<!--
3
/**
4
+ * NewRelic plugin for Magento
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo
28
<show_in_website>1</show_in_website>
29
<show_in_store>1</show_in_store>
30
<fields>
31
+ <enabled translate="label">
32
+ <label>Enable</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>10</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </enabled>
40
<appname translate="label">
41
<label>Application Name</label>
42
<comment><![CDATA[Appears in New Relic application-overview]]></comment>
43
<frontend_type>text</frontend_type>
44
+ <sort_order>20</sort_order>
45
<show_in_default>1</show_in_default>
46
<show_in_website>1</show_in_website>
47
<show_in_store>1</show_in_store>
50
<label>License Key</label>
51
<comment><![CDATA[Override of New Relic license-key]]></comment>
52
<frontend_type>text</frontend_type>
53
+ <sort_order>30</sort_order>
54
<show_in_default>1</show_in_default>
55
<show_in_website>1</show_in_website>
56
<show_in_store>1</show_in_store>
57
</license>
58
+ <xmit translate="label">
59
+ <label>Use xmit</label>
60
+ <comment><![CDATA[Use xmit on 'newrelic_set_appname<br/>
61
+ Warning: This gives a slight performance overhead - check the NewRelic docs for details]]></comment>
62
+ <frontend_type>select</frontend_type>
63
+ <source_model>adminhtml/system_config_source_yesno</source_model>
64
+ <sort_order>40</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>1</show_in_store>
68
+ </xmit>
69
+ <track_controller translate="label">
70
+ <label>Track Controllers</label>
71
+ <comment><![CDATA[Track the controllers as transactions.]]></comment>
72
+ <frontend_type>select</frontend_type>
73
+ <source_model>adminhtml/system_config_source_yesno</source_model>
74
+ <sort_order>50</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_store>1</show_in_store>
77
+ <show_in_default>1</show_in_default>
78
+ </track_controller>
79
<real_user_monitoring translate="label">
80
<label>Real User Monitoring</label>
81
<comment><![CDATA[Enable when your New Relic subscription includes this feature]]></comment>
82
<frontend_type>select</frontend_type>
83
<source_model>adminhtml/system_config_source_yesno</source_model>
84
+ <sort_order>60</sort_order>
85
<show_in_default>1</show_in_default>
86
<show_in_website>1</show_in_website>
87
<show_in_store>1</show_in_store>
app/design/frontend/base/default/layout/newrelic.xml ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="head">
5
+ <block type="newrelic/rum_timing_header" name="newrelic_rum_timing_header" as="newrelic.rum.timing.header" template="newrelic/rum/timing/content.phtml" />
6
+ </reference>
7
+ <reference name="before_body_end">
8
+ <block type="newrelic/rum_timing_footer" name="newrelic_rum_timing_footer" as="newrelic.rum.timing.footer" template="newrelic/rum/timing/content.phtml" after="-" />
9
+ </reference>
10
+ </default>
11
+ </layout>
app/design/frontend/base/default/template/newrelic/rum/timing/content.phtml ADDED
@@ -0,0 +1,3 @@
1
+ <?php
2
+ /* @var $this Yireo_Newrelic_Block_Rum_Timing_Abstract */
3
+ echo $this->getContentHtml();
app/etc/modules/Yireo_NewRelic.xml CHANGED
@@ -5,7 +5,7 @@
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo (http://www.yireo.com/)
8
- * @copyright Copyright (c) 2011 Yireo (http://www.yireo.com/)
9
* @license Open Software License
10
*/
11
-->
5
*
6
* @package Yireo_NewRelic
7
* @author Yireo (http://www.yireo.com/)
8
+ * @copyright Copyright (c) 2013 Yireo (http://www.yireo.com/)
9
* @license Open Software License
10
*/
11
-->
package.xml CHANGED
@@ -1,2 +1,2 @@
1
<?xml version="1.0"?>
2
- <package><name>Yireo_NewRelic</name><version>1.1.0</version><stability>stable</stability><license>Open Source License</license><channel>community</channel><extends></extends><summary>No summary</summary><description>No description</description><notes>No notes</notes><authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors><date>2013-05-13</date><time>23:00:54</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Yireo_NewRelic.xml" hash="ca797759fe9ecc807f986141989cee17"/></dir></dir><dir name="code"><dir name="community"><dir name="Yireo"><dir name="NewRelic"><dir name="etc"><file name="config.xml" hash="73d0df648e9baee26efabaa6cea4440a"/><file name="system.xml" hash="091a15b1f949db3213a72479e1ed5f79"/></dir><dir name="Helper"><file name="Data.php" hash="afb3f139ea7dc1cd90f11151947bd38c"/></dir><dir name="Model"><file name="Observer.php" hash="317204b51a372f050b8678866f2ec0b3"/><file name="Profiler.php" hash="86dfde082f5f0d5cf345205799ed301d"/></dir></dir></dir></dir></dir></dir></target></contents></package>
1
<?xml version="1.0"?>
2
+ <package><name>Yireo_NewRelic</name><version>1.2.0</version><stability>stable</stability><license>Open Source License</license><channel>community</channel><extends></extends><summary>No summary</summary><description>No description</description><notes>No notes</notes><authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors><date>2013-12-22</date><time>8:21:39</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Yireo_NewRelic.xml" hash="2f2eccc31fd844df834294385486c001"/></dir></dir><dir name="code"><dir name="community"><dir name="Varien"><file name="Profiler.php" hash="e55d75674c132b06a6eaed0467c5c0f5"/></dir><dir name="Yireo"><dir name="NewRelic"><dir name="Block"><dir name="Rum"><dir name="Timing"><file name="Abstract.php" hash="d80f63580a1e88c600f6981b21e19460"/><file name="Footer.php" hash="144812710e16c89c8b753538173657b2"/><file name="Header.php" hash="a53ee01441b34d9efe25404bc4cb8772"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="9722a9b110766bf061f198670c5bee93"/><file name="system.xml" hash="07bbdc6c35b1eb1b0eb4d452b3079875"/></dir><dir name="Helper"><file name="Data.php" hash="f2b8fa2db95a16050d174c24de813618"/></dir><dir name="Model"><file name="Observer.php" hash="0b24f90c76234cb0dcb5f99c50a8bb5f"/><file name="Profiler.php" hash="adea76be2a1e549c6f1fcddb06c3107d"/></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="newrelic"><dir name="rum"><dir name="timing"><file name="content.phtml" hash="9eb32c31c80f9ef2db1132f4becb3808"/></dir></dir></dir></dir><dir name="layout"><file name="newrelic.xml" hash="c2f3fc2682e867855a0d3924fd709e67"/></dir></dir></dir></dir></dir></dir></target></contents></package>