Skip to content

Commit 0723ee0

Browse files
Provide an option to dump the DAP perf (#435)
* Provide an option to dump the DAP perf
1 parent fe77989 commit 0723ee0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/UsageDataSession.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Microsoft Corporation and others.
2+
* Copyright (c) 2017-2022 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
1212
package com.microsoft.java.debug.core;
1313

1414
import java.util.ArrayList;
15+
import java.util.Formatter;
1516
import java.util.HashMap;
1617
import java.util.List;
1718
import java.util.Map;
@@ -32,6 +33,7 @@ public class UsageDataSession {
3233
private static final Logger usageDataLogger = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME);
3334
private static final long RESPONSE_MAX_DELAY_MS = 1000;
3435
private static final ThreadLocal<UsageDataSession> threadLocal = new InheritableThreadLocal<>();
36+
private static final boolean TRACE_DAP_PERF = Boolean.getBoolean("debug.dap.perf");
3537

3638
private final String sessionGuid = UUID.randomUUID().toString();
3739
private boolean jdiEventSequenceEnabled = false;
@@ -43,6 +45,7 @@ public class UsageDataSession {
4345
private Map<String, Integer> userErrorCount = new HashMap<>();
4446
private Map<String, Integer> commandPerfCountMap = new HashMap<>();
4547
private List<String> eventList = new ArrayList<>();
48+
private List<String[]> dapPerf = new ArrayList<>();
4649

4750
public static String getSessionGuid() {
4851
return threadLocal.get() == null ? "" : threadLocal.get().sessionGuid;
@@ -117,6 +120,12 @@ public void recordResponse(Response response) {
117120
long duration = responseMillis - requestMillis;
118121
commandPerfCountMap.compute(command, (k, v) -> (v == null ? 0 : v.intValue()) + (int) duration);
119122

123+
if (TRACE_DAP_PERF) {
124+
synchronized (dapPerf) {
125+
dapPerf.add(new String[]{command, String.valueOf(duration)});
126+
}
127+
}
128+
120129
if (!response.success || duration > RESPONSE_MAX_DELAY_MS) {
121130
Map<String, Object> props = new HashMap<>();
122131
props.put("duration", duration);
@@ -148,6 +157,18 @@ public void submitUsageData() {
148157
}
149158
}
150159
usageDataLogger.log(Level.INFO, "session usage data summary", props);
160+
161+
if (TRACE_DAP_PERF) {
162+
Formatter fmt = new Formatter();
163+
fmt.format("\nDAP Performance Metrics:\n");
164+
fmt.format("%30s %10s(ms)\n", "Request", "Duration");
165+
synchronized (dapPerf) {
166+
dapPerf.forEach((event) -> {
167+
fmt.format("%30s %14s\n", event[0], event[1]);
168+
});
169+
}
170+
logger.info(String.valueOf(fmt));
171+
}
151172
}
152173

153174
/**

0 commit comments

Comments
 (0)