|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // Copyright (c) 2009 Facebook 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // http://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // 00016 00032 // start moodle modification: moodleize this script 00033 require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); 00034 require_once($CFG->libdir . '/xhprof/xhprof_moodle.php'); 00035 require_login(); 00036 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); 00037 // end moodle modification 00038 00039 // by default assume that xhprof_html & xhprof_lib directories 00040 // are at the same level. 00041 $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib'; 00042 00043 require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php'; 00044 00045 ini_set('max_execution_time', 100); 00046 00047 $params = array(// run id param 00048 'run' => array(XHPROF_STRING_PARAM, ''), 00049 00050 // source/namespace/type of run 00051 'source' => array(XHPROF_STRING_PARAM, 'xhprof'), 00052 00053 // the focus function, if it is set, only directly 00054 // parents/children functions of it will be shown. 00055 'func' => array(XHPROF_STRING_PARAM, ''), 00056 00057 // image type, can be 'jpg', 'gif', 'ps', 'png' 00058 'type' => array(XHPROF_STRING_PARAM, 'png'), 00059 00060 // only functions whose exclusive time over the total time 00061 // is larger than this threshold will be shown. 00062 // default is 0.01. 00063 'threshold' => array(XHPROF_FLOAT_PARAM, 0.01), 00064 00065 // whether to show critical_path 00066 'critical' => array(XHPROF_BOOL_PARAM, true), 00067 00068 // first run in diff mode. 00069 'run1' => array(XHPROF_STRING_PARAM, ''), 00070 00071 // second run in diff mode. 00072 'run2' => array(XHPROF_STRING_PARAM, '') 00073 ); 00074 00075 // pull values of these params, and create named globals for each param 00076 xhprof_param_init($params); 00077 00078 // if invalid value specified for threshold, then use the default 00079 if ($threshold < 0 || $threshold > 1) { 00080 $threshold = $params['threshold'][1]; 00081 } 00082 00083 // if invalid value specified for type, use the default 00084 if (!array_key_exists($type, $xhprof_legal_image_types)) { 00085 $type = $params['type'][1]; // default image type. 00086 } 00087 00088 // start moodle modification: use own XHProfRuns implementation 00089 //$xhprof_runs_impl = new XHProfRuns_Default(); 00090 require_once($GLOBALS['XHPROF_LIB_ROOT'].'/../xhprof_moodle.php'); 00091 $xhprof_runs_impl = new moodle_xhprofrun(); 00092 // end moodle modification 00093 00094 if (!empty($run)) { 00095 // single run call graph image generation 00096 xhprof_render_image($xhprof_runs_impl, $run, $type, 00097 $threshold, $func, $source, $critical); 00098 } else { 00099 // diff report call graph image generation 00100 xhprof_render_diff_image($xhprof_runs_impl, $run1, $run2, 00101 $type, $threshold, $source); 00102 }