MDL-79285 xhprof: Enable reducing runs data for quicker use
commitbc70bd69edb651c51fa12eb24e25d6eaa8068315
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 6 Sep 2023 18:38:05 +0000 (6 20:38 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 26 Sep 2023 17:39:47 +0000 (26 19:39 +0200)
treec5d7c80f80bf65b9f04accfbb29fb70959f6a679
parentc6e727732a7f3f1060b1c1fbd7875746db5f1000
MDL-79285 xhprof: Enable reducing runs data for quicker use

Here we are reducing the xhprof runs data by removing the
__Mustache==>__Mustache calls and all the orphaned data.

To save N iterations what we are doing is:

0. The information is "topologically" sorted, so we ensure that
   all the parents in the data are processed before the children.
   (this will help a lot when cleaning orphaned data, see below).
1. First pass, all the candidate (by regexp) calls are removed
   from the run data.
2. Second pass, all the orphaned information (calls that have
   ended losing his parent) are also removed, so data is consistent.
   Note that, normally we would need N passes to remove all the
   orphaned data (because each pass creates new orphan candidates),
   but, as far as we have ensured that the information is topologically
   sorted (see point 0 above), all this can be done in one unique pass.

TODO:
  - Add unit tests.
  - Enable some system to be able to decide which utilities we
    want to get the data reduced and which ones will continue
    using the complete data. Right now the reduction is being
    applied to all the utilities (both table and graph views).
  - Document the change and, if implemented, the way to select
    between complete/reduced data.
  - Consider adding some caching to speed-up the reduction process
    (some TODOs have been left in the code pointing to the critical
    points).
lib/xhprof/xhprof_moodle.php