-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Several small fixes and enhancements #115
base: master
Are you sure you want to change the base?
Changes from all commits
0ffd5ec
1bb665a
de5860f
63e2e96
b16bbb4
04ddf70
6cf0d4f
13654e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "xhprof/xhgui", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The project is all in one: PHP extension and gui. For that reason using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, please propose one, I'll add it to the changeset. The question is: If these changes are going to be taken into this current project, I'm perfectly fine with preinheimer/xhprof. Or anything. If not, I'll have to stick to my fork... |
||
"description": "XHGUI is a GUI for the XHProf PHP extension, using a database backend, and pretty graphs to make it easy to use and interpret.", | ||
"keywords": ["php", "profiling", "xhprof", "gui"], | ||
"authors": [ | ||
{ | ||
"name": "Changhao Jiang", | ||
"role": "Creator" | ||
}, | ||
{ | ||
"name": "Kannan Muthukkaruppan", | ||
"role": "Creator" | ||
}, | ||
{ | ||
"name": "Venkat Venkataramani", | ||
"role": "Creator" | ||
}, | ||
{ | ||
"name": "George Cabrera", | ||
"role": "Additional Contributor - UI Enhancements" | ||
}, | ||
{ | ||
"name": "Paul Saab", | ||
"role": "Additional Contributor - FreeBSD port" | ||
}, | ||
{ | ||
"name": "Lorenzo Perone", | ||
"role": "Additional Contributor " | ||
} | ||
], | ||
"license": "Apache" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,32 @@ | |
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; | ||
} | ||
|
||
include(dirname(__FILE__) . '/../xhprof_lib/config.php'); | ||
// Search for config in different places - adding constant and env | ||
if(defined('XHPROF_CONFIG') && is_file(XHPROF_CONFIG)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for changes in |
||
require_once XHPROF_CONFIG; | ||
} | ||
else { | ||
$XHPROF_CONFIG = getenv('XHPROF_CONFIG'); | ||
if ( ! empty($XHPROF_CONFIG) && is_file($XHPROF_CONFIG)) { | ||
require_once $XHPROF_CONFIG; | ||
} elseif ( ! empty($_SERVER['XHPROF_CONFIG']) && is_file($_SERVER['XHPROF_CONFIG'])) { | ||
require_once $_SERVER['XHPROF_CONFIG']; | ||
} else { | ||
require_once(XHPROF_LIB_ROOT . "/config.php"); | ||
} | ||
} | ||
|
||
function getExtensionName() | ||
{ | ||
if (extension_loaded('tideways_xhprof')) | ||
{ | ||
return 'tideways_xhprof'; | ||
} | ||
if (extension_loaded('tideways')) | ||
{ | ||
return 'tideways'; | ||
}elseif(extension_loaded('xhprof')) { | ||
} | ||
elseif(extension_loaded('xhprof')) { | ||
return 'xhprof'; | ||
} | ||
return false; | ||
|
@@ -51,32 +69,72 @@ public static function __callstatic($name, $arguments) | |
} | ||
|
||
// Only users from authorized IP addresses may control Profiling | ||
if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs) || PHP_SAPI == 'cli') | ||
{ | ||
/* Backwards Compatibility getparam check*/ | ||
if (!isset($_xhprof['getparam'])) | ||
{ | ||
$_xhprof['getparam'] = '_profile'; | ||
} | ||
|
||
if (isset($_GET[$_xhprof['getparam']])) | ||
{ | ||
//Give them a cookie to hold status, and redirect back to the same page | ||
setcookie('_profile', $_GET[$_xhprof['getparam']]); | ||
$newURI = str_replace(array($_xhprof['getparam'].'=1',$_xhprof['getparam'].'=0'), '', $_SERVER['REQUEST_URI']); | ||
header("Location: $newURI"); | ||
exit; | ||
} | ||
|
||
if (isset($_COOKIE['_profile']) && $_COOKIE['_profile'] | ||
|| PHP_SAPI == 'cli' && ( (isset($_SERVER[$envVarName]) && $_SERVER[$envVarName]) | ||
|| (isset($_ENV[$envVarName]) && $_ENV[$envVarName]))) | ||
{ | ||
$_xhprof['display'] = true; | ||
$_xhprof['doprofile'] = true; | ||
$_xhprof['type'] = 1; | ||
} | ||
unset($envVarName); | ||
if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs) || PHP_SAPI == 'cli') { | ||
|
||
/* Backwards Compatibility getparam check*/ | ||
if ( ! isset($_xhprof['getparam'])) { | ||
$_xhprof['getparam'] = '_profile'; | ||
} | ||
|
||
if ( ! isset($_xhprof['displayparam'])) { | ||
$_xhprof['displayparam'] = '_display'; | ||
} | ||
|
||
$handleRuntimeToggle = function($key, $uri, $cookieName = null) { | ||
if (isset($_GET[ $key ])) { | ||
if (null === $cookieName) { | ||
$cookieName = $key; | ||
} | ||
// Give them a cookie to hold status, and redirect back to the same page | ||
if ($_GET[ $key ] === "1") { | ||
setcookie($cookieName, $_GET[ $key ]); | ||
} elseif ($_GET[ $key ] === "0") { | ||
setcookie($cookieName, null, - 1); | ||
unset($_COOKIE[ $cookieName ]); | ||
} | ||
|
||
$cleanURI = str_replace(array( | ||
'&' . $key . '=1', | ||
'&' . $key . '=0', | ||
'?' . $key . '=1', | ||
'?' . $key . '=0', | ||
), '', $uri); | ||
|
||
return [ true, $cleanURI ]; | ||
} else { | ||
return [ false, $uri ]; | ||
} | ||
}; | ||
|
||
$toggleParams = [ $_xhprof['getparam'], $_xhprof['displayparam'] ]; | ||
|
||
$currentURI = $_SERVER['REQUEST_URI']; | ||
$changes = false; | ||
foreach($toggleParams as $toggleParam) { | ||
list($changed, $currentURI) = $handleRuntimeToggle($toggleParam, $currentURI); | ||
$changes = ($changes or $changed); | ||
} | ||
|
||
if (isset($_COOKIE[ $_xhprof['getparam'] ]) && $_COOKIE[ $_xhprof['displayparam'] ] | ||
|| PHP_SAPI == 'cli' && ((isset($_SERVER[ $envVarName ]) && $_SERVER[ $envVarName ]) | ||
|| (isset($_ENV[ $envVarName ]) && $_ENV[ $envVarName ]))) { | ||
$_xhprof['doprofile'] = true; | ||
$_xhprof['type'] = 1; | ||
} | ||
|
||
if (isset($_COOKIE[ $_xhprof['displayparam'] ]) && $_COOKIE[ $_xhprof['displayparam'] ] | ||
|| PHP_SAPI == 'cli' && ((isset($_SERVER[ $envVarName ]) && $_SERVER[ $envVarName ]) | ||
|| (isset($_ENV[ $envVarName ]) && $_ENV[ $envVarName ]))) { | ||
$_xhprof['display'] = true; | ||
} | ||
|
||
if (true === $changes) { | ||
header('HTTP/1.1 302 Found'); | ||
header("Location: $currentURI"); | ||
die("Redirecting you to " . $currentURI); | ||
} | ||
|
||
unset($envVarName); | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,22 @@ | |
if (!defined('XHPROF_LIB_ROOT')) { | ||
define('XHPROF_LIB_ROOT', dirname(dirname(__FILE__)) . '/xhprof_lib'); | ||
} | ||
require_once (XHPROF_LIB_ROOT . "/config.php"); | ||
|
||
// Search for config in different places - adding constant and env | ||
if(defined('XHPROF_CONFIG') && is_file(XHPROF_CONFIG)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for checking in all these places (also prefixing environment variables with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getenv() only finds the env variables on command line, but (at least in my environment) not those set in the apache config (SetEnv...). Both cases might be useful, depending on command line / webserver usage. Agree on ENV_, adding to change list.. |
||
require_once XHPROF_CONFIG; | ||
} | ||
else { | ||
$XHPROF_CONFIG = getenv('XHPROF_CONFIG'); | ||
if ( ! empty($XHPROF_CONFIG) && is_file($XHPROF_CONFIG)) { | ||
require_once $XHPROF_CONFIG; | ||
} elseif ( ! empty($_SERVER['XHPROF_CONFIG']) && is_file($_SERVER['XHPROF_CONFIG'])) { | ||
require_once $_SERVER['XHPROF_CONFIG']; | ||
} else { | ||
require_once(XHPROF_LIB_ROOT . "/config.php"); | ||
} | ||
} | ||
|
||
include_once XHPROF_LIB_ROOT . '/display/xhprof.php'; | ||
include (XHPROF_LIB_ROOT . "/utils/common.php"); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,11 @@ | |
$_xhprof['dbpass'] = 'password'; | ||
$_xhprof['dbname'] = 'xhprof'; | ||
$_xhprof['dbadapter'] = 'Pdo'; | ||
$_xhprof['servername'] = 'myserver'; | ||
$_xhprof['servername'] = 's01'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because the table structure has a CHAR(3) in the current version, and when I first copied these settings, they ended up breaking all INSERTs because "myserver" is 8 chars long. I thought it would be more intuitive to have an example with 3 chars, so no need to change table structure, but it doesn't fail on the first try. |
||
$_xhprof['namespace'] = 'myapp'; | ||
$_xhprof['url'] = 'http://url/to/xhprof/xhprof_html'; | ||
$_xhprof['getparam'] = "_profile"; | ||
$_xhprof['displayparam'] = "_display"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/* | ||
* MySQL/MySQLi/PDO ONLY | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
|
||
<tr> | ||
<td style="background-color: <?php echo $color; ?>;"><span style="display: none"><?php echo $color; ?></span> </td> | ||
<td><a href="index.php?run=<?php echo $run1; ?>&symbol=<?php echo urlencode($element['fn']); ?>"><?php echo htmlentities($element['fn'], ENT_QUOTES, 'UTF-8'); ?></a></td> | ||
<td><a href="<?php echo $_xhprof['url']; ?>/index.php?run=<?php echo $run1; ?>&symbol=<?php echo urlencode($element['fn']); ?>"><?php echo htmlentities($element['fn'], ENT_QUOTES, 'UTF-8'); ?></a></td> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which scenarios without this change something breaks? I have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, this is one of the situations where not having the whole xhprof code in the document root breaks it (but, for example, only Alias as suggested in the original version, or a symlink of xhprof_html). Putting in this not only fixes xhprof for that case, but potentially also enables the use of a dedicated virtual host for it (although I haven't tested the latter yet), which might be very useful when comparing, for example, the results of different development hosts. |
||
<td><?php echo isset($element['ct'])?$element['ct']:''; ?></td> | ||
<td><?php echo isset($element['wt'])?$element['wt']:''; ?></td> | ||
<td><?php echo isset($element['cpu'])?$element['cpu']:''; ?></td> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why these lines are indented differently now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it looks more intuitive to me to put all the steps pertaining to editing the configuration under it...