Permalink
Browse files

MDL-40793 profiling: Allow multiple reference runs in display

  • Loading branch information...
1 parent 7aed82f commit 874d5a4f856f5e2a0366a4f421955106c6f03d5d @mr-russ mr-russ committed with Russell Smith Jul 20, 2013
Showing with 35 additions and 15 deletions.
  1. +4 −6 admin/tool/profiling/index.php
  2. +1 −1 admin/tool/profiling/lang/en/tool_profiling.php
  3. +30 −8 lib/xhprof/xhprof_moodle.php
@@ -74,12 +74,11 @@
$prevreferences = $DB->get_records_select('profiling',
'url = ? AND runreference = 1 AND timecreated < ?',
array($run->url, $run->timecreated),
- 'timecreated DESC', 'runid', 0, 1);
- $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
+ 'timecreated DESC', 'runid, runcomment, timecreated', 0, 10);
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
$header = get_string('lastrunof', 'tool_profiling', $script);
echo $OUTPUT->heading($header);
- $table = profiling_print_run($run, $prevrunid);
+ $table = profiling_print_run($run, $prevreferences);
echo $table;
echo $OUTPUT->box_end();
@@ -126,12 +125,11 @@
$prevreferences = $DB->get_records_select('profiling',
'url = ? AND runreference = 1 AND timecreated < ?',
array($run->url, $run->timecreated),
- 'timecreated DESC', 'runid', 0, 1);
- $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
+ 'timecreated DESC', 'runid, runcomment, timecreated', 0, 10);
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
$header = get_string('summaryof', 'tool_profiling', $run->url);
echo $OUTPUT->heading($header);
- $table = profiling_print_run($run, $prevrunid);
+ $table = profiling_print_run($run, $prevreferences);
echo $table;
echo $OUTPUT->box_end();
@@ -51,5 +51,5 @@
$string['runid'] = 'Run ID';
$string['summaryof'] = 'Summary of {$a}';
$string['viewdetails'] = 'View profiling details';
-$string['viewdiff'] = 'View profiling differences with last reference run';
+$string['viewdiff'] = 'View profiling differences with:';
$string['viewdiffdetails'] = 'View profiling diff details';
@@ -263,7 +263,14 @@ function profiling_urls($report, $runid, $runid2 = null) {
return $url;
}
-function profiling_print_run($run, $prevrunid = null) {
+/**
+ * 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.
+ */
+function profiling_print_run($run, $prevreferences = null) {
global $CFG, $OUTPUT;
$output = '';
@@ -297,13 +304,28 @@ function profiling_print_run($run, $prevrunid = null) {
// Add link to details
$strviewdetails = get_string('viewdetails', 'tool_profiling');
$url = profiling_urls('run', $run->runid);
- $output.=$OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');' .
- 'return false;"' . ' title="">' . $strviewdetails . '</a>', 3, 'main profilinglink');
- // If there is one previous run marked as reference, add link to diff
- if ($prevrunid) {
- $strviewdiff = get_string('viewdiff', 'tool_profiling');
- $url = 'index.php?runid=' . $run->runid . '&amp;runid2=' . $prevrunid . '&amp;listurl=' . urlencode($run->url);
- $output.=$OUTPUT->heading('<a href="' . $url . '" title="">' . $strviewdiff . '</a>', 3, 'main profilinglink');
+ $output .= $OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');' .
+ 'return false;"' . ' title="">' . $strviewdetails . '</a>', 3, 'main profilinglink');
+
+ // If there are previous run(s) marked as reference, add link to diff.
+ if ($prevreferences) {
+ $table = new html_table();
+ $table->align = array('left', 'left');
+ $table->head = array(get_string('date'), get_string('runid', 'tool_profiling'), get_string('comment', 'tool_profiling'));
+ $table->tablealign = 'center';
+ $table->attributes['class'] = 'flexible generaltable generalbox';
+ $table->colclasses = array('value', 'value', 'value');
+ $table->data = array();
+
+ $output .= $OUTPUT->heading(get_string('viewdiff', 'tool_profiling'), 3, 'main profilinglink');
+
+ foreach ($prevreferences as $reference) {
+ $url = 'index.php?runid=' . $run->runid . '&amp;runid2=' . $reference->runid . '&amp;listurl=' . urlencode($run->url);
+ $row = array(userdate($reference->timecreated), '<a href="' . $url . '" title="">'.$reference->runid.'</a>', $reference->runcomment);
+ $table->data[] = $row;
+ }
+ $output .= $OUTPUT->box(html_writer::table($table), 'profilingrunbox', 'profiling_diffs', true);
+
}
// Add link to export this run.
$strexport = get_string('exportthis', 'tool_profiling');

0 comments on commit 874d5a4

Please sign in to comment.