Skip to content
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

PostgreSQL support #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
# Netbeans project files
#
/nbproject

#
# IntelliJ IDEA project files
#
.idea
*.iml
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
3. Copy xhprof_lib/config.sample.php to xhprof_lib/config.php
4. Edit xhprof_lib/config.php with your database type and credentials. Set control IPs, and other fun stuff
Control IPs allow you to specify which IPs will be shown the footer linking directly to the results, and also which IPs will be able to turn profiling on and off
You can set this value to FALSE, which disables that protection all togethor.
You can set this value to FALSE, which disables that protection altogether.
5. Create a table as required for your database, SQL is available inside utils/Db/<database of choice>.php. If you're prefixing runs IDs, note that it will affect the length requried for the ID column.
5. Load up index.php, ensure happiness
7. Edit the virtual host configuration for the site you'd like to profile to
Expand Down
2 changes: 2 additions & 0 deletions external/footer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
global $_xhprof;

if (!defined('XHPROF_LIB_ROOT')) {
define('XHPROF_LIB_ROOT', dirname(dirname(__FILE__)) . '/xhprof_lib');
}
Expand Down
4 changes: 3 additions & 1 deletion external/header.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
global $_xhprof;

if (PHP_SAPI == 'cli') {
$_SERVER['REMOTE_ADDR'] = null;
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
Expand Down Expand Up @@ -63,7 +65,7 @@ public static function __callstatic($name, $arguments)
}
unset($exceptionURLs);

//Certain urls should have their POST data omitted. Think login forms, other privlidged info
//Certain urls should have their POST data omitted. Think login forms, other privileged info
$_xhprof['savepost'] = true;
foreach ($exceptionPostURLs as $url)
{
Expand Down
23 changes: 13 additions & 10 deletions xhprof_html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
$vgbar = ' class="vgbar"';

$xhprof_runs_impl = new XHProfRuns_Default();
$xhprof_db = $xhprof_runs_impl->getDbInstance();

$domainFilter = getFilter('domain_filter');
$serverFilter = getFilter('server_filter');
Expand Down Expand Up @@ -80,7 +81,7 @@
$_xh_header = "";
if(isset($_GET['run1']) || isset($_GET['run']))
{
include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");
displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts,
$symbol, $sort, $run1, $run2);
}elseif (isset($_GET['geturl']))
Expand All @@ -94,9 +95,9 @@
list($header, $body) = showChart($rs, true);
$_xh_header .= $header;

include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");
$rs = $xhprof_runs_impl->getRuns($criteria);
include ("../xhprof_lib/templates/emptyBody.phtml");
include (XHPROF_LIB_ROOT . "/templates/emptyBody.phtml");

$url = htmlentities($_GET['geturl'], ENT_QUOTES, "UTF-8");
displayRuns($rs, "Runs with URL: $url");
Expand All @@ -111,15 +112,15 @@
$rs = $xhprof_runs_impl->getUrlStats($criteria);
list($header, $body) = showChart($rs, true);
$_xh_header .= $header;
include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");

$url = htmlentities($_GET['getcurl'], ENT_QUOTES, "UTF-8");
$rs = $xhprof_runs_impl->getRuns($criteria);
include("../xhprof_lib/templates/emptyBody.phtml");
include(XHPROF_LIB_ROOT . "/templates/emptyBody.phtml");
displayRuns($rs, "Runs with Simplified URL: $url");
}elseif (isset($_GET['getruns']))
{
include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");
$days = (int) $_GET['days'];

switch ($_GET['getruns'])
Expand All @@ -137,12 +138,14 @@

$criteria['order by'] = $load;
$criteria['limit'] = "500";
$criteria['where'] = "DATE_SUB(CURDATE(), INTERVAL $days DAY) <= `timestamp`";
// @TODO kludgy, should plug the database stuff leaking into here altogether
$criteria['where'] = $xhprof_db->dateSub($days) . " <= " . $xhprof_db->quote("timestamp");

$rs = $xhprof_runs_impl->getRuns($criteria);
displayRuns($rs, "Worst runs by $load");
}elseif(isset($_GET['hit']))
{
include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");
$last = (isset($_GET['hit'])) ? $_GET['hit'] : 25;
$last = (int) $last;
$days = (isset($_GET['days'])) ? $_GET['days'] : 1;
Expand Down Expand Up @@ -203,7 +206,7 @@
CODESE;
}else
{
include ("../xhprof_lib/templates/header.phtml");
include (XHPROF_LIB_ROOT . "/templates/header.phtml");
$last = (isset($_GET['last'])) ? $_GET['last'] : 25;
$last = (int) $last;
$criteria['order by'] = "timestamp";
Expand All @@ -212,4 +215,4 @@
displayRuns($rs, "Last $last Runs");
}

include ("../xhprof_lib/templates/footer.phtml");
include (XHPROF_LIB_ROOT . "/templates/footer.phtml");
26 changes: 8 additions & 18 deletions xhprof_lib/templates/diff_run_header_block.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,14 @@ print('<div id="view-diff-tables">');
print("<div id=\"clear\"></div>");

