Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-24600 profiling - add xhprof integration

  • Loading branch information...
commit 6af80cae0187d02f777ce1a3ba18a03e2cd1a941 1 parent 88e5c58
@stronk7 stronk7 authored
Showing with 9,587 additions and 7 deletions.
  1. +186 −0 admin/report/profiling/index.php
  2. +45 −0 admin/report/profiling/lang/en/report_profiling.php
  3. +8 −0 admin/report/profiling/settings.php
  4. +25 −0 admin/report/profiling/styles.css
  5. +38 −0 admin/settings/development.php
  6. +1 −0  admin/settings/server.php
  7. +20 −0 lang/en/admin.php
  8. +27 −4 lib/db/install.xml
  9. +35 −0 lib/db/upgrade.php
  10. +9 −1 lib/outputrenderers.php
  11. +7 −1 lib/setup.php
  12. +7 −0 lib/thirdpartylibs.xml
  13. +63 −0 lib/xhprof/CHANGELOG
  14. +12 −0 lib/xhprof/CREDITS
  15. +177 −0 lib/xhprof/LICENSE
  16. +7 −0 lib/xhprof/README
  17. 0  lib/xhprof/index.html
  18. +41 −0 lib/xhprof/readme_moodle.txt
  19. +102 −0 lib/xhprof/xhprof_html/callgraph.php
  20. +90 −0 lib/xhprof/xhprof_html/css/xhprof.css
  21. +100 −0 lib/xhprof/xhprof_html/index.php
  22. BIN  lib/xhprof/xhprof_html/jquery/indicator.gif
  23. +3,549 −0 lib/xhprof/xhprof_html/jquery/jquery-1.2.6.js
  24. +61 −0 lib/xhprof/xhprof_html/jquery/jquery.autocomplete.css
  25. +759 −0 lib/xhprof/xhprof_html/jquery/jquery.autocomplete.js
  26. +24 −0 lib/xhprof/xhprof_html/jquery/jquery.tooltip.css
  27. +294 −0 lib/xhprof/xhprof_html/jquery/jquery.tooltip.js
  28. +204 −0 lib/xhprof/xhprof_html/js/xhprof_report.js
  29. +43 −0 lib/xhprof/xhprof_html/typeahead.php
  30. +80 −0 lib/xhprof/xhprof_lib/display/typeahead_common.php
  31. +1,439 −0 lib/xhprof/xhprof_lib/display/xhprof.php
  32. +486 −0 lib/xhprof/xhprof_lib/utils/callgraph_utils.php
  33. +942 −0 lib/xhprof/xhprof_lib/utils/xhprof_lib.php
  34. +163 −0 lib/xhprof/xhprof_lib/utils/xhprof_runs.php
  35. +542 −0 lib/xhprof/xhprof_moodle.php
  36. +1 −1  version.php
