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
$CMD_DURATION Weird format #1585
Comments
See #1279 too, which suggests outputting using the real/user/sys triplet. |
That would be great, is there any change of that happening any time soon? |
Not as such, but go for it if you feel up to it. |
Awesome, my C is a little rusty, but this should be simple enough. Just to be clear, you're fine with me getting rid of all that formatting and just returning the duration in ms? |
I don't think you'll find many people attached to the current behavior. Start by proposing any reasonable alternatives you can think of, then give your preference and justify it - pros and cons. Focusing on the use cases is good justification. The use case that prompted your interest (doing math) is a good one, and also think about formatting for display. For example, if the user wanted to show the duration of the last command in the prompt, what would the script to do that look like? Hope that doesn't scare you off. It's not mean to be some big process, just to put a little thought into the design. |
Not a problem. I definitely think setting Pros
Cons
Example use. Sends user notification if last command took more then ten seconds to execute.
|
I second the move to using milliseconds only.
By comparison, converting a value in ms to "formated" time is a lot simpler - it can be accomplished with the following:
This also allows users to choose their own format. |
I am having a bit of trouble implementing this(I don't know much c++). When I change out
I expect it to set $CMD_DURATION to the number of microseconds that is took the command to run(see |
usecs are in microseconds, namely 1 millionth of a second. Also you are ignoring the seconds part of the time difference. Lastly, the size information you provide to swprintf is not correct. You should provide the whole size of the memory to allocate, which would be equal to the size of 16 chars in your case. |
Ah, it both added together, thanks. |
It still doesn't make sense to me. If I swap in
and run |
I think you should multiply secs and divide usecs if you want the result in milliseconds. But the format string you've selected would produce something like '2000|5' in that case, if you ran sleep 2. Is that what you'd like? |
Ugg, I can't believe I reversed those. Also, the formatting was just for debugging. Pull request incoming. |
I am trying to make my prompt notify me when a command that has taken a certain amount of time is done. $CMD_DURATION is awesome for that, except its has a really weird output format, which makes it hard to any math with. This does not appear to be used anywhere else, so why the weird output? Wouldn't it be better to just output it in milliseconds?
The text was updated successfully, but these errors were encountered: