Skip to content

Commit ae93fa0

Browse files
authored
debugger paused resume events (#181)
1 parent 6188dc7 commit ae93fa0

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.digma.intellij.plugin.analytics;
22

3+
import org.digma.intellij.plugin.model.rest.debugger.DebuggerEventRequest;
34
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
45
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
56
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
@@ -18,6 +19,8 @@ public interface AnalyticsProvider extends Closeable {
1819

1920
List<String> getEnvironments();
2021

22+
void sendDebuggerEvent(DebuggerEventRequest debuggerEventRequest);
23+
2124
List<CodeObjectSummary> getSummaries(CodeObjectSummaryRequest summaryRequest);
2225

2326
List<CodeObjectInsight> getInsights(InsightsRequest insightsRequest);

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/RestAnalyticsProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import okhttp3.OkHttpClient;
77
import okhttp3.Request;
88
import okhttp3.ResponseBody;
9+
import org.digma.intellij.plugin.model.rest.debugger.DebuggerEventRequest;
910
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
1011
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
1112
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
@@ -54,6 +55,10 @@ public List<String> getEnvironments() {
5455
}
5556

5657

58+
public void sendDebuggerEvent(DebuggerEventRequest debuggerEventRequest){
59+
execute(() -> client.analyticsProvider.sendDebuggerEvent(debuggerEventRequest));
60+
}
61+
5762
public List<CodeObjectSummary> getSummaries(CodeObjectSummaryRequest summaryRequest) {
5863
return execute(() -> client.analyticsProvider.getSummaries(summaryRequest));
5964
}
@@ -246,6 +251,13 @@ public boolean verify(String s, SSLSession sslSession) {
246251
//both have the same methods with different return type.
247252
private interface AnalyticsProviderRetrofit {
248253

254+
@Headers({
255+
"Accept: application/+json",
256+
"Content-Type:application/json"
257+
})
258+
@POST("/CodeAnalytics/instrumentation/event")
259+
Call<Void> sendDebuggerEvent(@Body DebuggerEventRequest debuggerEventRequest);
260+
249261

250262
@Headers({
251263
"Accept: application/+json",

ide-common/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.intellij.ui.JBColor;
88
import org.apache.commons.lang3.time.StopWatch;
99
import org.digma.intellij.plugin.common.Backgroundable;
10+
import org.digma.intellij.plugin.common.CommonUtils;
1011
import org.digma.intellij.plugin.log.Log;
12+
import org.digma.intellij.plugin.model.rest.debugger.DebuggerEventRequest;
1113
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
1214
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
1315
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
@@ -152,6 +154,14 @@ private String getCurrentEnvironment() throws AnalyticsServiceException {
152154
}
153155

154156

157+
public void sendDebuggerEvent(int eventType) throws AnalyticsServiceException {
158+
executeCatching(() -> {
159+
analyticsProviderProxy.sendDebuggerEvent(new DebuggerEventRequest(String.valueOf(eventType), CommonUtils.getLocalHostname(), String.valueOf(System.currentTimeMillis())));
160+
return null;
161+
});
162+
}
163+
164+
155165
public List<CodeObjectSummary> getSummaries(List<String> objectIds) throws AnalyticsServiceException {
156166
var env = getCurrentEnvironment();
157167
return executeCatching(() -> analyticsProviderProxy.getSummaries(new CodeObjectSummaryRequest(env, objectIds)));
@@ -230,6 +240,8 @@ private AnalyticsProvider newAnalyticsProviderProxy(AnalyticsProvider obj) {
230240
}
231241

232242

243+
244+
233245
/**
234246
* A proxy for cross-cutting concerns across all api methods.
235247
* In a proxy it's easier to log events, we have the method name, parameters etc.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.digma.intellij.plugin.debugger
2+
3+
import com.intellij.openapi.project.Project
4+
import com.intellij.xdebugger.XDebugSession
5+
import com.intellij.xdebugger.XDebuggerManagerListener
6+
7+
class DebuggerListener(private val project: Project): XDebuggerManagerListener {
8+
9+
private var currentSessionListener: SessionListener? = null
10+
11+
override fun currentSessionChanged(previousSession: XDebugSession?, currentSession: XDebugSession?) {
12+
13+
//if debugger paused on breakpoint and user kills the debug session without resuming then
14+
//sessionResumed will not be called. here we track the state of SessionListener,
15+
//if it was paused but never resumed and now the debug session changed then call sessionResumed.
16+
//on session start isPaused will return false
17+
currentSessionListener?.let {
18+
if (it.isPaused()){
19+
it.sessionResumed()
20+
}
21+
}
22+
23+
currentSessionListener?.let {
24+
previousSession?.removeSessionListener(it)
25+
}
26+
27+
28+
currentSession?.let {
29+
currentSessionListener = SessionListener(project)
30+
it.addSessionListener(currentSessionListener!!)
31+
}
32+
}
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.digma.intellij.plugin.debugger
2+
3+
import com.intellij.openapi.diagnostic.Logger
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.xdebugger.XDebugSessionListener
6+
import org.digma.intellij.plugin.analytics.AnalyticsService
7+
import org.digma.intellij.plugin.log.Log
8+
9+
class SessionListener(project: Project) : XDebugSessionListener {
10+
11+
private val logger: Logger = Logger.getInstance(SessionListener::class.java)
12+
13+
private val analyticsService = project.getService(AnalyticsService::class.java)
14+
15+
private var paused = false
16+
17+
fun isPaused():Boolean{
18+
return paused
19+
}
20+
21+
override fun sessionPaused() {
22+
paused = true
23+
try {
24+
analyticsService.sendDebuggerEvent(0)
25+
}catch (e:Exception){
26+
Log.log(logger::debug, "exception calling sendDebuggerEvent {}. ", e.message)
27+
}
28+
}
29+
30+
override fun sessionResumed() {
31+
paused = false
32+
try {
33+
analyticsService.sendDebuggerEvent(1)
34+
}catch (e:Exception){
35+
Log.log(logger::debug, "exception calling sendDebuggerEvent {}. ", e.message)
36+
}
37+
}
38+
39+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.digma.intellij.plugin.model.rest.debugger
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
5+
data class DebuggerEventRequest
6+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
7+
constructor(val event: String, val machineName: String,val timestamp: String)

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
<listener
9595
class="org.digma.intellij.plugin.emvironment.EnvironmentChangeHandler"
9696
topic="org.digma.intellij.plugin.analytics.EnvironmentChanged"/>
97+
<listener class="org.digma.intellij.plugin.debugger.DebuggerListener"
98+
topic="com.intellij.xdebugger.XDebuggerManagerListener"/>
9799
</projectListeners>
98100

99101

0 commit comments

Comments
 (0)