function xhprof_init_metrics in XHProf 6
Same name and namespace in other branches
- 7 xhprof.inc \xhprof_init_metrics()
Initialize the metrics we'll display based on the information in the raw data.
@author Kannan
1 call to xhprof_init_metrics()
- xhprof_display_run in ./
xhprof.module - Display XHProf run report.
File
- ./
xhprof.inc, line 405
Code
function xhprof_init_metrics($xhprof_data, $rep_symbol, $sort, $diff_report = FALSE) {
global $stats;
global $pc_stats;
global $metrics;
global $diff_mode;
global $sort_col;
global $display_calls;
$diff_mode = $diff_report;
if (!empty($sort)) {
if (array_key_exists($sort, xhprof_sortable_columns())) {
$sort_col = $sort;
}
else {
print "Invalid Sort Key {$sort} specified in URL";
}
}
// For C++ profiler runs, walltime attribute isn't present.
// In that case, use "samples" as the default sort column.
if (!isset($xhprof_data["main()"]["wt"])) {
if ($sort_col == "wt") {
$sort_col = "samples";
}
// C++ profiler data doesn't have call counts.
// ideally we should check to see if "ct" metric
// is present for "main()". But currently "ct"
// metric is artificially set to 1. So, relying
// on absence of "wt" metric instead.
$display_calls = FALSE;
}
else {
$display_calls = TRUE;
}
// parent/child report doesn't support exclusive times yet.
// So, change sort hyperlinks to closest fit.
if (!empty($rep_symbol)) {
$sort_col = str_replace("excl_", "", $sort_col);
}
if ($display_calls) {
$stats = array(
"fn",
"ct",
"Calls%",
);
}
else {
$stats = array(
"fn",
);
}
$pc_stats = $stats;
$possible_metrics = xhprof_get_possible_metrics($xhprof_data);
foreach ($possible_metrics as $metric => $desc) {
if (isset($xhprof_data["main()"][$metric])) {
$metrics[] = $metric;
// flat (top-level reports): we can compute
// exclusive metrics reports as well.
$stats[] = $metric;
$stats[] = "I" . $desc[0] . "%";
$stats[] = "excl_" . $metric;
$stats[] = "E" . $desc[0] . "%";
// parent/child report for a function: we can
// only breakdown inclusive times correctly.
$pc_stats[] = $metric;
$pc_stats[] = "I" . $desc[0] . "%";
}
}
}