Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple async-profiler library deployments #173

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public static AsyncProfiler getAsyncProfiler() {
private static String deployLibrary() throws IOException {
final String fileName = libraryFileName();
final String userName = System.getProperty("user.name");
final String tmpDir = System.getProperty("java.io.tmpdir");
final File targetDir = new File(tmpDir, userName + "-pyroscope/");
targetDir.mkdirs();
final Path targetDir = Files.createTempDirectory( userName + "-pyroscope");

try (final InputStream is = loadResource(fileName)) {
final Path target = targetDir.toPath().resolve(targetLibraryFileName(fileName)).toAbsolutePath();
final Path target = targetDir.resolve(targetLibraryFileName(fileName)).toAbsolutePath();
Files.copy(is, target, StandardCopyOption.REPLACE_EXISTING);
return target.toString();
}
Expand Down
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);
}
});
}
}

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
);
}
}
Loading