Skip to content

Commit

Permalink
Enable jfr tests (async-profiler#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-soumadipta authored Sep 12, 2024
1 parent 25fa02e commit c122fde
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
17 changes: 17 additions & 0 deletions test/one/profiler/test/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import one.convert.Arguments;
import one.convert.FlameGraph;
import one.convert.JfrToFlame;
import one.jfr.JfrReader;

import java.io.*;
import java.util.Arrays;
Expand Down Expand Up @@ -69,6 +71,21 @@ public Output convertFlameToCollapsed() throws IOException {
}
}

public static Output convertJfrToCollapsed(String input, String... args) throws IOException {
JfrToFlame converter;
try (JfrReader jfr = new JfrReader(input)) {
Arguments arguments = new Arguments(args);
arguments.output = "collapsed";
converter = new JfrToFlame(jfr, arguments);
converter.convert();
}

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
converter.dump(outputStream);
return new Output(outputStream.toString("UTF-8").split(System.lineSeparator()));
}
}

public double ratio(String regex1, String regex2) {
long matched1 = samples(regex1);
long matched2 = samples(regex2);
Expand Down
2 changes: 1 addition & 1 deletion test/one/profiler/test/TestProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Output readFile(String fileId) {
File f = getFile(fileId);
try (Stream<String> stream = Files.lines(f.toPath())) {
return new Output(stream.toArray(String[]::new));
} catch (IOException e) {
} catch (IOException | UncheckedIOException e) {
return new Output(new String[0]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test/cpu/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Cache {
private volatile ValueWithTime[] top;

public Cache() {
executor.scheduleAtFixedRate(this::calculateTop, 0, 5, TimeUnit.SECONDS);
executor.scheduleAtFixedRate(this::calculateTop, 4, 4, TimeUnit.SECONDS);
}

public void put(Long key, String value) {
Expand Down
14 changes: 9 additions & 5 deletions test/test/cpu/CpuTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@

package test.cpu;

import one.profiler.test.Jvm;
import one.profiler.test.Output;
import one.profiler.test.Test;
import one.profiler.test.TestProcess;

public class CpuTests {

@Test(mainClass = RegularPeak.class, enabled = false, jvmArgs = "-XX:+UseG1GC -Xmx1g -Xms1g", jvm = Jvm.HOTSPOT)
@Test(mainClass = RegularPeak.class)
public void regularPeak(TestProcess p) throws Exception {
p.profile("-e cpu -d 3 -f %f.jfr");
Output out = p.readFile("%f");
assert out.contains("java/util/stream/SpinedBuffer\\.accept");
Output out = p.profile("-e cpu -d 6 -f %f.jfr");
String jfrOutPath = p.getFile("%f").getAbsolutePath();
out = Output.convertJfrToCollapsed(jfrOutPath, "--to", "2500");
assert !out.contains("test/cpu/Cache\\.lambda\\$calculateTop\\$1");
out = Output.convertJfrToCollapsed(jfrOutPath,"--from", "2500", "--to", "5000");
assert out.samples("test/cpu/Cache\\.lambda\\$calculateTop\\$1") >= 1;
out = Output.convertJfrToCollapsed(jfrOutPath,"--from", "5000");
assert !out.contains("test/cpu/Cache\\.lambda\\$calculateTop\\$1");
}
}

0 comments on commit c122fde

Please sign in to comment.