mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 02:14:52 +00:00
perf[net]: 优化StopWatch的打印格式,保留两位小数
This commit is contained in:
1 parent
be3ceab08f
commit
8acaf7eb57
4 files changed
+19
-7
No files matched your search
@@ -104,7 +104,7 @@ public class NetContext implements ApplicationListener<ApplicationContextEvent>,
|
||||
instance.packetService.init();
|
||||
instance.configManager.initRegistry();
|
||||
|
||||
logger.info("net start success and cost [{}] second", stopWatch.costSecond());
|
||||
logger.info("Net started successfully and cost [{}] seconds", stopWatch.costSeconds());
|
||||
} else if (event instanceof ContextClosedEvent) {
|
||||
shutdownBefore();
|
||||
shutdownAfter();
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OrmContext implements ApplicationListener<ApplicationContextEvent>,
|
||||
instance.ormManager.inject();
|
||||
instance.ormManager.initAfter();
|
||||
|
||||
logger.info("orm start success and cost [{}] second", stopWatch.costSecond());
|
||||
logger.info("Orm started successfully and cost [{}] seconds", stopWatch.costSeconds());
|
||||
} else if (event instanceof ContextClosedEvent) {
|
||||
shutdownBefore();
|
||||
shutdownBetween();
|
||||
|
||||
@@ -14,6 +14,9 @@ package com.zfoo.scheduler.model;
|
||||
|
||||
import com.zfoo.scheduler.util.TimeUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
@@ -26,12 +29,21 @@ public class StopWatch {
|
||||
return TimeUtils.currentTimeMillis() - startTime;
|
||||
}
|
||||
|
||||
public float costSecond() {
|
||||
return (TimeUtils.currentTimeMillis() - startTime) / (float) TimeUtils.MILLIS_PER_SECOND;
|
||||
/**
|
||||
* 从StopWatch被创建,到调用这个方法消耗的时间
|
||||
*
|
||||
* @return 返回消耗的时间,保留两位小数,格式xx.xx
|
||||
*/
|
||||
public String costSeconds() {
|
||||
var cost = cost() / (float) TimeUtils.MILLIS_PER_SECOND;
|
||||
var decimal = new BigDecimal(cost);
|
||||
return decimal.setScale(2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
|
||||
public float costMinute() {
|
||||
return (TimeUtils.currentTimeMillis() - startTime) / (float) TimeUtils.MILLIS_PER_MINUTE;
|
||||
public String costMinutes() {
|
||||
var cost = cost() / (float) TimeUtils.MILLIS_PER_MINUTE;
|
||||
var decimal = new BigDecimal(cost);
|
||||
return decimal.setScale(2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class StorageContext implements ApplicationListener<ApplicationContextEve
|
||||
|
||||
// 移除没有被引用的不必要资源,为了节省服务器内存
|
||||
instance.storageManager.initAfter();
|
||||
logger.info("storage start success and cost [{}] second", stopWatch.costSecond());
|
||||
logger.info("Storage started successfully and cost [{}] seconds", stopWatch.costSeconds());
|
||||
} else if (event instanceof ContextClosedEvent) {
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user