Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(no description)

Copyright: 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1201 lines (46 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

moodle_xhprofrun:: (8 methods):
  __construct()
  get_run()
  save_run()
  prepare_run()
  set_reducedata()
  sum_calls()
  reduce_run_data()
  xhprof_topo_sort()

xhprof_table_sql:: (7 methods):
  get_row_class()
  set_listurlmode()
  col_url()
  col_timecreated()
  col_totalexecutiontime()
  col_totalcputime()
  col_totalmemory()

Defines 7 functions


Class: moodle_xhprofrun  - X-Ref

Custom implementation of iXHProfRuns

This class is one implementation of the iXHProfRuns interface, in charge
of storing and retrieve profiling run data to/from DB (profiling table)

The interface only defines two methods to be defined: get_run() and
save_run() we'll be implementing some more in order to keep all the
rest of information in our runs properly handled.
__construct()   X-Ref
No description

get_run($run_id, $type, &$run_desc)   X-Ref
Given one runid and one type, return the run data
and some extra info in run_desc from DB

Note that $type is completely ignored

save_run($xhprof_data, $type, $run_id = null)   X-Ref
Given some run data, one type and, optionally, one runid
store the information in DB

Note that $type is completely ignored

prepare_run($url)   X-Ref
No description

set_reducedata(bool $reducedata)   X-Ref
Enable or disable reducing profiling data.

param: bool $reducedata Decide if we want to reduce profiling data (true) or no (false).

sum_calls($sum, $data)   X-Ref
No description

reduce_run_data(array $info)   X-Ref
Reduce the run data to a more manageable size.

This removes from the run data all the entries that
are matching a group of regular expressions.

The main use is to remove all the calls between "__Mustache"
functions, which don't provide any useful information and
make the call-graph too complex to be handled.

param: array $info The xhprof run data, original array.
return: array The xhprof run data, reduced array.

xhprof_topo_sort(array $info)   X-Ref
Sort the xhprof run pseudo-topologically, so all parents are always before their children.

Note that this is not a proper, complex, recursive topological sorting algorithm, returning
nodes that later have to be converted back to xhprof "pairs" but, instead, does the specific
work to get those parent==>child (2 levels only) "pairs" sorted (parents always before children).

param: array $info The xhprof run data, original array.
return: array The xhprof run data, sorted array.

Class: xhprof_table_sql  - X-Ref

Simple subclass of {@link table_sql} that provides
some custom formatters for various columns, in order
to make the main profiles list nicer

get_row_class($row)   X-Ref
Get row classes to be applied based on row contents


set_listurlmode($listurlmode)   X-Ref
Define it the table is in listurlmode or not, output will
be different based on that


col_url($row)   X-Ref
Format URL, so it points to last run for that url


col_timecreated($row)   X-Ref
Format profiling date, human and pointing to run


col_totalexecutiontime($row)   X-Ref
Format execution time


col_totalcputime($row)   X-Ref
Format cpu time


col_totalmemory($row)   X-Ref
Format memory


Functions that are not part of a class:

profiling_is_running($value = null)   X-Ref
Returns if profiling is running, optionally setting it


profiling_is_saved($value = null)   X-Ref
Returns if profiling has been saved, optionally setting it


profiling_available()   X-Ref
Whether PHP profiling is available.

This check ensures that one of the available PHP Profiling extensions is available.

return: bool

profiling_start()   X-Ref
Start profiling observing all the configuration


profiling_get_flag($flag)   X-Ref
Check for profiling flags in all possible places

param: string $flag name
return: boolean

profiling_stop()   X-Ref
Stop profiling, gathering results and storing them


profiling_prune_old_runs($exception = 0)   X-Ref
No description

profiling_get_script()   X-Ref
Returns the path to the php script being requested

Note this function is a partial copy of initialise_fullme() and
setup_get_remote_url(), in charge of setting $FULLME, $SCRIPT and
friends. To be used by early profiling runs in situations where
$SCRIPT isn't defined yet

return: string absolute path (wwwroot based) of the script being executed

profiling_urls($report, $runid, $runid2 = null)   X-Ref
No description

profiling_print_run($run, $prevreferences = null)   X-Ref
Generate the output to print a profiling run including further actions you can then take.

param: object $run The profiling run object we are going to display.
param: array $prevreferences A list of run objects to list as comparison targets.
return: string The output to display on the screen for this run.

profiling_print_rundiff($run1, $run2)   X-Ref
No description

profiling_list_controls($listurl)   X-Ref
Helper function that returns the HTML fragment to
be displayed on listing mode, it includes actions
like deletion/export/import...


profiling_string_matches($string, $patterns)   X-Ref
Helper function that looks for matchings of one string
against an array of * wildchar patterns


profiling_get_difference($number1, $number2, $units = '', $factor = 1, $numdec = 2)   X-Ref
Helper function that, given to floats, returns their numerical
and percentual differences, propertly formated and cssstyled


profiling_export_runs(array $runids, $file)   X-Ref
Export profiling runs to a .mpr (moodle profile runs) file.

This function gets an array of profiling runs (array of runids) and
saves a .mpr file into destination for ulterior handling.

Format of .mpr files:
mpr files are simple zip packages containing these files:
- moodle_profiling_runs.xml: Metadata about the information
exported. Contains some header information (version and
release of moodle, database, git hash - if available, date
of export...) and a list of all the runids included in the
export.
- runid.xml: One file per each run detailed in the main file,
containing the raw dump of the given runid in the profiling table.

Possible improvement: Start storing some extra information in the
profiling table for each run (moodle version, database, git hash...).

param: array $runids list of runids to be exported.
param: string $file filesystem fullpath to destination .mpr file.
return: boolean the mpr file has been successfully exported (true) or no (false).

profiling_import_runs($file, $commentprefix = '')   X-Ref
Import a .mpr (moodle profile runs) file into moodle.

See {@link profiling_export_runs()} for more details about the
implementation of .mpr files.

param: string $file filesystem fullpath to target .mpr file.
param: string $commentprefix prefix to add to the comments of all the imported runs.
return: boolean the mpr file has been successfully imported (true) or no (false).

profiling_export_generate(array $runids, $tmpdir)   X-Ref
Generate the mpr contents (xml files) in the temporal directory.

param: array $runids list of runids to be generated.
param: string $tmpdir filesystem fullpath of tmp generation.
return: boolean the mpr contents have been generated (true) or no (false).

profiling_export_package($file, $tmpdir)   X-Ref
Package (zip) the mpr contents (xml files) in the final location.

param: string $file filesystem fullpath to destination .mpr file.
param: string $tmpdir filesystem fullpath of tmp generation.
return: boolean the mpr contents have been generated (true) or no (false).

profiling_get_import_main_schema()   X-Ref
Return the xml schema for the main import file.

return: string

profiling_get_import_run_schema()   X-Ref
Return the xml schema for each individual run import file.

return: string