Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/org/tikv/common/log/SlowLogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class SlowLogImpl implements SlowLog {

private static final int MAX_SPAN_SIZE = 1024;

public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");

private final List<SlowLogSpan> slowLogSpans = new ArrayList<>();
private Throwable error = null;

Expand Down Expand Up @@ -85,10 +83,11 @@ public void log() {
}

private String getSlowLogString(long currentMS) {
SimpleDateFormat dateFormat = getSimpleDateFormat();
JsonObject jsonObject = new JsonObject();

jsonObject.addProperty("start", DATE_FORMAT.format(startMS));
jsonObject.addProperty("end", DATE_FORMAT.format(currentMS));
jsonObject.addProperty("start", dateFormat.format(startMS));
jsonObject.addProperty("end", dateFormat.format(currentMS));
jsonObject.addProperty("duration", (currentMS - startMS) + "ms");
if (error != null) {
jsonObject.addProperty("error", error.getMessage());
Expand All @@ -106,4 +105,8 @@ private String getSlowLogString(long currentMS) {

return jsonObject.toString();
}

public static SimpleDateFormat getSimpleDateFormat() {
return new SimpleDateFormat("HH:mm:ss.SSS");
}
}
16 changes: 9 additions & 7 deletions src/main/java/org/tikv/common/log/SlowLogSpanImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

package org.tikv.common.log;

import static org.tikv.common.log.SlowLogImpl.DATE_FORMAT;
import static org.tikv.common.log.SlowLogImpl.getSimpleDateFormat;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.text.SimpleDateFormat;

public class SlowLogSpanImpl implements SlowLogSpan {
private final String name;
Expand Down Expand Up @@ -60,27 +61,28 @@ public void end() {

@Override
public JsonElement toJsonElement() {
SimpleDateFormat simpleDateFormat = getSimpleDateFormat();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("name", name);
jsonObject.addProperty("start", getStartString());
jsonObject.addProperty("end", getEndString());
jsonObject.addProperty("start", getStartString(simpleDateFormat));
jsonObject.addProperty("end", getEndString(simpleDateFormat));
jsonObject.addProperty("duration", getDurationString());

return jsonObject;
}

private String getStartString() {
private String getStartString(SimpleDateFormat simpleDateFormat) {
if (startMS == 0) {
return "N/A";
}
return DATE_FORMAT.format(startMS);
return simpleDateFormat.format(startMS);
}

private String getEndString() {
private String getEndString(SimpleDateFormat simpleDateFormat) {
if (endMS == 0) {
return "N/A";
}
return DATE_FORMAT.format(endMS);
return simpleDateFormat.format(endMS);
}

private String getDurationString() {
Expand Down