Skip to content

Commit

Permalink
Adjust time display accuracy to milliseconds (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianshuang authored Sep 20, 2023
1 parent a23d93b commit 2d69300
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.taobao.arthas.core.command.model;

import java.util.Date;
import java.time.LocalDateTime;

/**
* StackCommand result model
* @author gongdewei 2020/4/13
*/
public class StackModel extends ResultModel {

private Date ts;
private LocalDateTime ts;
private double cost;
private String traceId;
private String rpcId;
Expand All @@ -25,11 +25,11 @@ public String getType() {
return "stack";
}

public Date getTs() {
public LocalDateTime getTs() {
return ts;
}

public void setTs(Date ts) {
public void setTs(LocalDateTime ts) {
this.ts = ts;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.taobao.arthas.core.command.model;

import java.util.Date;
import java.time.LocalDateTime;

/**
* Thread root node of TraceCommand
Expand All @@ -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) {
Expand All @@ -30,7 +30,7 @@ public ThreadNode(String threadName, long threadId, boolean daemon, int priority
this.daemon = daemon;
this.priority = priority;
this.classloader = classloader;
timestamp = new Date();
timestamp = LocalDateTime.now();
}

public String getThreadName() {
Expand Down Expand Up @@ -73,11 +73,11 @@ public void setClassloader(String classloader) {
this.classloader = classloader;
}

public Date getTimestamp() {
public LocalDateTime getTimestamp() {
return timestamp;
}

public void setTimestamp(Date timestamp) {
public void setTimestamp(LocalDateTime timestamp) {
this.timestamp = timestamp;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.taobao.arthas.core.command.model;

import java.util.Date;
import java.time.LocalDateTime;

/**
* VO for TimeFragment
* @author gongdewei 2020/4/27
*/
public class TimeFragmentVO {
private Integer index;
private Date timestamp;
private LocalDateTime timestamp;
private double cost;
private boolean isReturn;
private boolean isThrow;
Expand All @@ -31,11 +31,11 @@ public TimeFragmentVO setIndex(Integer index) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.taobao.arthas.core.command.model;

import java.util.Date;
import java.time.LocalDateTime;

/**
* Watch command result model
Expand All @@ -9,7 +9,7 @@
*/
public class WatchModel extends ResultModel {

private Date ts;
private LocalDateTime ts;
private double cost;
private ObjectVO value;

Expand All @@ -26,11 +26,11 @@ public String getType() {
return "watch";
}

public Date getTs() {
public LocalDateTime getTs() {
return ts;
}

public void setTs(Date ts) {
public void setTs(LocalDateTime ts) {
this.ts = ts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -160,7 +161,7 @@ private void finishing(Class<?> clazz, ArthasMethod method, boolean isThrowing,
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.taobao.arthas.core.command.monitor200;

import java.util.Date;
import java.time.LocalDateTime;

/**
* 数据监控用的value for MonitorCommand
Expand All @@ -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;
Expand Down Expand Up @@ -64,14 +64,14 @@ public void setCost(double cost) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.
Expand Down Expand Up @@ -61,7 +61,7 @@ private void finishing(Advice advice) {
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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
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.
Expand Down Expand Up @@ -68,7 +68,7 @@ public void afterThrowing(ClassLoader loader, Class<?> clazz, ArthasMethod metho

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -513,7 +514,7 @@ private void processPlay(CommandProcess process) {

//copy from tt record
TimeFragmentVO replayResult = createTimeFragmentVO(index, tf, expand);
replayResult.setTimestamp(new Date())
replayResult.setTimestamp(LocalDateTime.now())
.setCost(0)
.setReturn(false)
.setReturnObj(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static Element drawTimeTunnelTable(List<TimeFragmentVO> timeFragmentList,
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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.
Expand Down Expand Up @@ -87,7 +87,7 @@ private void watching(Advice advice) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void draw(CommandProcess process, MonitorModel result) {

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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void draw(CommandProcess process, StackModel result) {
.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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void renderNode(StringBuilder sb, TraceNode node, Ansi highlighted) {
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void draw(CommandProcess process, WatchModel model) {
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@
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;


/**
Expand Down Expand Up @@ -230,7 +226,7 @@ private ApiResponse processInitSessionRequest(ApiRequest apiRequest) throws ApiE
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static String welcome(Map<String, String> infos) {
.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());
}
Expand Down
Loading

0 comments on commit 2d69300

Please sign in to comment.