Search in sources :

Example 1 with CPUSamplerData

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;
}
Also used : CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) TruffleContext(com.oracle.truffle.api.TruffleContext) Params(com.oracle.truffle.tools.chromeinspector.commands.Params)

Example 2 with CPUSamplerData

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);
}
Also used : CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray)

Example 3 with CPUSamplerData

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());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) TruffleContext(com.oracle.truffle.api.TruffleContext) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 4 with CPUSamplerData

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());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) TruffleContext(com.oracle.truffle.api.TruffleContext) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 5 with CPUSamplerData

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;
}
Also used : CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) ProfilerNode(com.oracle.truffle.tools.profiler.ProfilerNode) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Payload(com.oracle.truffle.tools.profiler.CPUSampler.Payload)

Aggregations

CPUSamplerData (com.oracle.truffle.tools.profiler.CPUSamplerData)9 TruffleContext (com.oracle.truffle.api.TruffleContext)7 Test (org.junit.Test)5 ProfilerNode (com.oracle.truffle.tools.profiler.ProfilerNode)3 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)2 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)2 Payload (com.oracle.truffle.tools.profiler.CPUSampler.Payload)2 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)2 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)2 Collection (java.util.Collection)2 Context (org.graalvm.polyglot.Context)2 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 OptionValues (org.graalvm.options.OptionValues)1 Source (org.graalvm.polyglot.Source)1