Bug #71683 useless decimal digits in "has waited at ... for xxx.yy seconds" messages
Submitted: 12 Feb 2014 12:20 Modified: 12 Feb 2014 12:21
Reporter: Hartmut Holzgraefe Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S4 (Feature request)
Version:5.6.15 OS:Any
Assigned to: CPU Architecture:Any

[12 Feb 2014 12:20] Hartmut Holzgraefe
Description:
The code generating this message is:

        fprintf(file,
                "--Thread %lu has waited at %s line %lu"
                " for %.2f seconds the semaphore:\n",
                (ulong) os_thread_pf(cell->thread),
                innobase_basename(cell->file), (ulong) cell->line,
                difftime(time(NULL), cell->reservation_time));

So the result of difftime() is printed using %.2f as format.

difftime() never returns fractional if implemented according to the standard though:

  "... The difftime() function shall return the difference expressed in seconds as a type double. ..."
  (see eg. http://pubs.opengroup.org/onlinepubs/009695399/functions/difftime.html )

(the fact that it returns double instead of time_t is probably that time_t may be unsigned ...?)

So those extra two decimals give a false sense of precision that isn't actually there, and just printing the number of seconds without decimals would be sufficient

How to repeat:
see above

Suggested fix:
change %.2f format specifier to %.0f, or use %d and cast to (int) ...?
[12 Feb 2014 12:21] Hartmut Holzgraefe
PS: shouldn't this code use ut_time() and ut_timediff() from ut0ut.h ?