Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

   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  // XHProf: A Hierarchical Profiler for PHP
  19  //
  20  // XHProf has two components:
  21  //
  22  //  * This module is the UI/reporting component, used
  23  //    for viewing results of XHProf runs from a browser.
  24  //
  25  //  * Data collection component: This is implemented
  26  //    as a PHP extension (XHProf).
  27  //
  28  //
  29  //
  30  // @author(s)  Kannan Muthukkaruppan
  31  //             Changhao Jiang
  32  //
  33  
  34  // Start moodle modification: moodleize this script.
  35  require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
  36  require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
  37  require_login();
  38  require_capability('moodle/site:config', context_system::instance());
  39  raise_memory_limit(MEMORY_HUGE);
  40  \core\session\manager::write_close();
  41  // End moodle modification.
  42  
  43  // by default assume that xhprof_html & xhprof_lib directories
  44  // are at the same level.
  45  $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib';
  46  
  47  require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php';
  48  
  49  // param name, its type, and default value
  50  $params = array('run'        => array(XHPROF_STRING_PARAM, ''),
  51                  'wts'        => array(XHPROF_STRING_PARAM, ''),
  52                  'symbol'     => array(XHPROF_STRING_PARAM, ''),
  53                  'sort'       => array(XHPROF_STRING_PARAM, 'wt'), // wall time
  54                  'run1'       => array(XHPROF_STRING_PARAM, ''),
  55                  'run2'       => array(XHPROF_STRING_PARAM, ''),
  56                  'source'     => array(XHPROF_STRING_PARAM, 'xhprof'),
  57                  'all'        => array(XHPROF_UINT_PARAM, 0),
  58                  );
  59  
  60  // pull values of these params, and create named globals for each param
  61  xhprof_param_init($params);
  62  
  63  /* reset params to be a array of variable names to values
  64     by the end of this page, param should only contain values that need
  65     to be preserved for the next page. unset all unwanted keys in $params.
  66   */
  67  foreach ($params as $k => $v) {
  68    $params[$k] = $$k;
  69  
  70    // unset key from params that are using default values. So URLs aren't
  71    // ridiculously long.
  72    if ($params[$k] == $v[1]) {
  73      unset($params[$k]);
  74    }
  75  }
  76  
  77  echo "<html>";
  78  
  79  echo "<head><title>XHProf: Hierarchical Profiler Report</title>";
  80  xhprof_include_js_css();
  81  echo "</head>";
  82  
  83  echo "<body>";
  84  
  85  $vbar  = ' class="vbar"';
  86  $vwbar = ' class="vwbar"';
  87  $vwlbar = ' class="vwlbar"';
  88  $vbbar = ' class="vbbar"';
  89  $vrbar = ' class="vrbar"';
  90  $vgbar = ' class="vgbar"';
  91  
  92  // Start moodle modification: use own XHProfRuns implementation.
  93  // $xhprof_runs_impl = new XHProfRuns_Default();
  94  $xhprof_runs_impl = new moodle_xhprofrun();
  95  $reducedata = xhprof_get_bool_param('reducedata', 0); // Don't reduce data by default.
  96  $xhprof_runs_impl->set_reducedata($reducedata);
  97  if ($reducedata) {
  98      // We need to inject it, so we continue in "reduced data mode" all the time.
  99      $params['reducedata'] = $reducedata;
 100  }
 101  // End moodle modification.
 102  
 103  displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts,
 104                      $symbol, $sort, $run1, $run2);
 105  
 106  
 107  echo "</body>";
 108  echo "</html>";