jcabi-aspects icon indicating copy to clipboard operation
jcabi-aspects copied to clipboard

Time units change during one run

Open VitaliyKulikov opened this issue 8 years ago • 10 comments

Could we don't change time-units in output during one run. I can't parse log file correctly then time is in different units.

VitaliyKulikov avatar May 24 '16 17:05 VitaliyKulikov

@VitaliyKulikov what you mean? Could you please provide an example containing:

  • Problem description
  • What is showing in your log
  • Expected result

Thanks a lot, MC

maurcarvalho avatar May 24 '16 19:05 maurcarvalho

@MauricioJr thanks for quick replay. sure, here is more details.

i need parse log file and collect time for some executions. so, in log i have:

#methodA(...): in 11.90ms (too slow!)
#methodB(...): in 20.15ms (too slow!)
#methodC(...): in 2min (too slow!)

i know that i can cast all time to one unit, but wanna that all time was in one unit - ms OR min, like:

#methodA(...): in 11.90ms (too slow!)
#methodB(...): in 20.15ms (too slow!)
#methodC(...): in 120000ms (too slow!)

VitaliyKulikov avatar May 25 '16 11:05 VitaliyKulikov

@yegor256 dispatch this issue please, see par.21

dmarkov avatar May 30 '16 07:05 dmarkov

@VitaliyKulikov well, this is by design... How would you suggest to make this behavior configurable? The only idea I have is through system properties. something like java -Djcabi.log.smartTime=false Would that work?

yegor256 avatar Jun 27 '16 22:06 yegor256

@yegor256 sure, it will work. as a suggestion, i prefer to use annotation parameter, like:

@Loggable(smartTime = false)

also, as i understand time-unit will be MICROSECONDS by default.

VitaliyKulikov avatar Jun 28 '16 09:06 VitaliyKulikov

@VitaliyKulikov in that case, maybe it's better to do it this way:

@Loggable(timeUnit = TimeUnit.MICROSECONDS)

By default timeUnit attribute will be null, which will mean that the most appropriate time unit will be used. Make sense?

yegor256 avatar Jun 28 '16 16:06 yegor256

@yegor256 awesome )). just in case, if timeUnit = TimeUnit.SECONDS we will lost precision OR we wanna float? For example converting 999 milliseconds to seconds results in 0

VitaliyKulikov avatar Jun 28 '16 16:06 VitaliyKulikov

@VitaliyKulikov maybe we can add one more argument precision, which will contain the amount of digits after the dot? by default it's -1, which means "up to you":

@Loggable(timeUnit = TimeUnit.MICROSECONDS, precision = 2)

what do you think?

yegor256 avatar Jun 28 '16 17:06 yegor256

@yegor256 yep. i think, it will be the best solution for all needs. just to clarify, here are few use-cases:

@Loggable(timeUnit = TimeUnit.SECONDS, precision = 2)
input: 100 ms | output: 0.00 s
input: 10000 ms | output: 0.01 s
input: 1000000 ms | output: 1.00 s

@Loggable(timeUnit = TimeUnit.MICROSECONDS)
input: 100 ms | output: 100 ms
input: 20000 ms | output: 20000 ms

VitaliyKulikov avatar Jun 28 '16 17:06 VitaliyKulikov

@VitaliyKulikov not exactly :) "ms" means milliseconds, while "μs" means microseconds. but you got the idea

yegor256 avatar Jun 28 '16 17:06 yegor256