use of com.oracle.truffle.tools.profiler.CPUSamplerData in project graal by oracle.
the class InspectorProfiler method stop.
@Override
public Params stop() {
long time = System.currentTimeMillis();
Map<TruffleContext, CPUSamplerData> data;
long period;
synchronized (sampler) {
sampler.setCollecting(false);
sampler.setGatherSelfHitTimes(oldGatherSelfHitTimes);
data = sampler.getData();
sampler.clearData();
period = sampler.getPeriod();
}
long idleHitCount = (time - startTimestamp) / period - getSampleCount(data);
Params profile = getProfile(getRootNodes(data), idleHitCount, startTimestamp, time);
return profile;
}
use of com.oracle.truffle.tools.profiler.CPUSamplerData in project graal by oracle.
the class CPUSamplerCLI method printSamplingJson.
private static void printSamplingJson(PrintStream out, OptionValues options, Map<TruffleContext, CPUSamplerData> data) {
boolean gatheredHitTimes = options.get(GATHER_HIT_TIMES);
JSONObject output = new JSONObject();
output.put("tool", CPUSamplerInstrument.ID);
output.put("version", CPUSamplerInstrument.VERSION);
JSONArray contexts = new JSONArray();
for (CPUSamplerData samplerData : data.values()) {
contexts.put(perContextData(samplerData, gatheredHitTimes));
}
output.put("contexts", contexts);
out.println(output);
}
use of com.oracle.truffle.tools.profiler.CPUSamplerData in project graal by oracle.
the class CPUSamplerTest method testSampleContextInitialization.
@Test
public void testSampleContextInitialization() {
RootNode dummy = RootNode.createConstantNode(42);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void initializeContext(LanguageContext c) throws Exception {
for (int i = 0; i < 50; i++) {
Thread.sleep(1);
TruffleSafepoint.pollHere(dummy);
}
}
});
sampler.setPeriod(1);
sampler.setSampleContextInitialization(true);
sampler.setCollecting(true);
context.initialize(ProxyLanguage.ID);
sampler.setCollecting(false);
Map<TruffleContext, CPUSamplerData> data = sampler.getData();
assertEquals(1, data.size());
assertEquals(0, searchInitializeContext(data).size());
}
use of com.oracle.truffle.tools.profiler.CPUSamplerData in project graal by oracle.
the class CPUSamplerTest method testInitializeContext.
@Test
public void testInitializeContext() {
RootNode dummy = RootNode.createConstantNode(42);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void initializeContext(LanguageContext c) throws Exception {
for (int i = 0; i < 50; i++) {
Thread.sleep(1);
TruffleSafepoint.pollHere(dummy);
}
}
});
sampler.setPeriod(1);
sampler.clearData();
sampler.setCollecting(true);
context.initialize(ProxyLanguage.ID);
sampler.setCollecting(false);
Map<TruffleContext, CPUSamplerData> data = sampler.getData();
assertEquals(1, data.size());
assertEquals(0, searchInitializeContext(data).size());
}
use of com.oracle.truffle.tools.profiler.CPUSamplerData in project graal by oracle.
the class CPUSamplerTest method searchInitializeContext.
private static List<ProfilerNode<Payload>> searchInitializeContext(Map<TruffleContext, CPUSamplerData> data) {
List<ProfilerNode<Payload>> found = new ArrayList<>();
for (CPUSamplerData d : data.values()) {
Map<Thread, Collection<ProfilerNode<Payload>>> threadData = d.getThreadData();
assertEquals(threadData.toString(), 1, threadData.size());
searchNodes(found, threadData.values().iterator().next(), (node) -> {
return node.getRootName().equals("<<" + ProxyLanguage.ID + ":initializeContext>>");
});
}
return found;
}
Aggregations