File tree 5 files changed +71
-3
lines changed
agent/src/main/java/io/pyroscope/javaagent
async-profiler-context/src/main/java/io/pyroscope/labels
5 files changed +71
-3
lines changed Original file line number Diff line number Diff line change
1
+ package io .pyroscope .javaagent ;
2
+
3
+ import io .pyroscope .javaagent .api .ProfilerScopedContext ;
4
+ import io .pyroscope .javaagent .api .ProfilerApi ;
5
+ import io .pyroscope .javaagent .config .Config ;
6
+ import io .pyroscope .javaagent .impl .ProfilerScopedContextWrapper ;
7
+ import io .pyroscope .labels .LabelsSet ;
8
+ import io .pyroscope .labels .ScopedContext ;
9
+
10
+ import java .util .Map ;
11
+
12
+ public class ProfilerSdk implements ProfilerApi {
13
+
14
+ @ Override
15
+ public void startProfiling () {
16
+ PyroscopeAgent .start (Config .build ());
17
+ }
18
+
19
+ @ Override
20
+ public boolean isProfilingStarted () {
21
+ return PyroscopeAgent .isStarted ();
22
+ }
23
+
24
+ @ Override
25
+ public ProfilerScopedContext createScopedContext (Map <String , String > labels ) {
26
+ return new ProfilerScopedContextWrapper (new ScopedContext (new LabelsSet (labels )));
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package io .pyroscope .javaagent .api ;
2
+
3
+ import java .util .Map ;
4
+
5
+ public interface ProfilerApi {
6
+ void startProfiling ();
7
+ boolean isProfilingStarted ();
8
+ ProfilerScopedContext createScopedContext (Map <String , String > labels );
9
+ }
Original file line number Diff line number Diff line change
1
+ package io .pyroscope .javaagent .api ;
2
+
3
+ import java .util .function .BiConsumer ;
4
+
5
+ public interface ProfilerScopedContext {
6
+ void forEachLabel (BiConsumer <String , String > consumer );
7
+ void close ();
8
+ }
Original file line number Diff line number Diff line change
1
+ package io .pyroscope .javaagent .impl ;
2
+
3
+ import io .pyroscope .javaagent .api .ProfilerScopedContext ;
4
+ import io .pyroscope .labels .ScopedContext ;
5
+
6
+ import java .util .function .BiConsumer ;
7
+
8
+ public class ProfilerScopedContextWrapper implements ProfilerScopedContext {
9
+ private final ScopedContext ctx ;
10
+
11
+ public ProfilerScopedContextWrapper (ScopedContext ctx ) {
12
+ this .ctx = ctx ;
13
+ }
14
+
15
+ @ Override
16
+ public void forEachLabel (BiConsumer <String , String > consumer ) {
17
+ ctx .forEachLabel (consumer );
18
+ }
19
+
20
+ @ Override
21
+ public void close () {
22
+ ctx .close ();
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ public ScopedContext(LabelsSet labels) {
61
61
context .set (current );
62
62
}
63
63
64
-
65
64
@ Override
66
65
public void close () {
67
66
if (closed ) {
@@ -73,9 +72,9 @@ public void close() {
73
72
AsyncProfiler .getInstance ().setContextId (previous .id );
74
73
}
75
74
76
- public void forEach (BiConsumer <String , String > consumer ) {
75
+ public void forEachLabel (BiConsumer <String , String > labelConsumer ) {
77
76
for (Map .Entry <Ref <String >, Ref <String >> it : current .labels .entrySet ()) {
78
- consumer .accept (it .getKey ().val , it .getValue ().val );
77
+ labelConsumer .accept (it .getKey ().val , it .getValue ().val );
79
78
}
80
79
}
81
80
You can’t perform that action at this time.
0 commit comments