mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-06 02:49:57 +08:00
云快充1.5.0 初始化
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 抖音关注:程序员三丙
|
||||
* 知识星球:https://t.zsxq.com/j9b21
|
||||
*/
|
||||
package sanbing.jcpp.infrastructure.stats;
|
||||
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class StatsTimer {
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
private final Timer timer;
|
||||
|
||||
private int count;
|
||||
private long totalTime;
|
||||
|
||||
public StatsTimer(String name, Timer micrometerTimer) {
|
||||
this.name = name;
|
||||
this.timer = micrometerTimer;
|
||||
}
|
||||
|
||||
public void record(long timeMs) {
|
||||
count++;
|
||||
totalTime += timeMs;
|
||||
timer.record(timeMs, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public double getAvg() {
|
||||
if (count == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return (double) totalTime / count;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
count = 0;
|
||||
totalTime = 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user