Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  //  Copyright (c) 2009 Facebook
   3  //
   4  //  Licensed under the Apache License, Version 2.0 (the "License");
   5  //  you may not use this file except in compliance with the License.
   6  //  You may obtain a copy of the License at
   7  //
   8  //      http://www.apache.org/licenses/LICENSE-2.0
   9  //
  10  //  Unless required by applicable law or agreed to in writing, software
  11  //  distributed under the License is distributed on an "AS IS" BASIS,
  12  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13  //  See the License for the specific language governing permissions and
  14  //  limitations under the License.
  15  //
  16  
  17  /**
  18   *
  19   * A callgraph generator for XHProf.
  20   *
  21   * * This file is part of the UI/reporting component,
  22   *   used for viewing results of XHProf runs from a
  23   *   browser.
  24   *
  25   * Modification History:
  26   *  02/15/2008 - cjiang  - The first version of callgraph visualizer
  27   *                         based on Graphviz's DOT tool.
  28   *
  29   * @author Changhao Jiang (cjiang@facebook.com)
  30   */
  31  
  32  // Start moodle modification: moodleize this script.
  33  require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
  34  require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
  35  require_login();
  36  require_capability('moodle/site:config', context_system::instance());
  37  raise_memory_limit(MEMORY_HUGE);
  38  \core\session\manager::write_close();
  39  // End moodle modification.
  40  
  41  // by default assume that xhprof_html & xhprof_lib directories
  42  // are at the same level.
  43  $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib';
  44  
  45  require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php';
  46  
  47  ini_set('max_execution_time', 100);
  48  
  49  $params = array(// run id param
  50                  'run' => array(XHPROF_STRING_PARAM, ''),
  51  
  52                  // source/namespace/type of run
  53                  'source' => array(XHPROF_STRING_PARAM, 'xhprof'),
  54  
  55                  // the focus function, if it is set, only directly
  56                  // parents/children functions of it will be shown.
  57                  'func' => array(XHPROF_STRING_PARAM, ''),
  58  
  59                  // image type, can be 'jpg', 'gif', 'ps', 'png', 'svg'
  60                  'type' => array(XHPROF_STRING_PARAM, 'svg'),
  61  
  62                  // only functions whose exclusive time over the total time
  63                  // is larger than this threshold will be shown.
  64                  // default is 0.01.
  65                  'threshold' => array(XHPROF_FLOAT_PARAM, 0.01),
  66  
  67                  // whether to show critical_path
  68                  'critical' => array(XHPROF_BOOL_PARAM, true),
  69  
  70                  // first run in diff mode.
  71                  'run1' => array(XHPROF_STRING_PARAM, ''),
  72  
  73                  // second run in diff mode.
  74                  'run2' => array(XHPROF_STRING_PARAM, '')
  75                  );
  76  
  77  // pull values of these params, and create named globals for each param
  78  xhprof_param_init($params);
  79  
  80  // if invalid value specified for threshold, then use the default
  81  if ($threshold < 0 || $threshold > 1) {
  82    $threshold = $params['threshold'][1];
  83  }
  84  
  85  // if invalid value specified for type, use the default
  86  if (!array_key_exists($type, $xhprof_legal_image_types)) {
  87    $type = $params['type'][1]; // default image type.
  88  }
  89  
  90  // Start moodle modification: use own XHProfRuns implementation.
  91  // $xhprof_runs_impl = new XHProfRuns_Default();
  92  $xhprof_runs_impl = new moodle_xhprofrun();
  93  // End moodle modification.
  94  
  95  if (!empty($run)) {
  96    // single run call graph image generation
  97    xhprof_render_image($xhprof_runs_impl, $run, $type,
  98                        $threshold, $func, $source, $critical);
  99  } else {
 100    // diff report call graph image generation
 101    xhprof_render_diff_image($xhprof_runs_impl, $run1, $run2,
 102                             $type, $threshold, $source);
 103  }