-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProfilerApi for consumption by other libraries
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
agent/src/main/java/io/pyroscope/javaagent/ProfilerSdk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.pyroscope.javaagent; | ||
|
||
import io.pyroscope.javaagent.api.ProfilerScopedContext; | ||
import io.pyroscope.javaagent.api.ProfilerApi; | ||
import io.pyroscope.javaagent.config.Config; | ||
import io.pyroscope.javaagent.impl.ProfilerScopedContextWrapper; | ||
import io.pyroscope.labels.LabelsSet; | ||
import io.pyroscope.labels.ScopedContext; | ||
|
||
import java.util.Map; | ||
|
||
public class ProfilerSdk implements ProfilerApi { | ||
|
||
@Override | ||
public void startProfiling() { | ||
PyroscopeAgent.start(Config.build()); | ||
} | ||
|
||
@Override | ||
public boolean isProfilingStarted() { | ||
return PyroscopeAgent.isStarted(); | ||
} | ||
|
||
@Override | ||
public ProfilerScopedContext createScopedContext(Map<String, String> labels) { | ||
return new ProfilerScopedContextWrapper(new ScopedContext(new LabelsSet(labels))); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
agent/src/main/java/io/pyroscope/javaagent/api/ProfilerApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.pyroscope.javaagent.api; | ||
|
||
import java.util.Map; | ||
|
||
public interface ProfilerApi { | ||
void startProfiling(); | ||
boolean isProfilingStarted(); | ||
ProfilerScopedContext createScopedContext(Map<String, String> labels); | ||
} |
8 changes: 8 additions & 0 deletions
8
agent/src/main/java/io/pyroscope/javaagent/api/ProfilerScopedContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.pyroscope.javaagent.api; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public interface ProfilerScopedContext { | ||
void forEachLabel(BiConsumer<String, String> consumer); | ||
void close(); | ||
} |
24 changes: 24 additions & 0 deletions
24
agent/src/main/java/io/pyroscope/javaagent/impl/ProfilerScopedContextWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.pyroscope.javaagent.impl; | ||
|
||
import io.pyroscope.javaagent.api.ProfilerScopedContext; | ||
import io.pyroscope.labels.ScopedContext; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public class ProfilerScopedContextWrapper implements ProfilerScopedContext { | ||
private final ScopedContext ctx; | ||
|
||
public ProfilerScopedContextWrapper(ScopedContext ctx) { | ||
this.ctx = ctx; | ||
} | ||
|
||
@Override | ||
public void forEachLabel(BiConsumer<String, String> consumer) { | ||
ctx.forEachLabel(consumer); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
ctx.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters