Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
1. change System.currentTimeMillis() to System.nanoTime();
2. modify addCount()
  • Loading branch information
DanGuge committed Aug 11, 2023
1 parent 262ae05 commit 793ead8
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,25 @@

public class API {

protected static final Logger LOG = Log.logger(API.class);

public static final String CHARSET = "UTF-8";

public static final String TEXT_PLAIN = MediaType.TEXT_PLAIN;
public static final String APPLICATION_JSON = MediaType.APPLICATION_JSON;
public static final String APPLICATION_JSON_WITH_CHARSET =
APPLICATION_JSON + ";charset=" + CHARSET;
APPLICATION_JSON + ";charset=" + CHARSET;
public static final String JSON = MediaType.APPLICATION_JSON_TYPE
.getSubtype();

.getSubtype();
public static final String ACTION_APPEND = "append";
public static final String ACTION_ELIMINATE = "eliminate";
public static final String ACTION_CLEAR = "clear";

protected static final Logger LOG = Log.logger(API.class);
private static final Meter SUCCEED_METER =
MetricsUtil.registerMeter(API.class, "commit-succeed");
MetricsUtil.registerMeter(API.class, "commit-succeed");
private static final Meter ILLEGAL_ARG_ERROR_METER =
MetricsUtil.registerMeter(API.class, "illegal-arg");
MetricsUtil.registerMeter(API.class, "illegal-arg");
private static final Meter EXPECTED_ERROR_METER =
MetricsUtil.registerMeter(API.class, "expected-error");
MetricsUtil.registerMeter(API.class, "expected-error");
private static final Meter UNKNOWN_ERROR_METER =
MetricsUtil.registerMeter(API.class, "unknown-error");
MetricsUtil.registerMeter(API.class, "unknown-error");

public static HugeGraph graph(GraphManager manager, String graph) {
HugeGraph g = manager.graph(graph);
Expand Down Expand Up @@ -193,17 +189,17 @@ public static class ApiMeasurer {

public static final String EDGE_ITER = "edge_iterations";
public static final String VERTICE_ITER = "vertice_iterations";
public static final String COST = "cost";
public static final String COST = "cost(ns)";
private final long timeStart;
private final Map<String, Object> measures;

public ApiMeasurer() {
this.timeStart = System.currentTimeMillis();
this.timeStart = System.nanoTime();
this.measures = InsertionOrderUtil.newMap();
}

public Map<String, Object> measures() {
measures.put(COST, System.currentTimeMillis() - timeStart);
measures.put(COST, System.nanoTime() - timeStart);
return measures;
}

Expand All @@ -224,8 +220,7 @@ protected void addCount(String key, long value) {
if (current == null) {
measures.put(key, new MutableLong(value));
} else if (current instanceof MutableLong) {
MutableLong currentMutableLong = (MutableLong) current;
currentMutableLong.add(value);
((MutableLong) measures.computeIfAbsent(key, MutableLong::new)).add(value);
} else if (current instanceof Long) {
Long currentLong = (Long) current;
measures.put(key, new MutableLong(currentLong + value));

Check warning on line 226 in hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java#L225-L226

Added lines #L225 - L226 were not covered by tests
Expand Down

0 comments on commit 793ead8

Please sign in to comment.