Skip to content

Commit cb6a8e1

Browse files
committed
refactored code to reduce overhead
1 parent 2f4ee07 commit cb6a8e1

File tree

70 files changed

+36
-2113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+36
-2113
lines changed

Kotlin-Coroutines_1.2/src/main/java/com/nr/instrumentation/kotlin/coroutines/NRWrappedRunnable.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

Kotlin-Coroutines_1.2/src/main/java/kotlin/coroutines/jvm/internal/BaseContinuationImpl.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
@Weave(type=MatchType.BaseClass)
1010
public abstract class BaseContinuationImpl {
11-
12-
11+
12+
1313
@Trace
1414
public void resumeWith(Object obj) {
1515
String name = null;
@@ -23,5 +23,17 @@ public void resumeWith(Object obj) {
2323
Weaver.callOriginal();
2424
}
2525

26+
@Trace
27+
protected Object invokeSuspend(Object obj) {
28+
String name = null;
29+
StackTraceElement element = getStackTraceElement();
30+
if (element != null)
31+
name = element.getClassName() + "." + element.getMethodName();
32+
if (name != null)
33+
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] { "Custom", "Continuation", name, "invokeSuspend" });
34+
return Weaver.callOriginal();
35+
}
36+
37+
2638
public abstract StackTraceElement getStackTraceElement();
2739
}
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package kotlinx.coroutines;
22

33
import com.newrelic.api.agent.NewRelic;
4-
import com.newrelic.api.agent.Token;
54
import com.newrelic.api.agent.Trace;
65
import com.newrelic.api.agent.weaver.MatchType;
7-
import com.newrelic.api.agent.weaver.NewField;
86
import com.newrelic.api.agent.weaver.Weave;
97
import com.newrelic.api.agent.weaver.Weaver;
108

@@ -22,65 +20,48 @@ public AbstractCoroutine(CoroutineContext ctx, boolean active) {
2220

2321
public abstract String nameString$kotlinx_coroutines_core();
2422

25-
@NewField
26-
private Token token = null;
27-
28-
@Trace(async=true)
23+
@Trace
2924
public final void resumeWith(Object obj) {
3025
String name = nameString$kotlinx_coroutines_core();
3126
if(name != null && !name.isEmpty()) {
3227
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Coroutine",name,"resumeWith"});
3328
}
34-
if(token != null) {
35-
token.linkAndExpire();
36-
token = null;
37-
}
3829
Weaver.callOriginal();
3930
}
4031

41-
@Trace(dispatcher=true)
32+
@Trace
4233
public final void start(CoroutineStart start, Function1<? super Continuation<? super T>, ? extends Object> f) {
4334
String name = nameString$kotlinx_coroutines_core();
4435
if(name != null && !name.isEmpty()) {
4536
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Coroutine",name,"start"});
4637
}
47-
// token = NewRelic.getAgent().getTransaction().getToken();
4838
Weaver.callOriginal();
4939
}
5040

51-
@Trace(dispatcher=true)
41+
@Trace
5242
public final <R> void start(CoroutineStart start, R r, Function2<? super R, ? super Continuation<? super T>, ? extends Object> f) {
5343
String name = nameString$kotlinx_coroutines_core();
5444
if(name != null && !name.isEmpty()) {
5545
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Coroutine",name,"start"});
5646
}
57-
// token = NewRelic.getAgent().getTransaction().getToken();
5847
Weaver.callOriginal();
5948
}
6049

61-
@Trace(async=true)
50+
@Trace
6251
protected void onCompleted(T t) {
6352
String name = nameString$kotlinx_coroutines_core();
6453
if(name != null && !name.isEmpty()) {
6554
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Coroutine",name,"onCompleted"});
6655
}
67-
if(token != null) {
68-
token.linkAndExpire();
69-
token = null;
70-
}
7156
Weaver.callOriginal();
7257
}
7358

74-
@Trace(async=true)
59+
@Trace
7560
public void handleOnCompletionException$kotlinx_coroutines_core(java.lang.Throwable t) {
7661
String name = nameString$kotlinx_coroutines_core();
7762
if(name != null && !name.isEmpty()) {
7863
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Coroutine",name,"handleOnCompletionException"});
7964
}
80-
if(token != null) {
81-
token.linkAndExpire();
82-
token = null;
83-
}
8465
Weaver.callOriginal();
8566
}
8667
}

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/CancelHandlerBase.java

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package kotlinx.coroutines;
22

3+
import com.newrelic.api.agent.NewRelic;
34
import com.newrelic.api.agent.Trace;
45
import com.newrelic.api.agent.weaver.MatchType;
56
import com.newrelic.api.agent.weaver.Weave;
7+
import com.newrelic.api.agent.weaver.Weaver;
68

79
@Weave(type=MatchType.BaseClass)
810
public abstract class CompletionHandlerBase {
911

1012
@Trace
11-
public abstract void invoke(Throwable t);
13+
public void invoke(Throwable t) {
14+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","CompletionHandler",getClass().getSimpleName(),"invoke");
15+
if(t != null) {
16+
NewRelic.noticeError(t);
17+
}
18+
Weaver.callOriginal();
19+
}
1220
}

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/CoroutineDispatcher.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/EventLoopImplBase.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/Job.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010

1111
import kotlin.Unit;
1212
import kotlin.coroutines.Continuation;
13-
import kotlin.jvm.functions.Function1;
1413

1514
@Weave(type=MatchType.Interface)
1615
public abstract class Job {
1716

1817
@Trace
1918
public void cancel(CancellationException e) {
20-
NewRelic.noticeError(e);
19+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Job",getClass().getSimpleName(),"cancel");
20+
if(e != null) {
21+
NewRelic.noticeError(e);
22+
}
2123
Weaver.callOriginal();
2224
}
2325

2426
@Trace
25-
public abstract Object join(Continuation<? super Unit> c);
26-
27-
@Trace
28-
public abstract DisposableHandle invokeOnCompletion(Function1<? super Throwable, kotlin.Unit> f);
27+
public Object join(Continuation<? super Unit> c) {
28+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Job",getClass().getSimpleName(),"join");
29+
return Weaver.callOriginal();
30+
}
2931

30-
@Trace
31-
public abstract DisposableHandle invokeOnCompletion(boolean b1, boolean b2, Function1<? super Throwable, Unit> f);
32-
3332
}

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/intrinsics/CancellableKt.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

Kotlin-Coroutines_1.2/src/main/java/kotlinx/coroutines/intrinsics/UndispatchedKt.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)