Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

(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: 1050 lines (39 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

moodle_xhprofrun:: (5 methods):
  __construct()
  get_run()
  save_run()
  prepare_run()
  sum_calls()

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

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

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