Skip to content

Commit b656478

Browse files
Track the perf of stackTrace dap request (#496)
1 parent 6f5a9b3 commit b656478

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StackTraceRequestHandler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apache.commons.lang3.StringUtils;
2626

27+
import com.google.gson.JsonObject;
2728
import com.microsoft.java.debug.core.AsyncJdwpUtils;
2829
import com.microsoft.java.debug.core.DebugSettings;
2930
import com.microsoft.java.debug.core.DebugUtility;
@@ -41,6 +42,7 @@
4142
import com.microsoft.java.debug.core.protocol.Requests.StackTraceArguments;
4243
import com.microsoft.java.debug.core.protocol.Responses;
4344
import com.microsoft.java.debug.core.protocol.Types;
45+
import com.microsoft.java.debug.core.protocol.Events.TelemetryEvent;
4446
import com.sun.jdi.AbsentInformationException;
4547
import com.sun.jdi.IncompatibleThreadStateException;
4648
import com.sun.jdi.LocalVariable;
@@ -54,6 +56,7 @@
5456
import com.sun.jdi.request.BreakpointRequest;
5557

5658
public class StackTraceRequestHandler implements IDebugRequestHandler {
59+
private ThreadLocal<Boolean> isDecompilerInvoked = new ThreadLocal<>();
5760

5861
@Override
5962
public List<Command> getTargetCommands() {
@@ -62,6 +65,8 @@ public List<Command> getTargetCommands() {
6265

6366
@Override
6467
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
68+
final long startAt = System.currentTimeMillis();
69+
isDecompilerInvoked.set(false);
6570
StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments;
6671
List<Types.StackFrame> result = new ArrayList<>();
6772
if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) {
@@ -108,6 +113,15 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
108113
}
109114
}
110115
response.body = new Responses.StackTraceResponseBody(result, totalFrames);
116+
long duration = System.currentTimeMillis() - startAt;
117+
JsonObject properties = new JsonObject();
118+
properties.addProperty("command", "stackTrace");
119+
properties.addProperty("duration", duration);
120+
properties.addProperty("decompileSupport", DebugSettings.getCurrent().debugSupportOnDecompiledSource.toString());
121+
if (isDecompilerInvoked.get() != null) {
122+
properties.addProperty("isDecompilerInvoked", Boolean.toString(isDecompilerInvoked.get()));
123+
}
124+
context.getProtocolServer().sendEvent(new TelemetryEvent("dap", properties));
111125
return CompletableFuture.completedFuture(response);
112126
}
113127

@@ -198,6 +212,7 @@ private Types.StackFrame convertDebuggerStackFrameToClient(StackFrameInfo jdiFra
198212
int[] renderLines = AdapterUtils.binarySearchMappedLines(lineMappings, clientLineNumber);
199213
if (renderLines != null && renderLines.length > 0) {
200214
clientLineNumber = renderLines[0];
215+
isDecompilerInvoked.set(true);
201216
}
202217
}
203218

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/protocol/Events.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ public UserNotificationEvent(NotificationType notifyType, String message) {
246246
}
247247
}
248248

249+
public static class TelemetryEvent extends DebugEvent {
250+
/**
251+
* The telemetry event name.
252+
*/
253+
public String name;
254+
255+
/**
256+
* The properties is an object as below.
257+
* {
258+
* [key: string]: string | number;
259+
* }
260+
*/
261+
public Object properties;
262+
263+
/**
264+
* Constructor.
265+
*/
266+
public TelemetryEvent(String name, Object data) {
267+
super("telemetry");
268+
this.name = name;
269+
this.properties = data;
270+
}
271+
}
272+
249273
public static enum InvalidatedAreas {
250274
@SerializedName("all")
251275
ALL,

0 commit comments

Comments
 (0)