<?php
// Copyright (c) 2009 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// XHProf: A Hierarchical Profiler for PHP
//
// XHProf has two components:
//
// * This module is the UI/reporting component, used
// for viewing results of XHProf runs from a browser.
//
// * Data collection component: This is implemented
// as a PHP extension (XHProf).
//
// @author Kannan Muthukkaruppan
//
if (!isset($GLOBALS['XHPROF_LIB_ROOT'])) {
// by default, the parent directory is XHPROF lib root
$GLOBALS['XHPROF_LIB_ROOT'] = realpath(dirname(__FILE__) . '/..');
}
require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/xhprof_lib.php';
require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/callgraph_utils.php';
require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/xhprof_runs.php';
/**
* Our coding convention disallows relative paths in hrefs.
* Get the base URL path from the SCRIPT_NAME.
*/
$base_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
/**
* Generate references to required stylesheets & javascript.
*
* If the calling script (such as index.php) resides in
* a different location that than 'xhprof_html' directory the
* caller must provide the URL path to 'xhprof_html' directory
* so that the correct location of the style sheets/javascript
* can be specified in the generated HTML.
*
*/
function xhprof_include_js_css($ui_dir_url_path = null) {
if (empty($ui_dir_url_path)) {
$ui_dir_url_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
}
// style sheets
echo "<link href='$ui_dir_url_path/css/xhprof.css' rel='stylesheet' ".
" type='text/css' />";
echo "<link href='$ui_dir_url_path/jquery/jquery.tooltip.css' ".
" rel='stylesheet' type='text/css' />";
echo "<link href='$ui_dir_url_path/jquery/jquery.autocomplete.css' ".
" rel='stylesheet' type='text/css' />";
// javascript
echo "<script src='$ui_dir_url_path/jquery/jquery-1.2.6.js'>".
"</script>";
echo "<script src='$ui_dir_url_path/jquery/jquery.tooltip.js'>".
"</script>";
echo "<script src='$ui_dir_url_path/jquery/jquery.autocomplete.js'>"
."</script>";
echo "<script src='$ui_dir_url_path/js/xhprof_report.js'></script>";
}
/*
* Formats call counts for XHProf reports.
*
* Description:
* Call counts in single-run reports are integer values.
* However, call counts for aggregated reports can be
* fractional. This function will print integer values
* without decimal point, but with commas etc.
*
* 4000 ==> 4,000
*
* It'll round fractional values to decimal precision of 3
* 4000.1212 ==> 4,000.121
* 4000.0001 ==> 4,000
*
*/
function xhprof_count_format($num) {
$num = round($num, 3);
if (round($num) == $num) {
return number_format($num);
} else {
return number_format($num, 3);
}
}
function xhprof_percent_format($s, $precision = 1) {
return sprintf('%.'.$precision.'f%%', 100 * $s);
}
/**
* Implodes the text for a bunch of actions (such as links, forms,
* into a HTML list and returns the text.
*/
function xhprof_render_actions($actions) {
$out = array();
if (count($actions)) {
$out[] = '<ul class="xhprof_actions">';
foreach ($actions as $action) {
$out[] = '<li>'.$action.'</li>';
}
$out[] = '</ul>';
}
return implode('', $out);
}
/**
* @param html-str $content the text/image/innerhtml/whatever for the link
* @param raw-str $href
* @param raw-str $class
* @param raw-str $id
* @param raw-str $title
* @param raw-str $target
* @param raw-str $onclick
* @param raw-str $style
* @param raw-str $access
* @param raw-str $onmouseover
* @param raw-str $onmouseout
* @param raw-str $onmousedown
* @param raw-str $dir
* @param raw-str $rel
*/
function xhprof_render_link($content, $href, $class='', $id='', $title='',
$target='',
$onclick='', $style='', $access='', $onmouseover='',
$onmouseout='', $onmousedown='') {
if (!$content) {
return '';
}
if ($href) {
$link = '<a href="' . ($href) . '"';
} else {
$link = '<span';
}
if ($class) {
$link .= ' class="' . ($class) . '"';
}
if ($id) {
$link .= ' id="' . ($id) . '"';
}
if ($title) {
$link .= ' title="' . ($title) . '"';
}
if ($target) {
$link .= ' target="' . ($target) . '"';
}
if ($onclick && $href) {
$link .= ' onclick="' . ($onclick) . '"';
}
if ($style && $href) {
$link .= ' style="' . ($style) . '"';
}
if ($access && $href) {
$link .= ' accesskey="' . ($access) . '"';
}
if ($onmouseover) {
$link .= ' onmouseover="' . ($onmouseover) . '"';
}
if ($onmouseout) {
$link .= ' onmouseout="' . ($onmouseout) . '"';
}
if ($onmousedown) {
$link .= ' onmousedown="' . ($onmousedown) . '"';
}
$link .= '>';
$link .= $content;
if ($href) {
$link .= '</a>';
} else {
$link .= '</span>';
}
return $link;
}
// default column to sort on -- wall time
$sort_col = "wt";
// default is "single run" report
$diff_mode = false;
// call count data present?
$display_calls = true;
// The following column headers are sortable
$sortable_columns = array("fn" => 1,
"ct" => 1,
"wt" => 1,
"excl_wt" => 1,
"ut" => 1,
"excl_ut" => 1,
"st" => 1,
"excl_st" => 1,
"mu" => 1,
"excl_mu" => 1,
"pmu" => 1,
"excl_pmu" => 1,
"cpu" => 1,
"excl_cpu" => 1,
"samples" => 1,
"excl_samples" => 1
);
// Textual descriptions for column headers in "single run" mode
$descriptions = array(
"fn" => "Function Name",
"ct" => "Calls",
"Calls%" => "Calls%",
"wt" => "Incl. Wall Time<br>(microsec)",
"IWall%" => "IWall%",
"excl_wt" => "Excl. Wall Time<br>(microsec)",
"EWall%" => "EWall%",
"ut" => "Incl. User<br>(microsecs)",
"IUser%" => "IUser%",
"excl_ut" => "Excl. User<br>(microsec)",
"EUser%" => "EUser%",
"st" => "Incl. Sys <br>(microsec)",
"ISys%" => "ISys%",
"excl_st" => "Excl. Sys <br>(microsec)",
"ESys%" => "ESys%",
"cpu" => "Incl. CPU<br>(microsecs)",
"ICpu%" => "ICpu%",
"excl_cpu" => "Excl. CPU<br>(microsec)",
"ECpu%" => "ECPU%",
"mu" => "Incl.<br>MemUse<br>(bytes)",
"IMUse%" => "IMemUse%",
"excl_mu" => "Excl.<br>MemUse<br>(bytes)",
"EMUse%" => "EMemUse%",
"pmu" => "Incl.<br> PeakMemUse<br>(bytes)",
"IPMUse%" => "IPeakMemUse%",
"excl_pmu" => "Excl.<br>PeakMemUse<br>(bytes)",
"EPMUse%" => "EPeakMemUse%",
"samples" => "Incl. Samples",
"ISamples%" => "ISamples%",
评论1
最新资源