public function __construct($template) { $this->template = $template; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ViewTwig::render'); } }
/** * Add user-defined functions or methods to the list to be instrumented. * Internal PHP functions cannot have custom tracing. * * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-custom-tracer * * @param string $callable * * @return bool */ public function addCustomTracer($callable) { if (!$this->isLoaded()) { return false; } return newrelic_add_custom_tracer($callable); }
/** * Hook to record all fron controller events * * @param Varien_Event_Observer $observer */ public function controller_action_predispatch(Varien_Event_Observer $observer) { try { if (extension_loaded('newrelic')) { $controllerAction = $observer->getControllerAction(); $request = $controllerAction->getRequest(); $controllerName = explode("_", $request->getControllerName()); if (Mage::getStoreConfig('newrelic/settings/ignore_admin_routes') && $request->getRouteName() == 'adminhtml' || $request->getModuleName() == 'admin' || in_array('adminhtml', $controllerName)) { Mage::helper('proxiblue_newrelic')->setAppName(false); newrelic_ignore_transaction(); newrelic_ignore_apdex(); return $this; } if (mage::helper('proxiblue_newrelic')->ignoreModule($request->getModuleName()) === true) { Mage::helper('proxiblue_newrelic')->setAppName(false); newrelic_ignore_transaction(); newrelic_ignore_apdex(); return $this; } if (Mage::getStoreConfig('newrelic/settings/named_transactions')) { $route = $request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName(); if (Mage::getStoreConfig('newrelic/settings/add_module_to_named_transactions')) { $route .= ' (module: ' . $request->getModuleName() . ')'; } newrelic_name_transaction($route); Mage::helper('proxiblue_newrelic')->setAppName(true); return $this; } // tracers $tracerList = unserialize(Mage::getStoreConfig('newrelic/settings/custom_tracers')); if (is_array($tracerList) && count($tracerList) > 0) { foreach ($tracerList as $tracer) { newrelic_add_custom_tracer($tracer['string']); } } } } catch (Exception $e) { mage::logException($e); } }
/** * Method to initialize the profiler * * @access public * @param null * @return null */ public static function init() { // Do not continue when the PHP-extension "newrelic" is not found if (!extension_loaded('newrelic')) { return; } // Do not continue when the proper functions are not loaded if (!function_exists('newrelic_add_custom_tracer')) { return; } // Add generic NewRelic calls that don't have dependancies on Magento static $initialized = false; if ($initialized == false) { newrelic_add_custom_tracer('Mage::getModel'); newrelic_add_custom_tracer('Mage::getSingleton'); newrelic_add_custom_tracer('Mage::helper'); newrelic_add_custom_tracer('Mage::log'); newrelic_add_custom_tracer('Mage_Core_Model_App::_initCache'); newrelic_add_custom_tracer('Mage_Core_Model_Config::loadDb'); newrelic_add_custom_tracer('Mage_Core_Model_Config::loadModules'); newrelic_add_custom_tracer('include'); newrelic_add_custom_tracer('include_once'); newrelic_add_custom_tracer('require'); newrelic_add_custom_tracer('require_once'); $initialized = true; } // Register the Magento request (once it is loaded in Magento) with NewRelic static $request_logged = false; if ($request_logged == false) { $request = Mage::app()->getRequest(); if (!empty($request)) { $request_logged = true; if (function_exists('newrelic_name_transaction')) { newrelic_name_transaction($request->getRequestUri()); } } } }
/** * Add a custom method to have traced by NewRelic * * @param string $method * @return void */ public function tracer($method) { if (!$this->hasNewRelic()) { return; } newrelic_add_custom_tracer($method); }
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ProcessIncrementalResult'); newrelic_add_custom_tracer('CheckForSpam'); newrelic_add_custom_tracer('loadPageRunData'); newrelic_add_custom_tracer('getBreakdown'); newrelic_add_custom_tracer('GetVisualProgress'); newrelic_add_custom_tracer('DevToolsGetConsoleLog'); newrelic_add_custom_tracer('WaitForSystemLoad'); } chdir('..'); //$debug = true; require_once 'common.inc'; require_once 'archive.inc'; require_once 'page_data.inc'; require_once 'object_detail.inc'; require_once 'harTiming.inc'; require_once 'video.inc'; require_once 'breakdown.inc'; require_once 'devtools.inc.php'; require_once './video/visualProgress.inc.php'; require_once './video/avi2frames.inc.php'; if (!isset($included)) { error_reporting(E_ERROR | E_PARSE); header('Content-type: text/plain'); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); } set_time_limit(3600); ignore_user_abort(true);
if (is_array($val)) { DealWithMagicQuotes($val); } else { $val = stripslashes($val); } } } DealWithMagicQuotes($GLOBALS); } require_once 'common.inc'; require_once './ec2/ec2.inc.php'; set_time_limit(300); if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('WriteJob'); newrelic_add_custom_tracer('AddJobFile'); newrelic_add_custom_tracer('LogTest'); } $redirect_cache = array(); $error = NULL; $xml = false; $usingAPI = false; if (!strcasecmp($req_f, 'xml')) { $xml = true; } $json = false; if (!strcasecmp($req_f, 'json')) { $json = true; } $headless = false; if (array_key_exists('headless', $settings) && $settings['headless']) { $headless = true;
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('UpdateFeeds'); } /** * Update the feeds * */ function UpdateFeeds() { if (is_file('./settings/feeds.inc')) { if (!is_dir('./tmp')) { mkdir('./tmp', 0777); } $feedData = array(); $lock = Lock("Update Feeds", false); if (isset($lock)) { // load the list of feeds require_once './settings/feeds.inc'; require_once './lib/simplepie.inc'; // loop through and update each one foreach ($feeds as $category => &$feedList) { $feedData[$category] = array(); foreach ($feedList as $feedSource => $feedUrl) { $feedUrl = trim($feedUrl); if (strlen($feedUrl)) { $feed = new SimplePie(); if ($feed) { $rawFeed = trim(http_fetch($feedUrl)); $feed->set_raw_data($rawFeed);
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ProcessIncrementalResult'); newrelic_add_custom_tracer('CompressTextFiles'); newrelic_add_custom_tracer('loadPageStepData'); newrelic_add_custom_tracer('loadVideo'); newrelic_add_custom_tracer('GetVisualProgressForStep'); newrelic_add_custom_tracer('GetDevToolsCPUTimeForStep'); newrelic_add_custom_tracer('getBreakdown'); newrelic_add_custom_tracer('GetVisualProgress'); newrelic_add_custom_tracer('DevToolsGetConsoleLog'); newrelic_add_custom_tracer('ExtractZipFile'); } chdir('..'); //$debug = true; require_once 'common.inc'; require_once 'archive.inc'; require_once 'page_data.inc'; require_once 'object_detail.inc'; require_once 'harTiming.inc'; require_once 'video.inc'; require_once 'breakdown.inc'; require_once 'devtools.inc.php'; require_once './video/visualProgress.inc.php'; require_once './video/avi2frames.inc.php'; require_once __DIR__ . '/../include/ResultProcessing.php'; if (!isset($included)) { error_reporting(E_ERROR | E_PARSE); header('Content-type: text/plain'); header("Cache-Control: no-cache, must-revalidate");
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('GetVisualProgress'); newrelic_add_custom_tracer('GetImageHistogram'); } require_once 'devtools.inc.php'; /** * Calculate the progress for all of the images in a given directory */ function GetVisualProgress($testPath, $run, $cached, $options = null, $end = null, $startOffset = null) { $frames = null; if (substr($testPath, 0, 1) !== '.') { $testPath = './' . $testPath; } $testInfo = GetTestInfo($testPath); $completed = IsTestRunComplete($run, $testInfo); $video_directory = "{$testPath}/video_{$run}"; if ($cached) { $video_directory .= '_cached'; } $cache_file = "{$testPath}/{$run}.{$cached}.visual.dat"; if (!isset($startOffset)) { $startOffset = 0; } $visual_data_file = "{$testPath}/llab_{$run}.{$cached}.visual.dat"; if (gz_is_file($visual_data_file)) { $visual_data = json_decode(gz_file_get_contents($visual_data_file), true); // see if we are processing an externally-uploaded visual data file if (isset($visual_data['timespans']['page_load']['startOffset'])) {
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ProcessIncrementalResult'); newrelic_add_custom_tracer('CheckForSpam'); newrelic_add_custom_tracer('loadPageRunData'); newrelic_add_custom_tracer('getBreakdown'); newrelic_add_custom_tracer('GetVisualProgress'); newrelic_add_custom_tracer('DevToolsGetConsoleLog'); } chdir('..'); //$debug = true; require_once 'common.inc'; require_once 'archive.inc'; require_once './lib/pclzip.lib.php'; require_once 'page_data.inc'; require_once 'object_detail.inc'; require_once 'harTiming.inc'; require_once 'video.inc'; require_once 'breakdown.inc'; require_once 'devtools.inc.php'; require_once './video/visualProgress.inc.php'; require_once './video/avi2frames.inc.php'; if (!isset($included)) { error_reporting(E_ERROR | E_PARSE); header('Content-type: text/plain'); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); } set_time_limit(60 * 5); ignore_user_abort(true);
/** * API equivalent of the newrelic.transaction_tracer.customi setting. It allows you to add functions or methods to * the list to be instrumented. * * @param string $tracer * * @return $this */ public function addCustomTracer($tracer = 'classname::function_name') { if ($this->active) { newrelic_add_custom_tracer($tracer); } return $this; }
/** * Adds a user defined functions or methods to the list to be instrumented. * * Internal PHP functions cannot have custom tracing. * * @param string $name Either 'functionName', or 'ClassName::functionName' */ public function addCustomTracer($name) { if ($this->skip()) { return; } newrelic_add_custom_tracer($name); }
<?php // Jobs that need to run every 5 minutes chdir('..'); include 'common.inc'; ignore_user_abort(true); set_time_limit(1200); error_reporting(E_ALL); if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('EC2_TerminateIdleInstances'); newrelic_add_custom_tracer('EC2_StartNeededInstances'); newrelic_add_custom_tracer('EC2_DeleteOrphanedVolumes'); newrelic_add_custom_tracer('SBL_Update'); } $lock = Lock("cron-5", false, 1200); if (!isset($lock)) { exit(0); } // Clear the user cache if we drop below 10% or 5MB available if (function_exists("apc_sma_info") && function_exists("apc_clear_cache")) { $info = apc_sma_info(true); if (isset($info['num_seg']) && isset($info['seg_size']) && isset($info['avail_mem'])) { $total = $info['seg_size'] * $info['num_seg']; $avail = $info['avail_mem']; if ($total > 0) { $pct = $avail / $total; if ($avail < 5000000 || $pct < 0.1) { apc_clear_cache("user"); apc_clear_cache(); } }
<?php require_once './common_lib.inc'; require_once './lib/aws/aws-autoloader.php'; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('EC2_StartInstanceIfNeeded'); newrelic_add_custom_tracer('EC2_StartInstance'); newrelic_add_custom_tracer('EC2_TerminateIdleInstances'); newrelic_add_custom_tracer('EC2_GetRunningInstances'); newrelic_add_custom_tracer('EC2_SendInstancesOffline'); newrelic_add_custom_tracer('EC2_StartNeededInstances'); newrelic_add_custom_tracer('EC2_TerminateInstance'); newrelic_add_custom_tracer('EC2_LaunchInstance'); } /** * Tests are pending for the given location, start instances as necessary * * @param mixed $location */ function EC2_StartInstanceIfNeeded($ami) { $target = 1; // just support 1 instance at a time for now $needed = false; $lock = Lock('ec2-instances', true, 120); if ($lock) { $instances = json_decode(file_get_contents('./tmp/ec2-instances.dat'), true); if (!$instances || !is_array($instances)) { $instances = array(); } if (!isset($instances[$ami])) {
/** * {@inheritdoc} */ public function addCustomTracer($name) { if ($this->extensionLoaded()) { newrelic_add_custom_tracer($name); } }
/** * @param string $function functionName / ClassName::functionName */ public static function addTracer($function) { if (\VrtakCZ\NewRelic\Tracy\Bootstrap::isEnabled()) { newrelic_add_custom_tracer($function); } }
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('CheckUrl'); newrelic_add_custom_tracer('CheckIp'); newrelic_add_custom_tracer('WptHookValidateTest'); newrelic_add_custom_tracer('GetRedirect'); } // deal with magic quotes being enabled if (get_magic_quotes_gpc()) { function DealWithMagicQuotes(&$arr) { foreach ($arr as $key => &$val) { if ($key == "GLOBALS") { continue; } if (is_array($val)) { DealWithMagicQuotes($val); } else { $val = stripslashes($val); } } } DealWithMagicQuotes($GLOBALS); } require_once 'common.inc'; require_once './ec2/ec2.inc.php'; set_time_limit(300); $redirect_cache = array(); $error = NULL; $xml = false;
<?php require_once 'devtools.inc.php'; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ProcessAVIVideo'); newrelic_add_custom_tracer('Video2PNG'); newrelic_add_custom_tracer('FindAVIViewport'); newrelic_add_custom_tracer('EliminateDuplicateAVIFiles'); newrelic_add_custom_tracer('ProcessVideoFrames'); } /** * Re-process all of the video for an existing test * * @param mixed $id */ function ReprocessVideo($id) { $testPath = './' . GetTestPath($id); if (is_dir($testPath)) { $lock = LockTest($id); if (isset($lock)) { $cacheFiles = glob("{$testPath}/*.dat.gz"); if ($cacheFiles && is_array($cacheFiles) && count($cacheFiles)) { foreach ($cacheFiles as $cacheFile) { unlink($cacheFile); } } $videoFiles = glob("{$testPath}/*.mp4"); if ($videoFiles && is_array($videoFiles) && count($videoFiles)) { foreach ($videoFiles as $video) { if (preg_match('/^.*\\/(?P<run>[0-9]+)(?P<cached>_Cached)?_video\\.mp4$/i', $video, $matches)) {
/** * @param $name * @return boolean true on success */ public function addTrace($name) { return newrelic_add_custom_tracer($name); }
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('GetTestStatus'); newrelic_add_custom_tracer('calculatePageStats'); newrelic_add_custom_tracer('xmlDomains'); newrelic_add_custom_tracer('xmlBreakdown'); newrelic_add_custom_tracer('xmlRequests'); newrelic_add_custom_tracer('GetVisualProgress'); newrelic_add_custom_tracer('ArchiveApi'); } $msStart = microtime(true); //$debug=true; require_once 'common.inc'; require_once 'page_data.inc'; require_once 'testStatus.inc'; require_once 'video/visualProgress.inc.php'; require_once 'domains.inc'; require_once 'breakdown.inc'; require_once 'devtools.inc.php'; require_once 'archive.inc'; // see if we are sending abbreviated results $pagespeed = 0; if (array_key_exists('pagespeed', $_REQUEST)) { $pagespeed = (int) $_REQUEST['pagespeed']; } if (isset($test['test']) && $test['test']['batch']) { BatchResult($id, $testPath); } else { // see if the test is actually finished $status = GetTestStatus($id);
/** * {@inheritdoc} */ public function addCustomTracer($name) { if (!$this->extensionLoaded()) { return $this; } newrelic_add_custom_tracer($name); return $this; }
<?php $DevToolsCacheVersion = '1.7'; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('GetTimeline'); newrelic_add_custom_tracer('GetDevToolsRequests'); newrelic_add_custom_tracer('GetDevToolsEvents'); newrelic_add_custom_tracer('DevToolsGetConsoleLog'); newrelic_add_custom_tracer('DevToolsGetCPUSlices'); newrelic_add_custom_tracer('GetDevToolsCPUTime'); } /** * Load the timeline data for the given test run (from a timeline file or a raw dev tools dump) * * @param mixed $testPath * @param mixed $run * @param mixed $cached * @param mixed $timeline */ function GetTimeline($testPath, $run, $cached, &$timeline, &$startOffset) { $ok = false; $cachedText = ''; if ($cached) { $cachedText = '_Cached'; } //$timelineFile = "$testPath/$run{$cachedText}_devtools.json"; $timelineFile = "{$testPath}/devtools.json"; if (!gz_is_file($timelineFile)) { $timelineFile = "{$testPath}/{$run}{$cachedText}_timeline.json"; }
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('tbnDrawWaterfall'); newrelic_add_custom_tracer('tbnDrawChecklist'); newrelic_add_custom_tracer('GenerateThumbnail'); newrelic_add_custom_tracer('SendImage'); newrelic_add_custom_tracer('getRequests'); newrelic_add_custom_tracer('loadPageRunData'); } if (array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER) && strlen(trim($_SERVER['HTTP_IF_MODIFIED_SINCE']))) { header("HTTP/1.0 304 Not Modified"); } else { include __DIR__ . '/common.inc'; require_once __DIR__ . '/include/TestInfo.php'; require_once __DIR__ . '/include/TestStepResult.php'; global $testPath, $run, $cached, $step; // from common.inc $file = $_GET['file']; // make sure nobody is trying to use us to pull down external images from somewhere else if (strpos($file, ':') === FALSE && strpos($file, '//') === FALSE && strpos($file, '\\') === FALSE) { $fileParts = explode('.', $file); $parts = pathinfo($file); $type = $parts['extension']; $fit = max(min(@$_REQUEST['fit'], 1000), 0); $newWidth = 250; $w = @$_REQUEST['width']; if ($w && $w > 20 && $w < 1000) { $newWidth = $w; } $img = null;
<?php $DevToolsCacheVersion = '1.7'; require_once __DIR__ . '/include/TestPaths.php'; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('GetTimeline'); newrelic_add_custom_tracer('GetDevToolsRequests'); newrelic_add_custom_tracer('GetDevToolsEventsForStep'); newrelic_add_custom_tracer('DevToolsGetConsoleLog'); newrelic_add_custom_tracer('DevToolsGetCPUSlicesForStep'); newrelic_add_custom_tracer('GetDevToolsCPUTime'); newrelic_add_custom_tracer('ParseDevToolsEvents'); newrelic_add_custom_tracer('DevToolsMatchEvent'); } /** * Load the timeline data for the given test run (from a timeline file or a raw dev tools dump) * * @param mixed $testPath * @param mixed $run * @param mixed $cached * @param mixed $timeline */ function GetTimeline($testPath, $run, $cached, &$timeline, &$startOffset) { $ok = false; $cachedText = ''; if ($cached) { $cachedText = '_Cached'; } $timelineFile = "{$testPath}/{$run}{$cachedText}_devtools.json"; if (!gz_is_file($timelineFile)) {
<?php require_once 'devtools.inc.php'; if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ProcessAVIVideo'); newrelic_add_custom_tracer('Video2PNG'); newrelic_add_custom_tracer('FindAVIViewport'); newrelic_add_custom_tracer('EliminateDuplicateAVIFiles'); newrelic_add_custom_tracer('ProcessVideoFrames'); newrelic_add_custom_tracer('CreateHistogram'); newrelic_add_custom_tracer('PythonVisualMetrics'); } /** * Re-process all of the video for an existing test * * @param mixed $id */ function ReprocessVideo($id) { $testPath = './' . GetTestPath($id); if (is_dir($testPath)) { $lock = LockTest($id); if (isset($lock)) { $cacheFiles = glob("{$testPath}/*.dat.gz"); if ($cacheFiles && is_array($cacheFiles) && count($cacheFiles)) { foreach ($cacheFiles as $cacheFile) { unlink($cacheFile); } } $videoFiles = glob("{$testPath}/*.mp4"); if ($videoFiles && is_array($videoFiles) && count($videoFiles)) {
<?php if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('GetUpdate'); newrelic_add_custom_tracer('GetVideoJob'); newrelic_add_custom_tracer('GetJob'); newrelic_add_custom_tracer('GetJobFile'); newrelic_add_custom_tracer('CheckCron'); newrelic_add_custom_tracer('ProcessTestShard'); newrelic_add_custom_tracer('GetTesters'); newrelic_add_custom_tracer('LockLocation'); } chdir('..'); include 'common.inc'; error_reporting(0); set_time_limit(600); $is_json = array_key_exists('f', $_GET) && $_GET['f'] == 'json'; $locations = explode(',', $_GET['location']); $key = array_key_exists('key', $_GET) ? $_GET['key'] : ''; $recover = array_key_exists('recover', $_GET) ? $_GET['recover'] : ''; $pc = array_key_exists('pc', $_GET) ? $_GET['pc'] : ''; $ec2 = array_key_exists('ec2', $_GET) ? $_GET['ec2'] : ''; $tester = null; if (strlen($ec2)) { $tester = $ec2; } elseif (strlen($pc)) { $tester = $pc . '-' . trim($_SERVER['REMOTE_ADDR']); } else { $tester = trim($_SERVER['REMOTE_ADDR']); } $dnsServers = '';
require_once 'page_data.inc'; ignore_user_abort(true); set_time_limit(60 * 50); // disconnect the caller header("Content-Length: 0", true); ob_end_flush(); flush(); ob_end_clean(); if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ArchiveTest'); newrelic_add_custom_tracer('loadAllPageData'); newrelic_add_custom_tracer('SendBeacon'); newrelic_add_custom_tracer('SendCallback'); } if (array_key_exists('test', $_REQUEST)) { $id = $_REQUEST['test']; if (ValidateTestId($id)) { $testPath = './' . GetTestPath($id); $testInfo = GetTestInfo($id); // see if we need to log the raw test data $now = time(); $allowLog = true; $logPrivateTests = GetSetting('logPrivateTests'); if ($testInfo['private'] && $logPrivateTests !== false && $logPrivateTests == 0) { $allowLog = false; } $pageLog = GetSetting('logTestResults'); if ($allowLog && $pageLog !== false && strlen($pageLog)) {
} else { $val = stripslashes($val); } } } DealWithMagicQuotes($GLOBALS); } require_once 'common.inc'; require_once './ec2/ec2.inc.php'; set_time_limit(300); if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ValidateKey'); newrelic_add_custom_tracer('ValidateURL'); newrelic_add_custom_tracer('SubmitUrl'); newrelic_add_custom_tracer('GetRedirect'); newrelic_add_custom_tracer('CheckIp'); } $redirect_cache = array(); $error = NULL; $xml = false; $usingAPI = false; if (!strcasecmp($req_f, 'xml')) { $xml = true; } $json = false; if (!strcasecmp($req_f, 'json')) { $json = true; } $headless = false; if (array_key_exists('headless', $settings) && $settings['headless']) { $headless = true;
/** * Add some functions for NewRelic * * @access private * * @param null * * @return null */ private function loadNewRelic() { if (extension_loaded('newrelic_add_custom_tracer')) { newrelic_add_custom_tracer('MageBridgeModelProxy::getCURL'); } }