print('<div class="colone">');
// cookie diff data from array position 0
if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer']) == 'php') {
$cookieArr0 = unserialize($xhprof_runs_impl->run_details[0]['cookie']);
$cookieArr1 = unserialize($xhprof_runs_impl->run_details[1]['cookie']);
$getArr0 = unserialize($xhprof_runs_impl->run_details[0]['get']);
$getArr1 = unserialize($xhprof_runs_impl->run_details[1]['get']);
$postArr0 = unserialize($xhprof_runs_impl->run_details[0]['post']);
$postArr1 = unserialize($xhprof_runs_impl->run_details[1]['post']);
} else {
$cookieArr0 = json_decode($xhprof_runs_impl->run_details[0]['cookie'], true);
$cookieArr1 = json_decode($xhprof_runs_impl->run_details[1]['cookie'], true);
$getArr0 = json_decode($xhprof_runs_impl->run_details[0]['get'], true);
$getArr1 = json_decode($xhprof_runs_impl->run_details[1]['get'], true);
$postArr0 = json_decode($xhprof_runs_impl->run_details[0]['post'], true);
$postArr1 = json_decode($xhprof_runs_impl->run_details[1]['post'], true);
}


// cookie diff data from array position 0
$cookieArr0 = $xhprof_runs_impl->run_details[0]['cookie'];
$cookieArr1 = $xhprof_runs_impl->run_details[1]['cookie'];
$getArr0 = $xhprof_runs_impl->run_details[0]['get'];
$getArr1 = $xhprof_runs_impl->run_details[1]['get'];
$postArr0 = $xhprof_runs_impl->run_details[0]['post'];
$postArr1 = $xhprof_runs_impl->run_details[1]['post'];

print ('<div class="box-fix-small">');
print '<table class="box-tables-small">';
print "<thead>";
Expand Down
40 changes: 17 additions & 23 deletions xhprof_lib/templates/single_run_header_block.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
if ($display_calls) {
$format_total= number_format($totals['ct']);
}

if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
$cookieArr = unserialize($xhprof_runs_impl->run_details['cookie']);
$getArr = unserialize($xhprof_runs_impl->run_details['get']);
$postArr = unserialize($xhprof_runs_impl->run_details['post']);
} else {
$cookieArr = json_decode($xhprof_runs_impl->run_details['cookie'], true);
$getArr = json_decode($xhprof_runs_impl->run_details['get'], true);
$postArr = json_decode($xhprof_runs_impl->run_details['post'], true);
}

$cookieArr = $xhprof_runs_impl->run_details['cookie'];
$getArr = $xhprof_runs_impl->run_details['get'];
$postArr = $xhprof_runs_impl->run_details['post'];

//TODO This is lame
global $comparative;
Expand All @@ -38,21 +32,21 @@
<tr><th>Stat</th><th>Exact URL</th><th>Similar URLs</th></tr>
</thead>
<tbody>
<tr><td>Count</td><td><a href="?geturl=<?php echo urlencode($comparative['url']['url']);?>"><?php echo $comparative['url']['count(`id`)'];?></a></td><td><a href="?getcurl=<?php echo urlencode($comparative['c_url']['url']);?>"><?php echo $comparative['c_url']['count(`id`)'];?></a></td></tr>
<tr><td>Min Wall Time</td><td><?php echo printSeconds($comparative['url']['min(`wt`)']);?></td><td><?php echo printSeconds($comparative['c_url']['min(`wt`)']);?></td></tr>
<tr><td>Max Wall Time</td><td><?php echo printSeconds($comparative['url']['max(`wt`)']);?></td><td><?php echo printSeconds($comparative['c_url']['max(`wt`)']);?></td></tr>
<tr><td>Avg Wall Time</td><td><?php echo printSeconds($comparative['url']['avg(`wt`)']);?></td><td><?php echo printSeconds($comparative['c_url']['avg(`wt`)']);?></td></tr>
<tr><td>95% Wall Time</td><td><?php echo printSeconds($comparative['url']['95(`wt`)']);?></td><td><?php echo printSeconds($comparative['c_url']['95(`wt`)']);?></td></tr>
<tr><td>Count</td><td><a href="?geturl=<?php echo urlencode($comparative['url']['url']);?>"><?php echo $comparative['url']['count'];?></a></td><td><a href="?getcurl=<?php echo urlencode($comparative['c_url']['url']);?>"><?php echo $comparative['c_url']['count'];?></a></td></tr>
<tr><td>Min Wall Time</td><td><?php echo printSeconds($comparative['url']['wt_min']);?></td><td><?php echo printSeconds($comparative['c_url']['wt_min']);?></td></tr>
<tr><td>Max Wall Time</td><td><?php echo printSeconds($comparative['url']['wt_max']);?></td><td><?php echo printSeconds($comparative['c_url']['wt_max']);?></td></tr>
<tr><td>Avg Wall Time</td><td><?php echo printSeconds($comparative['url']['wt_avg']);?></td><td><?php echo printSeconds($comparative['c_url']['wt_avg']);?></td></tr>
<tr><td>95% Wall Time</td><td><?php echo printSeconds($comparative['url']['wt_95']);?></td><td><?php echo printSeconds($comparative['c_url']['wt_95']);?></td></tr>
<tr><td style="font-weight: bold;"><?php echo $arrayOfTotal[0]["label"]; ?></td><td style="font-weight: bold;"><?php echo $arrayOfTotal[0]["value"]; ?></td><td>&nbsp;</td></tr>
<tr><td>Min CPU Ticks</td><td><?php echo printSeconds($comparative['url']['min(`cpu`)']);?></td><td><?php echo printSeconds($comparative['c_url']['min(`cpu`)']);?></td></tr>
<tr><td>Max CPU Ticks</td><td><?php echo printSeconds($comparative['url']['max(`cpu`)']);?></td><td><?php echo printSeconds($comparative['c_url']['max(`cpu`)']);?></td></tr>
<tr><td>Avg CPU Ticks</td><td><?php echo printSeconds($comparative['url']['avg(`cpu`)']);?></td><td><?php echo printSeconds($comparative['c_url']['avg(`cpu`)']);?></td></tr>
<tr><td>95% CPU Ticks</td><td><?php echo printSeconds($comparative['url']['95(`cpu`)']);?></td><td><?php echo printSeconds($comparative['c_url']['95(`cpu`)']);?></td></tr>
<tr><td>Min CPU Ticks</td><td><?php echo printSeconds($comparative['url']['cpu_min']);?></td><td><?php echo printSeconds($comparative['c_url']['cpu_min']);?></td></tr>
<tr><td>Max CPU Ticks</td><td><?php echo printSeconds($comparative['url']['cpu_max']);?></td><td><?php echo printSeconds($comparative['c_url']['cpu_max']);?></td></tr>
<tr><td>Avg CPU Ticks</td><td><?php echo printSeconds($comparative['url']['cpu_avg']);?></td><td><?php echo printSeconds($comparative['c_url']['cpu_avg']);?></td></tr>
<tr><td>95% CPU Ticks</td><td><?php echo printSeconds($comparative['url']['cpu_95']);?></td><td><?php echo printSeconds($comparative['c_url']['cpu_95']);?></td></tr>
<tr><td style="font-weight: bold;"><?php echo $arrayOfTotal[1]["label"]; ?></td><td style="font-weight: bold;"><?php echo $arrayOfTotal[1]["value"]; ?></td><td>&nbsp;</td></tr>
<tr><td>Min Peak Memory Usage</td><td><?php echo number_format($comparative['url']['min(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['min(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>Max Peak Memory Usage</td><td><?php echo number_format($comparative['url']['max(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['max(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>Avg Peak Memory Usage</td><td><?php echo number_format($comparative['url']['avg(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['avg(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>95% Peak Memory Usage</td><td><?php echo number_format($comparative['url']['95(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['95(`pmu`)']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>Min Peak Memory Usage</td><td><?php echo number_format($comparative['url']['pmu_min']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['pmu_min']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>Max Peak Memory Usage</td><td><?php echo number_format($comparative['url']['pmu_max']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['pmu_max']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>Avg Peak Memory Usage</td><td><?php echo number_format($comparative['url']['pmu_avg']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['pmu_avg']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td>95% Peak Memory Usage</td><td><?php echo number_format($comparative['url']['pmu_95']) . " " . $arrayOfTotal[1]["metric"];?></td><td><?php echo number_format($comparative['c_url']['pmu_95']) . " " . $arrayOfTotal[1]["metric"];?></td></tr>
<tr><td style="font-weight: bold;"><?php echo $arrayOfTotal[2]["label"]; ?></td><td style="font-weight: bold;"><?php echo $arrayOfTotal[2]["value"]; ?></td><td>&nbsp;</td></tr>
<tr><td style="font-weight: bold;">Number of Function Calls:</td><td style="font-weight: bold;"><?php echo $format_total; ?></td><td>&nbsp;</td></tr>
<tr>
Expand Down
18 changes: 15 additions & 3 deletions xhprof_lib/utils/Db/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ public function __construct($config)
abstract public function connect();
abstract public function query($sql);
abstract public function escape($str);
abstract public function affectedRows();
abstract public function escapeBinary($data);
abstract public function unescapeBinary($data);
abstract public function affectedRows($resultSet);

public static function unixTimestamp($field)
public function quote($identifier)
{
throw new RuntimeException("Method '".get_called_class()."::".__FUNCTION__."' not implemented");
}

public static function dateSub($days)
public function unixTimestamp($field)
{
throw new RuntimeException("Method '".get_called_class()."::".__FUNCTION__."' not implemented");
}

public function fromUnixTimestamp($field)
{
throw new RuntimeException("Method '".get_called_class()."::".__FUNCTION__."' not implemented");
}

public function dateSub($days)
{
throw new RuntimeException("Method '".get_called_class()."::".__FUNCTION__."' not implemented");
}
Expand Down