Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading label for query duration: "duration_μs" #5

Closed
holtkamp opened this issue May 27, 2019 · 4 comments
Closed

Misleading label for query duration: "duration_μs" #5

holtkamp opened this issue May 27, 2019 · 4 comments

Comments

@holtkamp
Copy link
Contributor

Currently the label used for query duration is duration_μs:

'duration_μs' => $stop - $this->start,

For me μs suggests that the value is indicated in microseconds, also see https://en.wikipedia.org/wiki/Microsecond

However, the value itself is indicated in seconds, only the level of detail is in microseconds.

So I would expect the label to be: duration_s, or simply duration...

Maybe a bit nitpicking 😉 , but it might be something to think about.

@abacaphiliac
Copy link
Owner

good catch. i must have misunderstood the microtime docs. i'm definitely interested in getting a quick fix in. is that something you'd be interested in contributing as well? i'm also interested in getting a good test around the duration units to not only confirm the desired behavior now but also to prevent any mistakes in the future, haha. any ideas on that front?

@holtkamp
Copy link
Contributor Author

holtkamp commented May 28, 2019

i'm definitely interested in getting a quick fix in. is that something you'd be interested in contributing as well

Well, I can open a PR to replace duration_μs with duration, or durationInSeconds. We should probably not over-engineer this 😄

i'm also interested in getting a good test around the duration units to not only confirm the desired behavior now but also to prevent any mistakes in the future, haha. any ideas on that front?

mmm, interesting, never thought about it like that, but we "could" consider using a DateInterval representation, as of PHP 7.1 this supports the fractional part.

$d1=new DateTime("2012-07-08 11:14:15.638276"); 
$d2=new DateTime("2012-07-08 11:14:15.889342"); 
$diff=$d2->diff($d1); 
print_r( $diff ) ;

results in

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0.251066
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 1
    [days] => 0
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Only the question then still stands: how to "represent" this, PT0.251066F seems not a valid interval specification. I think it would be best to simply put it in number of seconds, also facilitating analysis tools to analyse log files and extract query times.

@abacaphiliac
Copy link
Owner

We should probably not over-engineer this 😄

i agree.

regarding the new label, i'd prefer some indication of units instead of simply duration, and the rest of the logger properties use snake-case so i'd prefer to stick with that convention. duration_s is acceptable but maybe we should compromise with duration_in_seconds, since we all know abbreviations are horrid : P

your DateInterval idea is very interesting to me. i would prefer to move to objects for managing date math and formatting anyway and we can certainly do that later. currently, this lib can be installed on php 7.0 so i'll schedule an overdue routine version bump and look into it at that time.

regarding interval formatting, there is a format function which i think we can use to reproduce the microtime format.

e.g.

php > $start = new DateTime();
php > // wait some time...
php > $start = new DateTime();
php > echo $end->diff($start)->format('%s.%f');
9.50798

abacaphiliac added a commit that referenced this issue Jan 18, 2020
fixes(#5): duration is expressed in seconds, not microseconds
@abacaphiliac
Copy link
Owner

resolved by #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants