KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Report on page / query load times #1647

Open Keith Burke opened this topic on on Oct 5, 2020 - 7 comments

Keith Burke commented on Oct 5, 2020

Hi,

Is there a function to return report load times [query and/or presentation etc]?

Keith

David Winterburn commented on Oct 6, 2020

Please try this:

$report = new MyReport();

$start = microtime(true); //get Unix time in seconds
$report->run();
$time_elapsed_secs = microtime(true) - $start;
echo "report running time = $time_elapsed_secs <br>";

$start = microtime(true);
$report->render();
$time_elapsed_secs = microtime(true) - $start;
echo "report rendering time = $time_elapsed_secs <br>";

Keith Burke commented on Oct 6, 2020

Cheers David. I thought there might be something sexy like $report->magicRunAndRenderTime() :)

Keith Burke commented on Oct 6, 2020

Is there an easy way of passing time_elapsed_secs into the view?

Keith Burke commented on Oct 6, 2020

To be specific, the run() elapsed time. Does render() take any parameters?

David Winterburn commented on Oct 6, 2020

Hi Keith,

Just set the running time as a property of the report like this:

$start = microtime(true); //get Unix time in seconds
$report->run();
$runningTime = microtime(true) - $start;
$report->runningTime = $runningTime;
$report->render();

Then in the report's view you could use $this->runningTime.

As for rendering time, it might require some trick. First put some place holders like "{runningTime}", "{renderingTime}" in your view, then use this code:

$start = microtime(true); //get Unix time in seconds
$report->run();
$runningTime = microtime(true) - $start;

ob_start();
$start = microtime(true);
$report->render();
$reportContent = ob_get_clearn();
$renderingTime = microtime(true) - $start;

$reportContent = str_replace("{runningTime}", $runningTime, $reportContent):
$reportContent = str_replace("{renderingTime}", $renderingTime, $reportContent):

echo $reportContent;

Keith Burke commented on Oct 6, 2020

Ah it's ok. I got it sorted by modifying my index.php a little to include a tiny bit of the view.

Thanks David.

Keith Burke commented on Oct 6, 2020

I just saw your update. Amazing., Thanks again.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

DataGrid