-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from grafana/patch/multiple-library-deployments
Prevent multiple async-profiler library deployments
- Loading branch information
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
async-profiler-context/src/test/java/io/pyroscope/ConcurrentUsageTest.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,36 @@ | ||
package io.pyroscope; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ConcurrentUsageTest { | ||
|
||
@Test | ||
public void runConcurrently() throws IOException { | ||
int iterations = 10; | ||
List<Process> processes = new ArrayList<>(); | ||
for (int i = 0; i < iterations; i++) { | ||
Process process = new ProcessBuilder( | ||
"java", "-cp", System.getProperty("java.class.path"), TestApplication.class.getName() | ||
).inheritIO().start(); | ||
processes.add(process); | ||
} | ||
|
||
processes.parallelStream().forEach(p -> { | ||
int exitCode = 0; | ||
try { | ||
exitCode = p.waitFor(); | ||
} catch (InterruptedException e) { | ||
Assertions.fail("could not get process status", e); | ||
} | ||
if (exitCode != 0) { | ||
Assertions.fail("process failed with exit code: " + exitCode); | ||
} | ||
}); | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
async-profiler-context/src/test/java/io/pyroscope/TestApplication.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,26 @@ | ||
package io.pyroscope; | ||
|
||
import io.pyroscope.labels.io.pyroscope.PyroscopeAsyncProfiler; | ||
import one.profiler.AsyncProfiler; | ||
import one.profiler.Counter; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class TestApplication { | ||
|
||
public static void main(String[] args) { | ||
AsyncProfiler asyncProfiler = PyroscopeAsyncProfiler.getAsyncProfiler(); | ||
asyncProfiler.start("cpu", TimeUnit.SECONDS.toNanos(1)); | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
System.exit(1); | ||
} | ||
asyncProfiler.stop(); | ||
|
||
System.out.println( | ||
asyncProfiler + "-" + | ||
asyncProfiler.dumpCollapsed(Counter.SAMPLES).split(";").length | ||
); | ||
} | ||
} |