View
186 admin/report/profiling/index.php
@@ -0,0 +1,186 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package core
+ * @subpackage profiling
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+// TODO: Move all the DB stuff to profiling_db_xxxx() function in xhprof_moodle.php
+
+require_once(dirname(__FILE__).'/../../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
+
+define('PROFILING_RUNSPERPAGE', 50);
+
+// page parameters
+$script = optional_param('script', null, PARAM_PATH);
+$runid = optional_param('runid', null, PARAM_ALPHANUM);
+$runid2 = optional_param('runid2', null, PARAM_ALPHANUM);
+$listurl = optional_param('listurl', null, PARAM_PATH);
+$runreference= optional_param('runreference', 0, PARAM_INT);
+$runcomment = optional_param('runcomment', null, PARAM_TEXT);
+
+$dbfields = 'runid, url, totalexecutiontime, totalcputime, ' .
+ 'totalcalls, totalmemory, runreference, runcomment, timecreated';
+
+admin_externalpage_setup('reportprofiling');
+
+// Always add listurl if available
+if ($listurl) {
+ $listurlnav = new moodle_url('/admin/report/profiling/index.php', array('listurl' => $listurl));
+ $PAGE->navbar->add($listurl, $listurlnav);
+}
+
+// Header
+echo $OUTPUT->header();
+
+// We have requested the last available run for one script
+if (isset($script)) {
+ // Get the last available run for the given script
+ $run = $DB->get_record_sql("SELECT $dbfields
+ FROM {profiling}
+ WHERE url = ?
+ AND id = (SELECT MAX(id)
+ FROM {profiling}
+ WHERE url = ?)",
+ array($script, $script), IGNORE_MISSING);
+
+ // No run found for script, warn and exit
+ if (!$run) {
+ notice(get_string('cannotfindanyrunforurl', 'report_profiling', $script), 'index.php');
+ }
+
+ // Check if there is any previous run marked as reference one
+ $prevreferences = $DB->get_records_select('profiling',
+ 'url = ? AND runreference = 1 AND timecreated < ?',
+ array($run->url, $run->timecreated),
+ 'timecreated DESC', 'runid', 0, 1);
+ $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
+ echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
+ $header = get_string('lastrunof', 'report_profiling', $script);
+ echo $OUTPUT->heading($header);
+ $table = profiling_print_run($run, $prevrunid);
+ echo $table;
+ echo $OUTPUT->box_end();
+
+
+// We have requested the diff between 2 runs
+} else if (isset($runid) && isset($runid2)) {
+ $run1 = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, MUST_EXIST);
+ $run2 = $DB->get_record('profiling', array('runid'=>$runid2), $dbfields, MUST_EXIST);
+ if ($run1->url == $run2->url && $run1->runid != $run2->runid) {
+ if ($run2->timecreated < $run1->timecreated) {
+ $runtemp = $run1;
+ $run1 = $run2;
+ $run2 = $runtemp;
+ }
+ echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
+ $header = get_string('differencesbetween2runsof', 'report_profiling', $run1->url);
+ echo $OUTPUT->heading($header);
+ $table = profiling_print_rundiff($run1, $run2);
+ echo $table;
+ echo $OUTPUT->box_end();
+ }
+
+
+// We have requested one run, invoke it
+} else if (isset($runid)) {
+ // Check if we are trying to update the runreference/runcomment for the run
+ if (isset($runcomment) && confirm_sesskey()) {
+ $id = $DB->get_field('profiling', 'id', array('runid' => $runid), MUST_EXIST);
+ $rec = new stdClass();
+ $rec->id = $id;
+ $rec->runreference = (bool)$runreference;
+ $rec->runcomment = $runcomment;
+ $DB->update_record('profiling', $rec);
+ }
+ // Get the requested runid
+ $run = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, IGNORE_MISSING);
+
+ // No run found for runid, warn and exit
+ if (!$run) {
+ notice(get_string('cannotfindanyrunforrunid', 'report_profiling', $runid), 'index.php');
+ }
+
+ // Check if there is any previous run marked as reference one
+ $prevreferences = $DB->get_records_select('profiling',
+ 'url = ? AND runreference = 1 AND timecreated < ?',
+ array($run->url, $run->timecreated),
+ 'timecreated DESC', 'runid', 0, 1);
+ $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
+ echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
+ $header = get_string('summaryof', 'report_profiling', $run->url);
+ echo $OUTPUT->heading($header);
+ $table = profiling_print_run($run, $prevrunid);
+ echo $table;
+ echo $OUTPUT->box_end();
+
+
+// Default: List one page of runs
+} else {
+
+ // The flexitable that will root listings
+ $table = new xhprof_table_sql('profiling-list-table');
+ $baseurl = $CFG->wwwroot . '/admin/report/profiling/index.php';
+
+ // Check if we are listing all or some URL ones
+ $sqlconditions = '';
+ $sqlparams = array();
+ if (!isset($listurl)) {
+ $header = get_string('pluginname', 'report_profiling');
+ $sqlconditions = '1 = 1';
+ $table->set_listurlmode(false);
+ } else {
+ $header = get_string('profilingrunsfor', 'report_profiling', $listurl);
+ $sqlconditions = 'url = :url';
+ $sqlparams['url'] = $listurl;
+ $table->set_listurlmode(true);
+ $baseurl .= '?listurl=' . urlencode($listurl);
+ }
+
+ echo $OUTPUT->heading($header);
+
+ // TODO: Fix flexitable to validate tsort/thide/tshow/tifirs/tilast/page
+ // TODO: Fix table_sql to allow it to work without WHERE clause
+ // add silly condition (1 = 1) because of table_sql bug
+ $table->set_sql($dbfields, '{profiling}', $sqlconditions, $sqlparams);
+ $table->set_count_sql("SELECT COUNT(*) FROM {profiling} WHERE $sqlconditions", $sqlparams);
+ $columns = array(
+ 'url', 'timecreated', 'totalexecutiontime', 'totalcputime',
+ 'totalcalls', 'totalmemory', 'runcomment');
+ $headers = array(
+ get_string('url'), get_string('date'), get_string('executiontime', 'report_profiling'),
+ get_string('cputime', 'report_profiling'), get_string('calls', 'report_profiling'),
+ get_string('memory', 'report_profiling'), get_string('comment', 'report_profiling'));
+ $table->define_columns($columns);
+ $table->define_headers($headers);
+ $table->sortable(true, 'timecreated', SORT_DESC);
+ $table->define_baseurl($baseurl);
+ $table->column_suppress('url');
+ $table->out(PROFILING_RUNSPERPAGE, true);
+
+ // Print the controller block with different options
+ echo profiling_list_controls($listurl);
+}
+
+// Footer.
+echo $OUTPUT->footer();
+
View
45 admin/report/profiling/lang/en/report_profiling.php
@@ -0,0 +1,45 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Strings for component 'report_profiling', language 'en', branch 'MOODLE_20_STABLE'
+ *
+ * @package report_profiling
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['calls'] = 'Function calls';
+$string['cannotfindanyrunforurl'] = 'Sorry, cannot find any profiling run for the \'{$a}\' URL';
+$string['cannotfindanyrunforrunid'] = 'Sorry, cannot find the \'{$a}\' profiling run';
+$string['comment'] = 'Comment';
+$string['differencesbetween2runsof'] = 'Differences between 2 runs of {$a}';
+$string['executiontime'] = 'Execution time';
+$string['cputime'] = 'CPU time';
+$string['lastrunof'] = 'Summary of last run of {$a}';
+$string['markreferencerun'] = 'Mark as reference run/comment';
+$string['memory'] = 'Memory used';
+$string['pluginname'] = 'Profiling runs';
+$string['profilingfocusscript'] = 'Focus on profiling runs for the script: {$a}';
+$string['profilingruns'] = 'Profiling runs';
+$string['profilingrunsfor'] = 'Profiling runs for {$a}';
+$string['referencerun'] = 'Reference run/comment';
+$string['runid'] = 'Run ID';
+$string['summaryof'] = 'Summary of {$a}';
+$string['viewdetails'] = 'View profiling details';
+$string['viewdiff'] = 'View profiling differences with last reference run';
+$string['viewdiffdetails'] = 'View profiling diff details';
View
8 admin/report/profiling/settings.php
@@ -0,0 +1,8 @@
+<?php
+
+defined('MOODLE_INTERNAL') || die;
+
+// profiling report, added to development
+if (extension_loaded('xhprof') && function_exists('xhprof_enable') && !empty($CFG->profilingenabled)) {
+ $ADMIN->add('development', new admin_externalpage('reportprofiling', get_string('pluginname', 'report_profiling'), "$CFG->wwwroot/$CFG->admin/report/profiling/index.php", 'moodle/site:config'));
+}
View
25 admin/report/profiling/styles.css
@@ -0,0 +1,25 @@
+/* report_profiling styles */
+
+.path-admin-report-profiling .profilingruntable .label {
+ font-weight: bold;
+}
+.path-admin-report-profiling .profiling_worse {
+ color: red;
+}
+.path-admin-report-profiling .profiling_better {
+ color: green;
+}
+.path-admin-report-profiling .profiling_same {
+ color: dimgrey;
+}
+.path-admin-report-profiling .profiling_important,
+.path-admin-report-profiling .flexible .referencerun {
+ font-weight: bold;
+}
+.path-admin-report-profiling .flexible .r1 .cell {
+ background-color: whitesmoke;
+}
+.path-admin-report-profiling .flexible {
+ margin-left:auto;
+ margin-right:auto
+}
View
38 admin/settings/development.php
@@ -35,6 +35,44 @@
$temp->add(new admin_setting_configcheckbox('debugpageinfo', get_string('debugpageinfo', 'admin'), get_string('configdebugpageinfo', 'admin'), 0));
$ADMIN->add('development', $temp);
+ // "profiling" settingpage (conditionally if the 'xhprof' extension is available only)
+ if (extension_loaded('xhprof') && function_exists('xhprof_enable')) {
+ $temp = new admin_settingpage('profiling', get_string('profiling', 'admin'));
+ // Main profiling switch
+ $temp->add(new admin_setting_configcheckbox('profilingenabled', get_string('profilingenabled', 'admin'), get_string('profilingenabled_help', 'admin'), false));
+ // List of URLs that will be automatically profiled
+ $temp->add(new admin_setting_configtextarea('profilingincluded', get_string('profilingincluded', 'admin'), get_string('profilingincluded_help', 'admin'), ''));
+ // List of URLs that won't be profiled ever
+ $temp->add(new admin_setting_configtextarea('profilingexcluded', get_string('profilingexcluded', 'admin'), get_string('profilingexcluded_help', 'admin'), ''));
+ // Allow random profiling each XX requests
+ $temp->add(new admin_setting_configtext('profilingautofrec', get_string('profilingautofrec', 'admin'), get_string('profilingautofrec_help', 'admin'), 0, PARAM_INT));
+ // Allow PROFILEME/DONTPROFILEME GPC
+ $temp->add(new admin_setting_configcheckbox('profilingallowme', get_string('profilingallowme', 'admin'), get_string('profilingallowme_help', 'admin'), false));
+ // Allow PROFILEALL/PROFILEALLSTOP GPC
+ $temp->add(new admin_setting_configcheckbox('profilingallowall', get_string('profilingallowall', 'admin'), get_string('profilingallowall_help', 'admin'), false));
+ // TODO: Allow to skip PHP functions (XHPROF_FLAGS_NO_BUILTINS)
+ // TODO: Allow to skip call_user functions (ignored_functions array)
+ // Specify the life time (in minutes) of profiling runs
+ $temp->add(new admin_setting_configselect('profilinglifetime', get_string('profilinglifetime', 'admin'), get_string('profilinglifetime_help', 'admin'), 24*60, array(
+ 0 => get_string('neverdeleteruns', 'admin'),
+ 30*24*60 => get_string('numdays', '', 30),
+ 15*24*60 => get_string('numdays', '', 15),
+ 7*24*60 => get_string('numdays', '', 7),
+ 4*24*60 => get_string('numdays', '', 4),
+ 2*24*60 => get_string('numdays', '', 2),
+ 24*60 => get_string('numhours', '', 24),
+ 16*80 => get_string('numhours', '', 16),
+ 8*60 => get_string('numhours', '', 8),
+ 4*60 => get_string('numhours', '', 4),
+ 2*60 => get_string('numhours', '', 2),
+ 60 => get_string('numminutes', '', 60),
+ 30 => get_string('numminutes', '', 30),
+ 15 => get_string('numminutes', '', 15))));
+
+ // Add the 'profiling' page to admin block
+ $ADMIN->add('development', $temp);
+ }
+
// XMLDB editor
$ADMIN->add('development', new admin_externalpage('xmldbeditor', get_string('xmldbeditor'), "$CFG->wwwroot/$CFG->admin/xmldb/"));
View
1  admin/settings/server.php
@@ -12,6 +12,7 @@
'2' => get_string('gd2'))));
$temp->add(new admin_setting_configexecutable('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), ''));
$temp->add(new admin_setting_configexecutable('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), ''));
+$temp->add(new admin_setting_configexecutable('pathtodot', get_string('pathtodot', 'admin'), get_string('pathtodot_help', 'admin'), ''));
$ADMIN->add('server', $temp);
View
20 lang/en/admin.php
@@ -735,6 +735,7 @@
$string['navcourselimit'] = 'Course limit';
$string['navshowallcourses'] = 'Show all courses';
$string['navshowcategories'] = 'Show course categories';
+$string['neverdeleteruns'] = 'Never delete runs';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
$string['nodatabase'] = 'No database';
$string['nodefaultuserrolelists'] = 'Don\'t return all default role users';
@@ -766,6 +767,8 @@
$string['pathdvips'] = 'Path of <i>dvips</i> binary';
$string['pathlatex'] = 'Path of <i>latex</i> binary';
$string['pathtoclam'] = 'clam AV path';
+$string['pathtodot'] = 'Path to dot';
+$string['pathtodot_help'] = 'Path to dot. Probably something like /usr/bin/dot. To be able to generate graphics from DOT files, you must have installed the dot executable and point to it here. Note that, for now, this only used by the profiling features (Development->Profiling) built into Moodle.';
$string['pathtodu'] = 'Path to du';
$string['pathtopgdump'] = 'Path to pg_dump';
$string['pathtopgdumpdesc'] = 'This is only necessary to enter if you have more than one pg_dump on your system (for example if you have more than one version of postgresql installed)';
@@ -801,6 +804,8 @@
$string['profiledeletecategory'] = 'Deleting a category';
$string['profiledeletefield'] = 'Deleting a field';
$string['profiledescription'] = 'Description of the field';
+$string['profiledscript'] = 'This script has been profiled';
+$string['profiledscriptview'] = 'View profiling information for this script';
$string['profileeditcategory'] = 'Editing category: {$a}';
$string['profileeditfield'] = 'Editing profile field: {$a}';
$string['profilefield'] = 'Profile field';
@@ -836,6 +841,21 @@
$string['profilevisibleall'] = 'Visible to everyone';
$string['profilevisiblenone'] = 'Not visible';
$string['profilevisibleprivate'] = 'Visible to user';
+$string['profiling'] = 'Profiling';
+$string['profilingallowall'] = 'Continuous profiling';
+$string['profilingallowall_help'] = 'If you enable this setting, then, at any moment, you can use the PROFILEALL parameter anywhere (PGC) to enable profiling for all the executed scripts along the Moodle session life. Analogously, you can use the PROFILEALLSTOP parameter to stop it.';
+$string['profilingallowme'] = 'Selective profiling';
+$string['profilingallowme_help'] = 'If you enable this setting, then, selectively, you can use the PROFILEME parameter anywhere (PGC) and profiling for that script will happen. Analogously, you can use the DONTPROFILEME parameter to prevent profiling to happen';
+$string['profilingautofrec'] = 'Automatic profiling';
+$string['profilingautofrec_help'] = 'By configuring this setting, some request (randomly, based on the frecuency specified - 1 of XXX) will be picked and automatically profiled, storing results for further analysis. Note that this way of profiling observes the include/exclude settings. Set it to 0 to disable automatic profiling.';
+$string['profilingenabled'] = 'Enable profiling';
+$string['profilingenabled_help'] = 'If you enable this setting, then profiling will be available in this site and you will be able to define its behavior by configuring the next options.';
+$string['profilingexcluded'] = 'Exclude profiling';
+$string['profilingexcluded_help'] = 'List of (comma separated, absolute skipping wwwroot, callable) URLs that will be excluded from being profiled from the ones defined by \'Profile these\' setting.';
+$string['profilingincluded'] = 'Profile these';
+$string['profilingincluded_help'] = 'List of (comma separated, absolute skipping wwwroot, callable) URLs that will be automatically profiled. Examples: /index.php, /course/view.php. Also accepts the * wildchar at any position. Examples: /mod/forum/*, /mod/*/view.php.';
+$string['profilinglifetime'] = 'Keep profiling runs';
+$string['profilinglifetime_help'] = 'Specify the time you want to keep information about old profiling runs. Older ones will be pruned periodically. Note that this excludes any profiling run marked as \'reference run\'.';
$string['protectusernames'] = 'Protect usernames';
$string['proxybypass'] = 'Proxy bypass hosts';
$string['proxyhost'] = 'Proxy host';
View
31 lib/db/install.xml 100644 → 100755
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20101026" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20101121" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -2688,7 +2688,7 @@
<INDEX NAME="backupid_contextid_component_filearea_itemid_ix" UNIQUE="false" FIELDS="backupid, contextid, component, filearea, itemid"/>
</INDEXES>
</TABLE>
- <TABLE NAME="backup_logs" COMMENT="To store all the logs from backup and restore operations (by db logger)" PREVIOUS="backup_files_template" NEXT="course_published">
+ <TABLE NAME="backup_logs" COMMENT="To store all the logs from backup and restore operations (by db logger)" PREVIOUS="backup_files_template" NEXT="profiling">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="backupid"/>
<FIELD NAME="backupid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="backupid the log record belongs to" PREVIOUS="id" NEXT="loglevel"/>
@@ -2704,7 +2704,30 @@
<INDEX NAME="backupid-id" UNIQUE="true" FIELDS="backupid, id" COMMENT="for quick ordered retrieval by backupid"/>
</INDEXES>
</TABLE>
- <TABLE NAME="course_published" COMMENT="Information about how and when an local courses were published to hubs" PREVIOUS="backup_logs">
+ <TABLE NAME="profiling" COMMENT="Stores the results of all the profiling runs" PREVIOUS="backup_logs" NEXT="course_published">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="runid"/>
+ <FIELD NAME="runid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="the unique id for this run (as generated by xhprof)" PREVIOUS="id" NEXT="url"/>
+ <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="the url this profiling record is about (without wwwroot nor query params)" PREVIOUS="runid" NEXT="data"/>
+ <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="the raw data gathered by xhprof" PREVIOUS="url" NEXT="totalexecutiontime"/>
+ <FIELD NAME="totalexecutiontime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="time (in microseconds) spent by the run" PREVIOUS="data" NEXT="totalcputime"/>
+ <FIELD NAME="totalcputime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="time (in microseconds) spent by the CPU in this run" PREVIOUS="totalexecutiontime" NEXT="totalcalls"/>
+ <FIELD NAME="totalcalls" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Total number of calls performed by the run" PREVIOUS="totalcputime" NEXT="totalmemory"/>
+ <FIELD NAME="totalmemory" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Total memory used byt the run" PREVIOUS="totalcalls" NEXT="runreference"/>
+ <FIELD NAME="runreference" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Is this run a reference one" PREVIOUS="totalmemory" NEXT="runcomment"/>
+ <FIELD NAME="runcomment" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Brief comment for this run" PREVIOUS="runreference" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="unix timestap of the creation of this run" PREVIOUS="runcomment"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="runid_uk"/>
+ <KEY NAME="runid_uk" TYPE="unique" FIELDS="runid" PREVIOUS="primary"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="url_runreference_ix" UNIQUE="false" FIELDS="url, runreference" NEXT="timecreated_runreference_ix"/>
+ <INDEX NAME="timecreated_runreference_ix" UNIQUE="false" FIELDS="timecreated, runreference" PREVIOUS="url_runreference_ix"/>
+ </INDEXES>
+ </TABLE>
+ <TABLE NAME="course_published" COMMENT="Information about how and when an local courses were published to hubs" PREVIOUS="profiling">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="huburl"/>
<FIELD NAME="huburl" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="the url of the &quot;registered on&quot; hub" PREVIOUS="id" NEXT="courseid"/>
@@ -2720,4 +2743,4 @@
</KEYS>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
35 lib/db/upgrade.php
@@ -5477,6 +5477,41 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2010111702);
}
+ if ($oldversion < 2010121401) {
+
+ // Define table profiling to be created
+ $table = new xmldb_table('profiling');
+
+ // Adding fields to table profiling
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('runid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('totalexecutiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+ $table->add_field('totalcputime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+ $table->add_field('totalcalls', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+ $table->add_field('totalmemory', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+ $table->add_field('runreference', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('runcomment', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
+
+ // Adding keys to table profiling
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+ $table->add_key('runid_uk', XMLDB_KEY_UNIQUE, array('runid'));
+
+ // Adding indexes to table profiling
+ $table->add_index('url_runreference_ix', XMLDB_INDEX_NOTUNIQUE, array('url', 'runreference'));
+ $table->add_index('timecreated_runreference_ix', XMLDB_INDEX_NOTUNIQUE, array('timecreated', 'runreference'));
+
+ // Conditionally launch create table for profiling
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2010121401);
+ }
+
return true;
}
View
10 lib/outputrenderers.php
@@ -353,7 +353,7 @@ public function standard_top_of_body_html() {
* @return string HTML fragment.
*/
public function standard_footer_html() {
- global $CFG;
+ global $CFG, $SCRIPT;
// This function is normally called from a layout.php file in {@link header()}
// but some of the content won't be known until later, so we return a placeholder
@@ -367,6 +367,14 @@ public function standard_footer_html() {
$output .= '<div class="performanceinfo pageinfo">This page is: ' . $this->page->debug_summary() . '</div>';
}
if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { // Only in developer mode
+ // Add link to profiling report if necessary
+ if (function_exists('profiling_is_running') && profiling_is_running()) {
+ $txt = get_string('profiledscript', 'admin');
+ $title = get_string('profiledscriptview', 'admin');
+ $url = $CFG->wwwroot . '/admin/report/profiling/index.php?script=' . urlencode($SCRIPT);
+ $link= '<a title="' . $title . '" href="' . $url . '">' . $txt . '</a>';
+ $output .= '<div class="profilingfooter">' . $link . '</div>';
+ }
$output .= '<div class="purgecaches"><a href="'.$CFG->wwwroot.'/admin/purgecaches.php?confirm=1&amp;sesskey='.sesskey().'">'.get_string('purgecaches', 'admin').'</a></div>';
}
if (!empty($CFG->debugvalidators)) {
View
8 lib/setup.php
@@ -646,7 +646,6 @@ function stripslashes_deep($value) {
// initialise ME's
initialise_fullme();
-
// init session prevention flag - this is defined on pages that do not want session
if (CLI_SCRIPT) {
// no sessions in CLI scripts possible
@@ -669,6 +668,13 @@ function stripslashes_deep($value) {
$SESSION = &$_SESSION['SESSION'];
$USER = &$_SESSION['USER'];
+// include and start profiling if needed, and register profiling_stop as shutdown function
+if (!empty($CFG->profilingenabled)) {
+ require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
+ profiling_start();
+ register_shutdown_function('profiling_stop');
+}
+
// Process theme change in the URL.
if (!empty($CFG->allowthemechangeonurl) and !empty($_GET['theme'])) {
// we have to use _GET directly because we do not want this to interfere with _POST
View
7 lib/thirdpartylibs.xml
@@ -295,6 +295,13 @@
<licenseversion></licenseversion>
</library>
<library>
+ <location>xhprof</location>
+ <name>XHProf</name>
+ <license>Apache</license>
+ <version>0.9.2</version>
+ <licenseversion>2.0</licenseversion>
+ </library>
+ <library>
<location>xmlize.php</location>
<name>XMLize</name>
<license>GPL</license>
View
63 lib/xhprof/CHANGELOG
@@ -0,0 +1,63 @@
+Modification History:
+
+ *** NOTE ***
+ DO NOT UPDATE THIS FILE. UPDATE package.xml INSTEAD.
+ This file contains the CHANGELOG for the initial release. For subsequent
+ releases, the CHANGLELOG is maintained in the package.xml file itself.
+ Please edit package.xml instead.
+ ************
+
+ 03/02/2008 kannan, checkin xhprof_html/ and xhprof_lib/ directories.
+ cjiang [These contain PHP sources for the UI as well
+ as various supporting libraries to compute
+ "flat" info, diff reports, aggregate results
+ of multiple runs, typeahead support, etc.]
+ 02/20/2008 kannan add basic sanity tests for the extension
+ 02/19/2008 kannan register constants for optional profiler flags;
+ add xhprof.output_dir ini setting.
+ 01/22/2008 ps port cpu affinity functions to FreeBSD
+ 01/15/2008 kannan intercept builtins even if zend_execute_internal
+ were null to begin with
+ 01/14/2008 kannan track builtins by default;
+ fix compiler warnings with fwd decls
+ 12/22/2008 cjiang Further refactoring of the code for open sourcing:
+ (1). Remove level 1 profiling mode.
+ (2). Add xhprof_sample_enable, xhprof_sample_disable.
+ (3). Unifiy function and global variable prefix.
+ (4). Group relevant functions together.
+ (5). Migrate change history to CHANAGELOG file.
+ 12/19/2008 kannan First step refactoring for open sourcing:
+ (1). Put basic direcotry structure
+ (2). Rename extension and function names
+ (3). Add LICENCE header.
+ 06/17/2008 veeve use cycle_timer() for XHPROF_MODE_SAMPLED
+ 03/27/2008 cjiang Add a 'hash-based' filter to reduce the number
+ of expensive call-stack tranversal on recursion
+ detection.
+ 03/17/2008 kannan must not keep state on C stack to handle
+ exit (which causes _zend_bailout to longjmp
+ 02/25/2008 kannan add xhprof_flags to toggle various metric
+ collections (buitins on/off, cpu metric on/off
+ memory stats on/off)
+ 02/14/2008 cjiang Use cycle_timer based on 'rdtsc' instruction
+ on x86 machines to replace gettimeofday. rdtsc
+ is extremely cheap compared with gettimeofday
+ or getrusage.
+ 12/06/2007 veeve bump version 1.1.2,
+ added hp_global_t
+ added mode callbacks, made modes extensible
+ added sampler mode
+ 12/05/2007 veeve added doc; house cleaning
+ 11/28/2007 kannan split include accounting into load/run_init
+ 11/09/2007 kannan memory usage profiling
+ 10/27/2007 kannan handle recursive calls, "include" operations
+ 10/20/2007 kannan add hierarchical profiling; incl vs. exclusive
+ function times; browser based UI; diff and
+ aggregation support
+ 10/10/2007 hzhao creation (flat function profiles)
+
+Authors:
+ Haiping Zhao hzhao@facebook.com
+ Kannan Muthukkaruppan kannan@facebook.com
+ Venkat Venkataramani veeve@facebook.com
+ Changhao Jiang cjiang@facebook.com
View
12 lib/xhprof/CREDITS
@@ -0,0 +1,12 @@
+Originally developed at Facebook, XHProf was open sourced in Mar, 2009.
+
+Creators:
+ Changhao Jiang
+ Kannan Muthukkaruppan
+ Venkat Venkataramani
+ Haiping Zhao
+
+Additional Contributors:
+ George Cabrera - UI enhancements
+ Paul Saab - FreeBSD port
+
View
177 lib/xhprof/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
View
7 lib/xhprof/README
@@ -0,0 +1,7 @@
+For installation and usage notes refer to:
+ xhprof_html/docs/index.html
+
+To view the latest version of the doc, go to:
+ http://pecl.php.net/package/xhprof ---> [View Documentation]
+
+
View
0  lib/xhprof/index.html
No changes.
View
41 lib/xhprof/readme_moodle.txt
@@ -0,0 +1,41 @@
+Description of XHProf 0.9.2 library/viewer import into Moodle
+
+Removed:
+ * examples - examples dir removed completely
+ * extension - extension dir removed completely
+ * package.xml - PECL package definition removed completely
+ * xhprof_html/docs - documentation dir removed completely
+
+Added:
+ * index.html - prevent directory browsing on misconfigured servers
+ * xhprof_moodle.php - containing all the stuff needed to run the xhprof profiler within Moodle
+ * readme_moodle.txt - this file ;-)
+
+Our changes: Look for "moodle" in code
+ * xhprof_html/index.php ----|
+ * xhprof_html/callgraph.php -|=> Changed to use own DB iXHProfRuns implementation (moodle_xhprofrun)
+ * xhprof_html/typeahead.php -|
+ * xhprof_html/css/xhprof.css: Minor tweaks to report styles
+ * xhprof_lib/utils/callgraph_utils.php: Modified to use $CFG->pathtodot
+
+TODO:
+ * with the 3 reports (index, callgraph and typeahead), close seesion asap,
+ so user can continue working with moodle while the report (specially
+ the graph is being generated).
+ * export/import profiling runs: Allow to pick any profile record, encapsulate
+ it into some serialized/encoded way and allow download/upload. It requires
+ DB changes in order to be able to specify the source of each record (own/imported).
+ * move profiling start to earlier place: detect if all the needed $CFG->profilingXXX variables
+ have been defined in config.php file and if that condition is fullfilled, start profiling
+ @ the very first lines of setup.php (as early as possible).
+ * improvements to the listing mode: various commodity details like:
+ - allow to filter by various criteria
+ - inline (and ajax) editing of reference/comment and deleting
+ - whatever daily usage discovers ;-)
+ * add new settings to control if we want to profile things like:
+ - php functions
+ - memory
+ - cpu times
+ (all them are right now enabled for everybody by default)
+
+20101122 - Eloy Lafuente (stronk7): Original import of 0.9.2 release
View
102 lib/xhprof/xhprof_html/callgraph.php
@@ -0,0 +1,102 @@
+<?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.
+//
+
+/**
+ *
+ * A callgraph generator for XHProf.
+ *
+ * * This file is part of the UI/reporting component,
+ * used for viewing results of XHProf runs from a
+ * browser.
+ *
+ * Modification History:
+ * 02/15/2008 - cjiang - The first version of callgraph visualizer
+ * based on Graphviz's DOT tool.
+ *
+ * @author Changhao Jiang (cjiang@facebook.com)
+ */
+
+// start moodle modification: moodleize this script
+require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
+require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
+require_login();
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+// end moodle modification
+
+// by default assume that xhprof_html & xhprof_lib directories
+// are at the same level.
+$GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib';
+
+require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php';
+
+ini_set('max_execution_time', 100);
+
+$params = array(// run id param
+ 'run' => array(XHPROF_STRING_PARAM, ''),
+
+ // source/namespace/type of run
+ 'source' => array(XHPROF_STRING_PARAM, 'xhprof'),
+
+ // the focus function, if it is set, only directly
+ // parents/children functions of it will be shown.
+ 'func' => array(XHPROF_STRING_PARAM, ''),
+
+ // image type, can be 'jpg', 'gif', 'ps', 'png'
+ 'type' => array(XHPROF_STRING_PARAM, 'png'),
+
+ // only functions whose exclusive time over the total time
+ // is larger than this threshold will be shown.
+ // default is 0.01.
+ 'threshold' => array(XHPROF_FLOAT_PARAM, 0.01),
+
+ // whether to show critical_path
+ 'critical' => array(XHPROF_BOOL_PARAM, true),
+
+ // first run in diff mode.
+ 'run1' => array(XHPROF_STRING_PARAM, ''),
+
+ // second run in diff mode.
+ 'run2' => array(XHPROF_STRING_PARAM, '')
+ );
+
+// pull values of these params, and create named globals for each param
+xhprof_param_init($params);
+
+// if invalid value specified for threshold, then use the default
+if ($threshold < 0 || $threshold > 1) {
+ $threshold = $params['threshold'][1];
+}
+
+// if invalid value specified for type, use the default
+if (!array_key_exists($type, $xhprof_legal_image_types)) {
+ $type = $params['type'][1]; // default image type.
+}
+
+// start moodle modification: use own XHProfRuns implementation
+//$xhprof_runs_impl = new XHProfRuns_Default();
+require_once($GLOBALS['XHPROF_LIB_ROOT'].'/../xhprof_moodle.php');
+$xhprof_runs_impl = new moodle_xhprofrun();
+// end moodle modification
+
+if (!empty($run)) {
+ // single run call graph image generation
+ xhprof_render_image($xhprof_runs_impl, $run, $type,
+ $threshold, $func, $source, $critical);
+} else {
+ // diff report call graph image generation
+ xhprof_render_diff_image($xhprof_runs_impl, $run1, $run2,
+ $type, $threshold, $source);
+}
View
90 lib/xhprof/xhprof_html/css/xhprof.css
@@ -0,0 +1,90 @@
+/* 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.
+ */
+
+/* start moodle modification: add basic, smaller, font specs */
+body, p, table, li {
+ font: normal normal normal 13px/1.231 arial, helvetica, clean, sans-serif;
+}
+
+/* end moodle modification */
+
+
+td.sorted {
+ color:#0000FF;
+}
+
+td.vbar, th.vbar {
+ text-align: right;
+ border-left:
+ solid 1px #bdc7d8;
+}
+
+td.vbbar, th.vbar {
+ text-align: right;
+ border-left:
+ solid 1px #bdc7d8;
+ color:blue;
+}
+
+/* diff reports: display regressions in red */
+td.vrbar {
+ text-align: right;
+ border-left:solid 1px #bdc7d8;
+ color:red;
+}
+
+/* diff reports: display improvements in green */
+td.vgbar {
+ text-align: right;
+ border-left: solid 1px #bdc7d8;
+ color:green;
+}
+
+td.vwbar, th.vwbar {
+ text-align: right;
+ border-left: solid 1px white;
+}
+
+td.vwlbar, th.vwlbar {
+ text-align: left;
+ border-left: solid 1px white;
+}
+
+p.blue {
+ color:blue
+}
+
+.bubble {
+ background-color:#C3D9FF
+}
+
+ul.xhprof_actions {
+ float: right;
+ padding-left: 16px;
+ list-style-image: none;
+ list-style-type: none;
+ margin:10px 10px 10px 3em;
+ position:relative;
+}
+
+ul.xhprof_actions li {
+ border-bottom:1px solid #D8DFEA;
+}
+
+ul.xhprof_actions li a:hover {
+ background:#3B5998 none repeat scroll 0 0;
+ color:#FFFFFF;
+}
+
View
100 lib/xhprof/xhprof_html/index.php
@@ -0,0 +1,100 @@
+<?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(s) Kannan Muthukkaruppan
+// Changhao Jiang
+//
+
+// start moodle modification: moodleize this script
+require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
+require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
+require_login();
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+// end moodle modification
+
+// by default assume that xhprof_html & xhprof_lib directories
+// are at the same level.
+$GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib';
+
+require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php';
+
+// param name, its type, and default value
+$params = array('run' => array(XHPROF_STRING_PARAM, ''),
+ 'wts' => array(XHPROF_STRING_PARAM, ''),
+ 'symbol' => array(XHPROF_STRING_PARAM, ''),
+ 'sort' => array(XHPROF_STRING_PARAM, 'wt'), // wall time
+ 'run1' => array(XHPROF_STRING_PARAM, ''),
+ 'run2' => array(XHPROF_STRING_PARAM, ''),
+ 'source' => array(XHPROF_STRING_PARAM, 'xhprof'),
+ 'all' => array(XHPROF_UINT_PARAM, 0),
+ );
+
+// pull values of these params, and create named globals for each param
+xhprof_param_init($params);
+
+/* reset params to be a array of variable names to values
+ by the end of this page, param should only contain values that need
+ to be preserved for the next page. unset all unwanted keys in $params.
+ */
+foreach ($params as $k => $v) {
+ $params[$k] = $$k;
+
+ // unset key from params that are using default values. So URLs aren't
+ // ridiculously long.
+ if ($params[$k] == $v[1]) {
+ unset($params[$k]);
+ }
+}
+
+echo "<html>";
+
+echo "<head><title>XHProf: Hierarchical Profiler Report</title>";
+xhprof_include_js_css();
+echo "</head>";
+
+echo "<body>";
+
+$vbar = ' class="vbar"';
+$vwbar = ' class="vwbar"';
+$vwlbar = ' class="vwlbar"';
+$vbbar = ' class="vbbar"';
+$vrbar = ' class="vrbar"';
+$vgbar = ' class="vgbar"';
+
+// start moodle modification: use own XHProfRuns implementation
+//$xhprof_runs_impl = new XHProfRuns_Default()
+$xhprof_runs_impl = new moodle_xhprofrun();
+// end moodle modification
+
+displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts,
+ $symbol, $sort, $run1, $run2);
+
+
+echo "</body>";
+echo "</html>";
View
BIN  lib/xhprof/xhprof_html/jquery/indicator.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3,549 lib/xhprof/xhprof_html/jquery/jquery-1.2.6.js
3,549 additions, 0 deletions not shown
View
61 lib/xhprof/xhprof_html/jquery/jquery.autocomplete.css
@@ -0,0 +1,61 @@
+/*
+ * Autocomplete - jQuery plugin 1.0.2
+ *
+ * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * Revision: $Id$
+ *
+ */
+
+.ac_results {
+ padding: 0px;
+ border: 1px solid black;
+ background-color: white;
+ overflow: hidden;
+ z-index: 99999;
+}
+
+.ac_results ul {
+ width: 100%;
+ list-style-position: outside;
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+.ac_results li {
+ margin: 0px;
+ padding: 2px 5px;
+ cursor: default;
+ display: block;
+ /*
+ if width will be 100% horizontal scrollbar will apear
+ when scroll mode will be used
+ */
+ /*width: 100%;*/
+ font: menu;
+ font-size: 12px;
+ /*
+ it is very important, if line-height not setted or setted
+ in relative units scroll will be broken in firefox
+ */
+ line-height: 16px;
+ overflow: hidden;
+}
+
+.ac_loading {
+ background: white url('indicator.gif') right center no-repeat;
+}
+
+.ac_odd {
+ background-color: #eee;
+}
+
+.ac_over {
+ background-color: #0A246A;
+ color: white;
+}
View
759 lib/xhprof/xhprof_html/jquery/jquery.autocomplete.js
@@ -0,0 +1,759 @@
+/*
+ * Autocomplete - jQuery plugin 1.0.2
+ *
+ * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * Revision: $Id: jquery.autocomplete.js,v 1.1.1.1 2009-03-17 18:35:18 kannan Exp $
+ *
+ */
+
+;(function($) {
+
+$.fn.extend({
+ autocomplete: function(urlOrData, options) {
+ var isUrl = typeof urlOrData == "string";
+ options = $.extend({}, $.Autocompleter.defaults, {
+ url: isUrl ? urlOrData : null,
+ data: isUrl ? null : urlOrData,
+ delay: isUrl ? $.Autocompleter.defaults.delay : 10,
+ max: options && !options.scroll ? 10 : 150
+ }, options);
+
+ // if highlight is set to false, replace it with a do-nothing function
+ options.highlight = options.highlight || function(value) { return value; };
+
+ // if the formatMatch option is not specified, then use formatItem for backwards compatibility
+ options.formatMatch = options.formatMatch || options.formatItem;
+
+ return this.each(function() {
+ new $.Autocompleter(this, options);
+ });
+ },
+ result: function(handler) {
+ return this.bind("result", handler);
+ },
+ search: function(handler) {
+ return this.trigger("search", [handler]);
+ },
+ flushCache: function() {
+ return this.trigger("flushCache");
+ },
+ setOptions: function(options){
+ return this.trigger("setOptions", [options]);
+ },
+ unautocomplete: function() {
+ return this.trigger("unautocomplete");
+ }
+});
+
+$.Autocompleter = function(input, options) {
+
+ var KEY = {
+ UP: 38,
+ DOWN: 40,
+ DEL: 46,
+ TAB: 9,
+ RETURN: 13,
+ ESC: 27,
+ COMMA: 188,
+ PAGEUP: 33,
+ PAGEDOWN: 34,
+ BACKSPACE: 8
+ };
+
+ // Create $ object for input element
+ var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
+
+ var timeout;
+ var previousValue = "";
+ var cache = $.Autocompleter.Cache(options);
+ var hasFocus = 0;
+ var lastKeyPressCode;
+ var config = {
+ mouseDownOnSelect: false
+ };
+ var select = $.Autocompleter.Select(options, input, selectCurrent, config);
+
+ var blockSubmit;
+
+ // prevent form submit in opera when selecting with return key
+ $.browser.opera && $(input.form).bind("submit.autocomplete", function() {
+ if (blockSubmit) {
+ blockSubmit = false;
+ return false;
+ }
+ });
+
+ // only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
+ $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
+ // track last key pressed
+ lastKeyPressCode = event.keyCode;
+ switch(event.keyCode) {
+
+ case KEY.UP:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.prev();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.DOWN:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.next();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.PAGEUP:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.pageUp();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.PAGEDOWN:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.pageDown();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ // matches also semicolon
+ case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
+ case KEY.TAB:
+ case KEY.RETURN:
+ if( selectCurrent() ) {
+ // stop default to prevent a form submit, Opera needs special handling
+ event.preventDefault();
+ blockSubmit = true;
+ return false;
+ }
+ break;
+
+ case KEY.ESC:
+ select.hide();
+ break;
+
+ default:
+ clearTimeout(timeout);
+ timeout = setTimeout(onChange, options.delay);
+ break;
+ }
+ }).focus(function(){
+ // track whether the field has focus, we shouldn't process any
+ // results if the field no longer has focus
+ hasFocus++;
+ }).blur(function() {
+ hasFocus = 0;
+ if (!config.mouseDownOnSelect) {
+ hideResults();
+ }
+ }).click(function() {
+ // show select when clicking in a focused field
+ if ( hasFocus++ > 1 && !select.visible() ) {
+ onChange(0, true);
+ }
+ }).bind("search", function() {
+ // TODO why not just specifying both arguments?
+ var fn = (arguments.length > 1) ? arguments[1] : null;
+ function findValueCallback(q, data) {
+ var result;
+ if( data && data.length ) {
+ for (var i=0; i < data.length; i++) {
+ if( data[i].result.toLowerCase() == q.toLowerCase() ) {
+ result = data[i];
+ break;
+ }
+ }
+ }
+ if( typeof fn == "function" ) fn(result);
+ else $input.trigger("result", result && [result.data, result.value]);
+ }
+ $.each(trimWords($input.val()), function(i, value) {
+ request(value, findValueCallback, findValueCallback);
+ });
+ }).bind("flushCache", function() {
+ cache.flush();
+ }).bind("setOptions", function() {
+ $.extend(options, arguments[1]);
+ // if we've updated the data, repopulate
+ if ( "data" in arguments[1] )
+ cache.populate();
+ }).bind("unautocomplete", function() {
+ select.unbind();
+ $input.unbind();
+ $(input.form).unbind(".autocomplete");
+ });
+
+
+ function selectCurrent() {
+ var selected = select.selected();
+ if( !selected )
+ return false;
+
+ var v = selected.result;
+ previousValue = v;
+
+ if ( options.multiple ) {
+ var words = trimWords($input.val());
+ if ( words.length > 1 ) {
+ v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
+ }
+ v += options.multipleSeparator;
+ }
+
+ $input.val(v);
+ hideResultsNow();
+ $input.trigger("result", [selected.data, selected.value]);
+ return true;
+ }
+
+ function onChange(crap, skipPrevCheck) {
+ if( lastKeyPressCode == KEY.DEL ) {
+ select.hide();
+ return;
+ }
+
+ var currentValue = $input.val();
+
+ if ( !skipPrevCheck && currentValue == previousValue )
+ return;
+
+ previousValue = currentValue;
+
+ currentValue = lastWord(currentValue);
+ if ( currentValue.length >= options.minChars) {
+ $input.addClass(options.loadingClass);
+ if (!options.matchCase)
+ currentValue = currentValue.toLowerCase();
+ request(currentValue, receiveData, hideResultsNow);
+ } else {
+ stopLoading();
+ select.hide();
+ }
+ };
+
+ function trimWords(value) {
+ if ( !value ) {
+ return [""];
+ }
+ var words = value.split( options.multipleSeparator );
+ var result = [];
+ $.each(words, function(i, value) {
+ if ( $.trim(value) )
+ result[i] = $.trim(value);
+ });
+ return result;
+ }
+
+ function lastWord(value) {
+ if ( !options.multiple )
+ return value;
+ var words = trimWords(value);
+ return words[words.length - 1];
+ }
+
+ // fills in the input box w/the first match (assumed to be the best match)
+ // q: the term entered
+ // sValue: the first matching result
+ function autoFill(q, sValue){
+ // autofill in the complete box w/the first match as long as the user hasn't entered in more data
+ // if the last user key pressed was backspace, don't autofill
+ if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
+ // fill in the value (keep the case the user has typed)
+ $input.val($input.val() + sValue.substring(lastWord(previousValue).length));
+ // select the portion of the value not typed by the user (so the next character will erase)
+ $.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
+ }
+ };
+
+ function hideResults() {
+ clearTimeout(timeout);
+ timeout = setTimeout(hideResultsNow, 200);
+ };
+
+ function hideResultsNow() {
+ var wasVisible = select.visible();
+ select.hide();
+ clearTimeout(timeout);
+ stopLoading();
+ if (options.mustMatch) {
+ // call search and run callback
+ $input.search(
+ function (result){
+ // if no value found, clear the input box
+ if( !result ) {
+ if (options.multiple) {
+ var words = trimWords($input.val()).slice(0, -1);
+ $input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
+ }
+ else
+ $input.val( "" );
+ }
+ }
+ );
+ }
+ if (wasVisible)
+ // position cursor at end of input field
+ $.Autocompleter.Selection(input, input.value.length, input.value.length);
+ };
+
+ function receiveData(q, data) {
+ if ( data && data.length && hasFocus ) {
+ stopLoading();
+ select.display(data, q);
+ autoFill(q, data[0].value);
+ select.show();
+ } else {
+ hideResultsNow();
+ }
+ };
+
+ function request(term, success, failure) {
+ if (!options.matchCase)
+ term = term.toLowerCase();
+ var data = cache.load(term);
+ // recieve the cached data
+ if (data && data.length) {
+ success(term, data);
+ // if an AJAX url has been supplied, try loading the data now
+ } else if( (typeof options.url == "string") && (options.url.length > 0) ){
+
+ var extraParams = {
+ timestamp: +new Date()
+ };
+ $.each(options.extraParams, function(key, param) {
+ extraParams[key] = typeof param == "function" ? param() : param;
+ });
+
+ $.ajax({
+ // try to leverage ajaxQueue plugin to abort previous requests
+ mode: "abort",
+ // limit abortion to this input
+ port: "autocomplete" + input.name,
+ dataType: options.dataType,
+ url: options.url,
+ data: $.extend({
+ q: lastWord(term),
+ limit: options.max
+ }, extraParams),
+ success: function(data) {
+ var parsed = options.parse && options.parse(data) || parse(data);
+ cache.add(term, parsed);
+ success(term, parsed);
+ }
+ });
+ } else {
+ // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
+ select.emptyList();
+ failure(term);
+ }
+ };
+
+ function parse(data) {
+ var parsed = [];
+ var rows = data.split("\n");
+ for (var i=0; i < rows.length; i++) {
+ var row = $.trim(rows[i]);
+ if (row) {
+ row = row.split("|");
+ parsed[parsed.length] = {
+ data: row,
+ value: row[0],
+ result: options.formatResult && options.formatResult(row, row[0]) || row[0]
+ };
+ }
+ }
+ return parsed;
+ };
+
+ function stopLoading() {
+ $input.removeClass(options.loadingClass);
+ };
+
+};
+
+$.Autocompleter.defaults = {
+ inputClass: "ac_input",
+ resultsClass: "ac_results",
+ loadingClass: "ac_loading",
+ minChars: 1,
+ delay: 400,
+ matchCase: false,
+ matchSubset: true,
+ matchContains: false,
+ cacheLength: 10,
+ max: 100,
+ mustMatch: false,
+ extraParams: {},
+ selectFirst: true,
+ formatItem: function(row) { return row[0]; },
+ formatMatch: null,
+ autoFill: false,
+ width: 0,
+ multiple: false,
+ multipleSeparator: ", ",
+ highlight: function(value, term) {
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
+ },
+ scroll: true,
+ scrollHeight: 180
+};
+
+$.Autocompleter.Cache = function(options) {
+
+ var data = {};
+ var length = 0;
+
+ function matchSubset(s, sub) {
+ if (!options.matchCase)
+ s = s.toLowerCase();
+ var i = s.indexOf(sub);
+ if (i == -1) return false;
+ return i == 0 || options.matchContains;
+ };
+
+ function add(q, value) {
+ if (length > options.cacheLength){
+ flush();
+ }
+ if (!data[q]){
+ length++;
+ }
+ data[q] = value;
+ }
+
+ function populate(){
+ if( !options.data ) return false;
+ // track the matches
+ var stMatchSets = {},
+ nullData = 0;
+
+ // no url was specified, we need to adjust the cache length to make sure it fits the local data store
+ if( !options.url ) options.cacheLength = 1;
+
+ // track all options for minChars = 0
+ stMatchSets[""] = [];
+
+ // loop through the array and create a lookup structure
+ for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
+ var rawValue = options.data[i];
+ // if rawValue is a string, make an array otherwise just reference the array
+ rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
+
+ var value = options.formatMatch(rawValue, i+1, options.data.length);
+ if ( value === false )
+ continue;
+
+ var firstChar = value.charAt(0).toLowerCase();
+ // if no lookup array for this character exists, look it up now
+ if( !stMatchSets[firstChar] )
+ stMatchSets[firstChar] = [];
+
+ // if the match is a string
+ var row = {
+ value: value,
+ data: rawValue,
+ result: options.formatResult && options.formatResult(rawValue) || value
+ };
+
+ // push the current match into the set list
+ stMatchSets[firstChar].push(row);
+
+ // keep track of minChars zero items
+ if ( nullData++ < options.max ) {
+ stMatchSets[""].push(row);
+ }
+ };
+
+ // add the data items to the cache
+ $.each(stMatchSets, function(i, value) {
+ // increase the cache size
+ options.cacheLength++;
+ // add to the cache
+ add(i, value);
+ });
+ }
+
+ // populate any existing data
+ setTimeout(populate, 25);
+
+ function flush(){
+ data = {};
+ length = 0;
+ }
+
+ return {
+ flush: flush,
+ add: add,
+ populate: populate,
+ load: function(q) {
+ if (!options.cacheLength || !length)
+ return null;
+ /*
+ * if dealing w/local data and matchContains than we must make sure
+ * to loop through all the data collections looking for matches
+ */
+ if( !options.url && options.matchContains ){
+ // track all matches
+ var csub = [];
+ // loop through all the data grids for matches
+ for( var k in data ){
+ // don't search through the stMatchSets[""] (minChars: 0) cache
+ // this prevents duplicates
+ if( k.length > 0 ){
+ var c = data[k];
+ $.each(c, function(i, x) {
+ // if we've got a match, add it to the array
+ if (matchSubset(x.value, q)) {
+ csub.push(x);
+ }
+ });
+ }
+ }
+ return csub;
+ } else
+ // if the exact item exists, use it
+ if (data[q]){
+ return data[q];
+ } else
+ if (options.matchSubset) {
+ for (var i = q.length - 1; i >= options.minChars; i--) {
+ var c = data[q.substr(0, i)];
+ if (c) {
+ var csub = [];
+ $.each(c, function(i, x) {
+ if (matchSubset(x.value, q)) {
+ csub[csub.length] = x;
+ }
+ });
+ return csub;
+ }
+ }
+ }
+ return null;
+ }
+ };
+};
+
+$.Autocompleter.Select = function (options, input, select, config) {
+ var CLASSES = {
+ ACTIVE: "ac_over"
+ };
+
+ var listItems,
+ active = -1,
+ data,
+ term = "",
+ needsInit = true,
+ element,
+ list;
+
+ // Create results
+ function init() {
+ if (!needsInit)
+ return;
+ element = $("<div/>")
+ .hide()
+ .addClass(options.resultsClass)
+ .css("position", "absolute")
+ .appendTo(document.body);
+
+ list = $("<ul/>").appendTo(element).mouseover( function(event) {
+ if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
+ active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
+ $(target(event)).addClass(CLASSES.ACTIVE);
+ }
+ }).click(function(event) {
+ $(target(event)).addClass(CLASSES.ACTIVE);
+ select();
+ // TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
+ input.focus();
+ return false;
+ }).mousedown(function() {
+ config.mouseDownOnSelect = true;
+ }).mouseup(function() {
+ config.mouseDownOnSelect = false;
+ });
+
+ if( options.width > 0 )
+ element.css("width", options.width);
+
+ needsInit = false;
+ }
+
+ function target(event) {
+ var element = event.target;
+ while(element && element.tagName != "LI")
+ element = element.parentNode;
+ // more fun with IE, sometimes event.target is empty, just ignore it then
+ if(!element)
+ return [];
+ return element;
+ }
+
+ function moveSelect(step) {
+ listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
+ movePosition(step);
+ var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
+ if(options.scroll) {
+ var offset = 0;
+ listItems.slice(0, active).each(function() {
+ offset += this.offsetHeight;
+ });
+ if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
+ list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
+ } else if(offset < list.scrollTop()) {
+ list.scrollTop(offset);
+ }
+ }
+ };
+
+ function movePosition(step) {
+ active += step;
+ if (active < 0) {
+ active = listItems.size() - 1;
+ } else if (active >= listItems.size()) {
+ active = 0;
+ }
+ }
+
+ function limitNumberOfItems(available) {
+ return options.max && options.max < available
+ ? options.max
+ : available;
+ }
+
+ function fillList() {
+ list.empty();
+ var max = limitNumberOfItems(data.length);
+ for (var i=0; i < max; i++) {
+ if (!data[i])
+ continue;
+ var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
+ if ( formatted === false )
+ continue;
+ var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
+ $.data(li, "ac_data", data[i]);
+ }
+ listItems = list.find("li");
+ if ( options.selectFirst ) {
+ listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
+ active = 0;
+ }
+ // apply bgiframe if available
+ if ( $.fn.bgiframe )
+ list.bgiframe();
+ }
+
+ return {
+ display: function(d, q) {
+ init();
+ data = d;
+ term = q;
+ fillList();
+ },
+ next: function() {
+ moveSelect(1);
+ },
+ prev: function() {
+ moveSelect(-1);
+ },
+ pageUp: function() {
+ if (active != 0 && active - 8 < 0) {
+ moveSelect( -active );
+ } else {
+ moveSelect(-8);
+ }
+ },
+ pageDown: function() {
+ if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
+ moveSelect( listItems.size() - 1 - active );
+ } else {
+ moveSelect(8);
+ }
+ },
+ hide: function() {
+ element && element.hide();
+ listItems && listItems.removeClass(CLASSES.ACTIVE);
+ active = -1;
+ },
+ visible : function() {
+ return element && element.is(":visible");
+ },
+ current: function() {
+ return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
+ },
+ show: function() {
+ var offset = $(input).offset();
+ element.css({
+ width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
+ top: offset.top + input.offsetHeight,
+ left: offset.left
+ }).show();
+ if(options.scroll) {
+ list.scrollTop(0);
+ list.css({
+ maxHeight: options.scrollHeight,
+ overflow: 'auto'
+ });
+
+ if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
+ var listHeight = 0;
+ listItems.each(function() {
+ listHeight += this.offsetHeight;
+ });
+ var scrollbarsVisible = listHeight > options.scrollHeight;
+ list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
+ if (!scrollbarsVisible) {
+ // IE doesn't recalculate width when scrollbar disappears
+ listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
+ }
+ }
+
+ }
+ },
+ selected: function() {
+ var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
+ return selected && selected.length && $.data(selected[0], "ac_data");
+ },
+ emptyList: function (){
+ list && list.empty();
+ },
+ unbind: function() {
+ element && element.remove();
+ }
+ };
+};
+
+$.Autocompleter.Selection = function(field, start, end) {
+ if( field.createTextRange ){
+ var selRange = field.createTextRange();
+ selRange.collapse(true);
+ selRange.moveStart("character", start);
+ selRange.moveEnd("character", end);
+ selRange.select();
+ } else if( field.setSelectionRange ){
+ field.setSelectionRange(start, end);
+ } else {
+ if( field.selectionStart ){
+ field.selectionStart = start;
+ field.selectionEnd = end;
+ }
+ }
+ field.focus();
+};
+
+})(jQuery);
View
24 lib/xhprof/xhprof_html/jquery/jquery.tooltip.css
@@ -0,0 +1,24 @@
+/*
+ * jQuery Tooltip plugin 1.3
+ *
+ * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
+ * http://docs.jquery.com/Plugins/Tooltip
+ *
+ * Copyright (c) 2006 - 2008 Jörn Zaefferer
+ *
+ * $Id$
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+
+ #tooltip {
+ position: absolute;
+ z-index: 3000;
+ border: 1px solid #111;
+ background-color: lightyellow;
+ padding: 5px;
+ opacity: 0.9;
+}
+#tooltip h3, #tooltip div { margin: 0; }
View
294 lib/xhprof/xhprof_html/jquery/jquery.tooltip.js
@@ -0,0 +1,294 @@
+/*
+ * jQuery Tooltip plugin 1.3
+ *
+ * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
+ * http://docs.jquery.com/Plugins/Tooltip
+ *
+ * Copyright (c) 2006 - 2008 Jörn Zaefferer
+ *
+ * $Id: jquery.tooltip.js,v 1.1.1.1 2009-03-17 18:35:18 kannan Exp $
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+
+;(function($) {
+
+ // the tooltip element
+ var helper = {},
+ // the current tooltipped element
+ current,
+ // the title of the current element, used for restoring
+ title,
+ // timeout id for delayed tooltips
+ tID,
+ // IE 5.5 or 6
+ IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
+ // flag for mouse tracking
+ track = false;
+
+ $.tooltip = {
+ blocked: false,
+ defaults: {
+ delay: 200,
+ fade: false,
+ showURL: true,
+ extraClass: "",
+ top: 15,
+ left: 15,
+ id: "tooltip"
+ },
+ block: function() {
+ $.tooltip.blocked = !$.tooltip.blocked;
+ }
+ };
+
+ $.fn.extend({
+ tooltip: function(settings) {
+ settings = $.extend({}, $.tooltip.defaults, settings);
+ createHelper(settings);
+ return this.each(function() {
+ $.data(this, "tooltip", settings);
+ this.tOpacity = helper.parent.css("opacity");
+ // copy tooltip into its own expando and remove the title
+ this.tooltipText = this.title;
+ $(this).removeAttr("title");
+ // also remove alt attribute to prevent default tooltip in IE
+ this.alt = "";
+ })
+ .mouseover(save)
+ .mouseout(hide)
+ .click(hide);
+ },
+ fixPNG: IE ? function() {
+ return this.each(function () {
+ var image = $(this).css('backgroundImage');
+ if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
+ image = RegExp.$1;
+ $(this).css({
+ 'backgroundImage': 'none',
+ 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
+ }).each(function () {
+ var position = $(this).css('position');
+ if (position != 'absolute' && position != 'relative')
+ $(this).css('position', 'relative');
+ });
+ }
+ });
+ } : function() { return this; },
+ unfixPNG: IE ? function() {
+ return this.each(function () {
+ $(this).css({'filter': '', backgroundImage: ''});
+ });
+ } : function() { return this; },
+ hideWhenEmpty: function() {
+ return this.each(function() {
+ $(this)[ $(this).html() ? "show" : "hide" ]();
+ });
+ },
+ url: function() {
+ return this.attr('href') || this.attr('src');
+ }
+ });
+
+ function createHelper(settings) {
+ // there can be only one tooltip helper
+ if( helper.parent )
+ return;
+ // create the helper, h3 for title, div for url
+ helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>')
+ // add to document
+ .appendTo(document.body)
+ // hide it at first
+ .hide();
+
+ // apply bgiframe if available
+ if ( $.fn.bgiframe )
+ helper.parent.bgiframe();
+
+ // save references to title and url elements
+ helper.title = $('h3', helper.parent);
+ helper.body = $('div.body', helper.parent);
+ helper.url = $('div.url', helper.parent);
+ }
+
+ function settings(element) {
+ return $.data(element, "tooltip");
+ }
+