use of org.neo4j.resources.Profiler in project neo4j by neo4j.
the class ProfilerExtension method afterEach.
@Override
public void afterEach(ExtensionContext context) {
Profiler profiler = getStoredValue(context);
try {
profiler.finish();
if (context.getExecutionException().isPresent()) {
String displayName = "Profile: " + context.getTestClass().map(Class::getSimpleName).orElse("class") + "." + context.getDisplayName();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
profiler.printProfile(new PrintStream(buffer, false, StandardCharsets.UTF_8), displayName);
buffer.writeTo(System.err);
ExtensionContext.Store testDirStore = getStore(context, TestDirectorySupportExtension.TEST_DIRECTORY_NAMESPACE);
TestDirectory testDir = testDirStore.get(TestDirectorySupportExtension.TEST_DIRECTORY, TestDirectory.class);
if (testDir != null && testDir.isInitialised()) {
Path profileOutputFile = testDir.createFile("profiler-output.txt");
FileSystemAbstraction fs = testDir.getFileSystem();
try (OutputStream out = fs.openAsOutputStream(profileOutputFile, false)) {
buffer.writeTo(out);
}
}
}
} catch (Exception e) {
throw new JUnitException("Failed to finish profiling and/or produce profiling output.", e);
}
}
use of org.neo4j.resources.Profiler in project neo4j by neo4j.
the class CentralJobSchedulerTest method shouldProfileGroup.
@Timeout(value = 20, unit = SECONDS)
@Test
void shouldProfileGroup() throws InterruptedException {
life.start();
BinaryLatch checkpointLatch = new BinaryLatch();
scheduler.schedule(Group.CHECKPOINT, NOT_MONITORED, checkpointLatch::await);
Profiler profiler = Profiler.profiler();
scheduler.profileGroup(Group.CHECKPOINT, profiler);
String printedProfile;
do {
ByteArrayOutputStream bufferOut = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bufferOut);
profiler.printProfile(out, "Test Title");
out.flush();
printedProfile = bufferOut.toString();
} while (!printedProfile.contains("BinaryLatch.await"));
checkpointLatch.release();
profiler.finish();
}
Aggregations