From: River Tarnell Date: Sun, 3 Jul 2005 02:22:09 +0000 (+0000) Subject: spiffy script to display profiling info on the interweb X-Git-Tag: 1.5.0beta2~70 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=9af3c09e5c233ae5b0b466327759aba7852a187c;p=lhc%2Fweb%2Fwiklou.git spiffy script to display profiling info on the interweb --- diff --git a/AdminSettings.sample b/AdminSettings.sample index c121fc7bd0..0eea90cc2d 100644 --- a/AdminSettings.sample +++ b/AdminSettings.sample @@ -23,4 +23,9 @@ $wgDBadminuser = 'wikiadmin'; $wgDBadminpassword = 'adminpass'; +/* + * Whether to enable the profileinfo.php script. + */ +$wgEnableProfileInfo = false; + ?> diff --git a/profileinfo.php b/profileinfo.php new file mode 100644 index 0000000000..36ef14dbb8 --- /dev/null +++ b/profileinfo.php @@ -0,0 +1,233 @@ + + + +Profiling data + + + +name = $name; + $this->count = $count; + $this->time = $time; + $this->children = array(); + } + + function add_child($child) { + $this->children[] = $child; + } + + function display($indent = 0.0) { + global $expand; + usort($this->children, "compare_point"); + + $extet = ''; + if (isset($expand[$this->name()])) + $ex = true; + else $ex = false; + if (!$ex) { + if (count($this->children)) { + $url = makeurl(false, false, $expand + array($this->name() => true)); + $extet = " [+]"; + } else $extet = ''; + } else { + $e = array(); + foreach ($expand as $name => $ep) + if ($name != $this->name()) + $e += array($name => $ep); + + $extet = " [–]"; + } + ?> + + fmttime() ?> + count() ?> + + name()) . $extet ?> + + + children as $child) + $child->display($indent + 2); + } + + function name() { + return $this->name; + } + + function count() { + return $this->count; + } + + function time() { + return $this->time; + } + + function fmttime() { + return sprintf("%5.02f", $this->time); + } +}; + +function compare_point($a, $b) { + global $sort; + switch ($sort) { + case "name": + return strcmp($a->name(), $b->name()); + case "time": + return $a->time() > $b->time() ? -1 : 1; + case "count": + return $a->count() > $b->count() ? -1 : 1; + } +} + +$sorts = array("time", "count", "name"); +$sort = 'time'; +if (isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sorts)) + $sort = $_REQUEST['sort']; + +$dbh = mysql_connect($wgDBserver, $wgDBadminuser, $wgDBadminpassword) + or die("mysql server failed: " . mysql_error()); +mysql_select_db($wgDBname, $dbh) or die(mysql_error($dbh)); +$res = mysql_query(" + SELECT pf_count, pf_time, pf_name + FROM profiling + ORDER BY pf_name ASC +", $dbh) or die("query failed: " . mysql_error()); + +if (isset($_REQUEST['filter'])) + $filter = $_REQUEST['filter']; +else $filter = ''; + +?> +
+

+ + +"/> + +

+
+ + + + + + + +pf_name, $o->pf_count, $o->pf_time); + $totaltime += $next->time(); + if ($last !== false) { + if (preg_match("/^".preg_quote($last->name(), "/")."/", $next->name())) { + $last->add_child($next); + continue; + } + } + $last = $next; + $points[] = $next; +} + +usort($points, "compare_point"); + +foreach ($points as $point) { + if (strlen($filter) && !strstr($point->name(), $filter)) + continue; + + $point->display(); +} +?> +
">Time">Count">Name
+ +

Total time:

+ + +