You may say its not a critical bug? Well, its more crazy then critical.

The problem is in start_timer function.

Its your function:

function timer_start($name) {
  global $timers;

  list($usec, $sec) = explode(' ', microtime());
  $timers[$name]['start'] = (float)$usec + (float)$sec;
  $timers[$name]['count'] = isset($timers[$name]['count']) ? $timers[$name]['count']++ : 1;
}

Any timer's count field is always 1. Just don't know... Maybe its some php bug or else. Try it, you'll see.
P.S. My PHP 4.3.6.

But this works:

  $timers[$name]['count'] = isset($timers[$name]['count']) ? ++$timers[$name]['count'] : 1;

Probably it'll work for U too.

Crazy, ha?

CommentFileSizeAuthor
#3 bootstrap.inc_8.patch653 bytespuregin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

markus_petrux’s picture

It is initialized to 1 the first time you call, say timer_start('mytimer'). The next time you call it, the counter is incremented.

puregin’s picture

Priority: Critical » Normal

Can't reproduce. For example, the page timer seems to work fine. I'm marking this as normal priority.
I'm running PHP 5.0.4. Djun

puregin’s picture

FileSize
653 bytes

I spoke too soon. This bug does appear to exist. I tried

  $time = timer_read('page');                                                                                                                             
  timer_start('page');                                                                                                                            
  $count = $timers['page']['count'];                                                                                                                     
  echo t(' Page execution time was %time ms, and the page timer was accessed %count times.', array('%time' => $time, '%count' => $count));  

This indeed gives the wrong answer (1) for count, rather than the expected count (>= 2) unless the count is preincremented. Does this have to do with operator precedence? In any case, here's a patch...

puregin’s picture

Status: Active » Needs review
markus_petrux’s picture

I spoke too soon too. A good catch indeed.

Wouldn't it be clear using count+1 instead of ++count ?

puregin’s picture

Title: Preincrement? » Timer counts not properly incremented

I think the pre-increment syntax is relatively clear...

Renaming the issue to be more descriptive

killes@www.drop.org’s picture

Status: Needs review » Fixed

committed.

john.money’s picture

Why does the variable need to be checked if isset? Incrementing a variable will always make a null variable value 1. Just,

$timers[$name]['count']++;

Crell’s picture

@ Gestaltware: That only works if you don't mind generating an E_NOTICE. Numerous people are trying to push for E_ALL compliance for better future-proofing, which makes the isset() check necessary.

john.money’s picture

Ah, ok. Thanks Crell for point that out.

Anonymous’s picture

Status: Fixed » Closed (fixed)