Fork me on GitHub
Subscribe 3

Ticket #311 (open bug)

The timer for timing script execution isn't started as soon as it should be

  • Created: 2011-02-22 14:59:22
  • Reported by: Reines
  • Assigned to: None
  • Milestone: 2.0-alpha5
  • Component: code
  • Priority: low

At the moment we start the timer after including functions/utf8 library and cleaning up some input. This means it isn't correctly measuring the entire generation time.

See: https://fluxbb.org/forums/viewtopic.php?id=5166

History

Reines 2011-02-22 21:28:06

Just as a note - the solution by Visman doesn't take db_update.php/install.php any other scripts which don't include common.php into account.

Reines 2011-03-11 09:26:06

  • Milestone changed from 1.4.5 to 1.4.6.

Reines 2011-03-11 09:29:50

  • Component set to code.

Reines 2011-03-12 15:52:35

  • Priority changed from normal to low.

Franz 2011-03-18 13:16:24

  • Owner set to Franz.

Franz 2011-03-23 19:59:35

Do we need generation times for the scripts you mentioned, Reines?

Reines 2011-03-23 20:45:42

No, though moving the get_microtime function out of functions.php and into common.php will cause those scripts to get an error unless it is defined in those scripts separately.

Franz 2011-03-23 20:47:52

Which... would suck.
Well, we can use the proper function once we have PHP5 requirements (in v2.0). How about copying the function to common.php, defining it if it doesn't exist in functions.php and just ignore install script etc.?
The timing would then be correct for the scripts where it matters and everybody is happy.

Reines 2011-06-05 21:35:40

  • Milestone changed from 1.4.6 to 2.0-alpha5.

I'm going to just push this back to 2.0. It is a minor issue, and will be much, much easier to fix then.

Franz 2012-02-21 12:40:43

  • Owner Franz removed.

adaur 2015-10-30 11:17:20

Do you have a solution that works?

Visman 2015-10-31 09:27:37

functions.php
1. delete

//
// Return current timestamp (with microseconds) as a float
//
function get_microtime()
{
	list($usec, $sec) = explode(' ', microtime());
	return ((float)$usec + (float)$sec);
}

common.php
2. delete

// Record the start time (will be used to calculate the generation time for the page)
$pun_start = get_microtime();

3. before

// Attempt to load the configuration file config.php
if (file_exists(PUN_ROOT.'config.php'))
	require PUN_ROOT.'config.php';

add

//
// Return current timestamp (with microseconds) as a float
//
function get_microtime()
{
	list($usec, $sec) = explode(' ', microtime());
	return ((float)$usec + (float)$sec);
}

// Record the start time (will be used to calculate the generation time for the page)
$pun_start = get_microtime();

footer.php
4.

// Display debug info (if enabled/defined)
if (defined('PUN_DEBUG'))
{
	echo '<p id="debugtime">[ ';

	// Calculate script generation time
	$time_diff = sprintf('%.3f', get_microtime() - $pun_start);
	echo sprintf($lang_common['Querytime'], $time_diff, $db->get_num_queries());

	if (function_exists('memory_get_usage'))
	{
		echo ' - '.sprintf($lang_common['Memory usage'], file_size(memory_get_usage()));

		if (function_exists('memory_get_peak_usage'))
			echo ' '.sprintf($lang_common['Peak usage'], file_size(memory_get_peak_usage()));
	}

	echo ' ]</p>'."\n";
}


// End the transaction
$db->end_transaction();

// Display executed queries (if enabled)
if (defined('PUN_SHOW_QUERIES'))
	display_saved_queries();

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_footer>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <pun_footer>


// Close the db connection (and free up any result data)
$db->close();

replace

// End the transaction
$db->end_transaction();

// Close the db connection (and free up any result data)
$db->close();

// Display debug info (if enabled/defined)
if (defined('PUN_DEBUG'))
{
	echo '<p id="debugtime">[ ';

	// Calculate script generation time
	$time_diff = sprintf('%.3f', get_microtime() - $pun_start);
	echo sprintf($lang_common['Querytime'], $time_diff, $db->get_num_queries());

	if (function_exists('memory_get_usage'))
	{
		echo ' - '.sprintf($lang_common['Memory usage'], file_size(memory_get_usage()));

		if (function_exists('memory_get_peak_usage'))
			echo ' '.sprintf($lang_common['Peak usage'], file_size(memory_get_peak_usage()));
	}

	echo ' ]</p>'."\n";
}


// Display executed queries (if enabled)
if (defined('PUN_SHOW_QUERIES'))
	display_saved_queries();

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_footer>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <pun_footer>
Comment edited 1 times (Diff)