Author: daniel
Description:
Patch file for wfDebugLog to render more precise timestamps
Log entries from wfDebugLog() include a timestamp that shows the time to the nearest second. It is often the case that many actions complete and many log items are output in a single second, all showing the same timestamp. Consequently, often the timestamp is not precise enough to properly evaluate timing between events, especially those events that occur within the same timestamp second.
This is different from the wfDebug() function, which renders timestamps to the nearest 0.0001 second when the $wgDebugTimestamps global is set. Note that Bug 14601 recommends using wfDebugLog() instead of the more widely used wfDebug().
PHP provides a microtime() function that reports time with the fractional part of the second, but the current wfDebugLog code relies on the MWDateTime() object, which does not store (or render) time more precisely than one second.
The attached patch demonstrates one possible solution using microtime() to fetch the timestamp with the fractional second part, and appending that fractional part to the timestamp in the log entry.
The patch only produces this more precise when the global variable $wgDebugLogTimestampPrecision is set to a number that represents the digits of precision greater than zero. The actual number of digits would not exceed the total number of digits provided by microtime(). If this global is zero (0) or is not set, the behavior is exactly as without the patch. For example:
// show timestamps to the nearest millisecond
$wgDebugLogTimestampPrecision = 3;
As with the current wfDebugLog timestamp, the more precise timestamp provided by this example patch includes the decimal fraction of a second in a manner that is compatible with ISO 8601 (without the date/time "T" separator): "YY-MM-DD HH:MM:SS.S[...]". The time zone is omitted, as before.
Another solution that might apply much more broadly would include modifying the MWDateTime object to record and render time more precisely.
Version: 1.23.0
Severity: enhancement
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=73492
Attached: