Search in sources :

Example 1 with ScriptCoverage

use of com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage in project graal by oracle.

the class TruffleProfiler method getCoverage.

private Params getCoverage(Collection<CPUTracer.Payload> payloads) {
    JSONObject json = new JSONObject();
    Map<Source, Map<String, Collection<CPUTracer.Payload>>> sourceToRoots = new HashMap<>();
    payloads.forEach(payload -> {
        Map<String, Collection<CPUTracer.Payload>> rootsToPayloads = sourceToRoots.computeIfAbsent(payload.getSourceSection().getSource(), s -> new LinkedHashMap<>());
        Collection<CPUTracer.Payload> pls = rootsToPayloads.computeIfAbsent(payload.getRootName(), t -> new LinkedList<>());
        pls.add(payload);
    });
    JSONArray result = new JSONArray();
    sourceToRoots.entrySet().stream().map(sourceEntry -> {
        List<FunctionCoverage> functions = new ArrayList<>();
        sourceEntry.getValue().entrySet().forEach(rootEntry -> {
            boolean isBlockCoverage = false;
            List<CoverageRange> ranges = new ArrayList<>();
            for (CPUTracer.Payload payload : rootEntry.getValue()) {
                isBlockCoverage |= payload.getTags().contains(StandardTags.StatementTag.class);
                ranges.add(new CoverageRange(payload.getSourceSection().getCharIndex(), payload.getSourceSection().getCharEndIndex(), payload.getCount()));
            }
            functions.add(new FunctionCoverage(rootEntry.getKey(), isBlockCoverage, ranges.toArray(new CoverageRange[ranges.size()])));
        });
        int scriptId = slh.getScriptId(sourceEntry.getKey());
        Script script = scriptId < 0 ? null : slh.getScript(scriptId);
        return new ScriptCoverage(script != null ? script.getId() : 0, script != null ? script.getUrl() : "", functions.toArray(new FunctionCoverage[functions.size()]));
    }).forEachOrdered(scriptCoverage -> {
        result.put(scriptCoverage.toJSON());
    });
    json.put("result", result);
    return new Params(json);
}
Also used : ProfileNode(com.oracle.truffle.tools.chromeinspector.types.ProfileNode) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) TypeProfileInstrument(com.oracle.truffle.tools.chromeinspector.instrument.TypeProfileInstrument) CoverageRange(com.oracle.truffle.tools.chromeinspector.types.CoverageRange) Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Enabler(com.oracle.truffle.tools.chromeinspector.instrument.Enabler) TypeProfileEntry(com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) Map(java.util.Map) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) CPUTracer(com.oracle.truffle.tools.profiler.CPUTracer) SourceSection(com.oracle.truffle.api.source.SourceSection) LinkedList(java.util.LinkedList) ProfilerDomain(com.oracle.truffle.tools.chromeinspector.domains.ProfilerDomain) RuntimeCallFrame(com.oracle.truffle.tools.chromeinspector.types.RuntimeCallFrame) Profile(com.oracle.truffle.tools.chromeinspector.types.Profile) Collection(java.util.Collection) ProfilerNode(com.oracle.truffle.tools.profiler.ProfilerNode) InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Source(com.oracle.truffle.api.source.Source) CPUSamplerInstrument(com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) Collections(java.util.Collections) JSONArray(org.json.JSONArray) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) CPUTracerInstrument(com.oracle.truffle.tools.profiler.impl.CPUTracerInstrument) Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) JSONObject(org.json.JSONObject) CPUTracer(com.oracle.truffle.tools.profiler.CPUTracer) CoverageRange(com.oracle.truffle.tools.chromeinspector.types.CoverageRange) Collection(java.util.Collection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

InstrumentInfo (com.oracle.truffle.api.InstrumentInfo)1 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)1 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)1 Source (com.oracle.truffle.api.source.Source)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 ProfilerDomain (com.oracle.truffle.tools.chromeinspector.domains.ProfilerDomain)1 Enabler (com.oracle.truffle.tools.chromeinspector.instrument.Enabler)1 TypeProfileInstrument (com.oracle.truffle.tools.chromeinspector.instrument.TypeProfileInstrument)1 CoverageRange (com.oracle.truffle.tools.chromeinspector.types.CoverageRange)1 FunctionCoverage (com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage)1 Profile (com.oracle.truffle.tools.chromeinspector.types.Profile)1 ProfileNode (com.oracle.truffle.tools.chromeinspector.types.ProfileNode)1 RuntimeCallFrame (com.oracle.truffle.tools.chromeinspector.types.RuntimeCallFrame)1 Script (com.oracle.truffle.tools.chromeinspector.types.Script)1 ScriptCoverage (com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage)1 ScriptTypeProfile (com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile)1 TypeObject (com.oracle.truffle.tools.chromeinspector.types.TypeObject)1 TypeProfileEntry (com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry)1 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)1