mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
Adjust time display accuracy to milliseconds (#2663)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.taobao.arthas.core.command.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* StackCommand result model
|
||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
*/
|
||||
public class StackModel extends ResultModel {
|
||||
|
||||
private Date ts;
|
||||
private LocalDateTime ts;
|
||||
private double cost;
|
||||
private String traceId;
|
||||
private String rpcId;
|
||||
@@ -25,11 +25,11 @@ public class StackModel extends ResultModel {
|
||||
return "stack";
|
||||
}
|
||||
|
||||
public Date getTs() {
|
||||
public LocalDateTime getTs() {
|
||||
return ts;
|
||||
}
|
||||
|
||||
public void setTs(Date ts) {
|
||||
public void setTs(LocalDateTime ts) {
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.taobao.arthas.core.command.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Thread root node of TraceCommand
|
||||
@@ -13,14 +13,14 @@ public class ThreadNode extends TraceNode {
|
||||
private boolean daemon;
|
||||
private int priority;
|
||||
private String classloader;
|
||||
private Date timestamp;
|
||||
private LocalDateTime timestamp;
|
||||
|
||||
private String traceId;
|
||||
private String rpcId;
|
||||
|
||||
public ThreadNode() {
|
||||
super("thread");
|
||||
timestamp = new Date();
|
||||
timestamp = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public ThreadNode(String threadName, long threadId, boolean daemon, int priority, String classloader) {
|
||||
@@ -30,7 +30,7 @@ public class ThreadNode extends TraceNode {
|
||||
this.daemon = daemon;
|
||||
this.priority = priority;
|
||||
this.classloader = classloader;
|
||||
timestamp = new Date();
|
||||
timestamp = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
@@ -73,11 +73,11 @@ public class ThreadNode extends TraceNode {
|
||||
this.classloader = classloader;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
public LocalDateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Date timestamp) {
|
||||
public void setTimestamp(LocalDateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.taobao.arthas.core.command.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* VO for TimeFragment
|
||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
*/
|
||||
public class TimeFragmentVO {
|
||||
private Integer index;
|
||||
private Date timestamp;
|
||||
private LocalDateTime timestamp;
|
||||
private double cost;
|
||||
private boolean isReturn;
|
||||
private boolean isThrow;
|
||||
@@ -31,11 +31,11 @@ public class TimeFragmentVO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
public LocalDateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public TimeFragmentVO setTimestamp(Date timestamp) {
|
||||
public TimeFragmentVO setTimestamp(LocalDateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.taobao.arthas.core.command.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Watch command result model
|
||||
@@ -9,7 +9,7 @@ import java.util.Date;
|
||||
*/
|
||||
public class WatchModel extends ResultModel {
|
||||
|
||||
private Date ts;
|
||||
private LocalDateTime ts;
|
||||
private double cost;
|
||||
private ObjectVO value;
|
||||
|
||||
@@ -26,11 +26,11 @@ public class WatchModel extends ResultModel {
|
||||
return "watch";
|
||||
}
|
||||
|
||||
public Date getTs() {
|
||||
public LocalDateTime getTs() {
|
||||
return ts;
|
||||
}
|
||||
|
||||
public void setTs(Date ts) {
|
||||
public void setTs(LocalDateTime ts) {
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
import com.taobao.arthas.core.util.ThreadLocalWatch;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -160,7 +161,7 @@ class MonitorAdviceListener extends AdviceListenerAdapter {
|
||||
MonitorData oData = value.get();
|
||||
MonitorData nData = new MonitorData();
|
||||
nData.setCost(oData.getCost() + cost);
|
||||
nData.setTimestamp(new Date());
|
||||
nData.setTimestamp(LocalDateTime.now());
|
||||
if (isThrowing) {
|
||||
nData.setFailed(oData.getFailed() + 1);
|
||||
nData.setSuccess(oData.getSuccess());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.taobao.arthas.core.command.monitor200;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 数据监控用的value for MonitorCommand
|
||||
@@ -14,7 +14,7 @@ public class MonitorData {
|
||||
private int success;
|
||||
private int failed;
|
||||
private double cost;
|
||||
private Date timestamp;
|
||||
private LocalDateTime timestamp;
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
@@ -64,14 +64,14 @@ public class MonitorData {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
public LocalDateTime getTimestamp() {
|
||||
if (timestamp == null) {
|
||||
timestamp = new Date();
|
||||
timestamp = LocalDateTime.now();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Date timestamp) {
|
||||
public void setTimestamp(LocalDateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import com.taobao.arthas.core.util.LogUtil;
|
||||
import com.taobao.arthas.core.util.ThreadLocalWatch;
|
||||
import com.taobao.arthas.core.util.ThreadUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author beiwei30 on 29/11/2016.
|
||||
@@ -61,7 +61,7 @@ public class StackAdviceListener extends AdviceListenerAdapter {
|
||||
if (conditionResult) {
|
||||
// TODO: concurrency issues for process.write
|
||||
StackModel stackModel = ThreadUtil.getThreadStackModel(advice.getLoader(), Thread.currentThread());
|
||||
stackModel.setTs(new Date());
|
||||
stackModel.setTs(LocalDateTime.now());
|
||||
process.appendResult(stackModel);
|
||||
process.times().incrementAndGet();
|
||||
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
|
||||
|
||||
@@ -2,28 +2,28 @@ package com.taobao.arthas.core.command.monitor200;
|
||||
|
||||
import com.taobao.arthas.core.advisor.Advice;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 时间碎片
|
||||
*/
|
||||
class TimeFragment {
|
||||
|
||||
public TimeFragment(Advice advice, Date gmtCreate, double cost) {
|
||||
public TimeFragment(Advice advice, LocalDateTime gmtCreate, double cost) {
|
||||
this.advice = advice;
|
||||
this.gmtCreate = gmtCreate;
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
private final Advice advice;
|
||||
private final Date gmtCreate;
|
||||
private final LocalDateTime gmtCreate;
|
||||
private final double cost;
|
||||
|
||||
public Advice getAdvice() {
|
||||
return advice;
|
||||
}
|
||||
|
||||
public Date getGmtCreate() {
|
||||
public LocalDateTime getGmtCreate() {
|
||||
return gmtCreate;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.util.LogUtil;
|
||||
import com.taobao.arthas.core.util.ThreadLocalWatch;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author beiwei30 on 30/11/2016.
|
||||
@@ -68,7 +68,7 @@ public class TimeTunnelAdviceListener extends AdviceListenerAdapter {
|
||||
|
||||
private void afterFinishing(Advice advice) {
|
||||
double cost = threadLocalWatch.costInMillis();
|
||||
TimeFragment timeTunnel = new TimeFragment(advice, new Date(), cost);
|
||||
TimeFragment timeTunnel = new TimeFragment(advice, LocalDateTime.now(), cost);
|
||||
|
||||
boolean match = false;
|
||||
try {
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.taobao.middleware.cli.annotations.Option;
|
||||
import com.taobao.middleware.cli.annotations.Summary;
|
||||
import com.taobao.middleware.cli.annotations.Argument;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -513,7 +514,7 @@ public class TimeTunnelCommand extends EnhancerCommand {
|
||||
|
||||
//copy from tt record
|
||||
TimeFragmentVO replayResult = createTimeFragmentVO(index, tf, expand);
|
||||
replayResult.setTimestamp(new Date())
|
||||
replayResult.setTimestamp(LocalDateTime.now())
|
||||
.setCost(0)
|
||||
.setReturn(false)
|
||||
.setReturnObj(null)
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.monitor200;
|
||||
|
||||
import com.taobao.arthas.core.command.model.ObjectVO;
|
||||
import com.taobao.arthas.core.command.model.TimeFragmentVO;
|
||||
import com.taobao.arthas.core.util.DateUtils;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
import com.taobao.arthas.core.view.ObjectView;
|
||||
import com.taobao.text.Decoration;
|
||||
@@ -81,7 +82,7 @@ public class TimeTunnelTable {
|
||||
static TableElement fillTableRow(TableElement table, TimeFragmentVO tf) {
|
||||
return table.row(
|
||||
"" + tf.getIndex(),
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tf.getTimestamp()),
|
||||
DateUtils.formatDateTime(tf.getTimestamp()),
|
||||
"" + tf.getCost(),
|
||||
"" + tf.isReturn(),
|
||||
"" + tf.isThrow(),
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.util.LogUtil;
|
||||
import com.taobao.arthas.core.util.ThreadLocalWatch;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author beiwei30 on 29/11/2016.
|
||||
@@ -87,7 +87,7 @@ class WatchAdviceListener extends AdviceListenerAdapter {
|
||||
Object value = getExpressionResult(command.getExpress(), advice, cost);
|
||||
|
||||
WatchModel model = new WatchModel();
|
||||
model.setTs(new Date());
|
||||
model.setTs(LocalDateTime.now());
|
||||
model.setCost(cost);
|
||||
model.setValue(new ObjectVO(value, command.getExpand()));
|
||||
model.setSizeLimit(command.getSizeLimit());
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.taobao.arthas.core.command.view;
|
||||
import com.taobao.arthas.core.command.model.MonitorModel;
|
||||
import com.taobao.arthas.core.command.monitor200.MonitorData;
|
||||
import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.util.DateUtils;
|
||||
import com.taobao.text.Decoration;
|
||||
import com.taobao.text.ui.TableElement;
|
||||
import com.taobao.text.util.RenderUtil;
|
||||
@@ -33,7 +34,7 @@ public class MonitorView extends ResultView<MonitorModel> {
|
||||
|
||||
for (MonitorData data : result.getMonitorDataList()) {
|
||||
table.row(
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(data.getTimestamp()),
|
||||
DateUtils.formatDateTime(data.getTimestamp()),
|
||||
data.getClassName(),
|
||||
data.getMethodName(),
|
||||
"" + data.getTotal(),
|
||||
|
||||
@@ -35,7 +35,7 @@ public class StackView extends ResultView<StackModel> {
|
||||
.append(ste.getLineNumber())
|
||||
.append(")\n");
|
||||
}
|
||||
process.write("ts=" + DateUtils.formatDate(result.getTs()) + ";" + sb.toString() + "\n");
|
||||
process.write("ts=" + DateUtils.formatDateTime(result.getTs()) + ";" + sb.toString() + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class TraceView extends ResultView<TraceModel> {
|
||||
ThreadNode threadNode = (ThreadNode) node;
|
||||
//ts=2020-04-29 10:34:00;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
|
||||
sb.append(format("ts=%s;thread_name=%s;id=%d;is_daemon=%s;priority=%d;TCCL=%s",
|
||||
DateUtils.formatDate(threadNode.getTimestamp()),
|
||||
DateUtils.formatDateTime(threadNode.getTimestamp()),
|
||||
threadNode.getThreadName(),
|
||||
threadNode.getThreadId(),
|
||||
threadNode.isDaemon(),
|
||||
|
||||
@@ -20,6 +20,6 @@ public class WatchView extends ResultView<WatchModel> {
|
||||
String result = StringUtils.objectToString(
|
||||
objectVO.needExpand() ? new ObjectView(model.getSizeLimit(), objectVO).draw() : objectVO.getObject());
|
||||
process.write("method=" + model.getClassName() + "." + model.getMethodName() + " location=" + model.getAccessPoint() + "\n");
|
||||
process.write("ts=" + DateUtils.formatDate(model.getTs()) + "; [cost=" + model.getCost() + "ms] result=" + result + "\n");
|
||||
process.write("ts=" + DateUtils.formatDateTime(model.getTs()) + "; [cost=" + model.getCost() + "ms] result=" + result + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -33,19 +33,15 @@ import com.taobao.arthas.core.util.ArthasBanner;
|
||||
import com.taobao.arthas.core.util.DateUtils;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.http.*;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.termd.core.function.Function;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
@@ -230,7 +226,7 @@ public class HttpApiHandler {
|
||||
welcomeModel.setTutorials(ArthasBanner.tutorials());
|
||||
welcomeModel.setMainClass(PidUtils.mainClass());
|
||||
welcomeModel.setPid(PidUtils.currentPid());
|
||||
welcomeModel.setTime(DateUtils.getCurrentDate());
|
||||
welcomeModel.setTime(DateUtils.getCurrentDateTime());
|
||||
resultDistributor.appendResult(welcomeModel);
|
||||
|
||||
//allow input
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ArthasBanner {
|
||||
.row("version", version())
|
||||
.row("main_class", PidUtils.mainClass())
|
||||
.row("pid", PidUtils.currentPid())
|
||||
.row("time", DateUtils.getCurrentDate());
|
||||
.row("time", DateUtils.getCurrentDateTime());
|
||||
for (Entry<String, String> entry : infos.entrySet()) {
|
||||
table.row(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author diecui1202 on 2017/10/25.
|
||||
*/
|
||||
public class DateUtils {
|
||||
public final class DateUtils {
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> dataFormat = new ThreadLocal<SimpleDateFormat>() {
|
||||
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
public static String getCurrentDate() {
|
||||
return dataFormat.get().format(new Date());
|
||||
private DateUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static String formatDate(Date date) {
|
||||
return dataFormat.get().format(date);
|
||||
public static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
public static String getCurrentDateTime() {
|
||||
return DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
||||
}
|
||||
|
||||
public static String formatDateTime(LocalDateTime dateTime) {
|
||||
return DATE_TIME_FORMATTER.format(dateTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
/**
|
||||
*
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brijeshprasad89
|
||||
*
|
||||
*/
|
||||
public class DateUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetCurrentDateWithCorrectFormat() {
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // supported date format
|
||||
Date date = new Date();
|
||||
Assert.assertEquals(DateUtils.formatDate(date), dateFormat.format(date));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentDateWithInCorrectFormat() {
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Not supported Date format
|
||||
Date date = new Date();
|
||||
Assert.assertNotEquals(DateUtils.formatDate(date), dateFormat.format(date));
|
||||
|
||||
public void testFormatDateTimeWithCorrectFormat() {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); // supported date format
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
Assert.assertEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatDateTimeWithInCorrectFormat() {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); // Not supported Date format
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
Assert.assertNotEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user