use of com.oracle.truffle.tools.chromeinspector.types.CoverageRange 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);
}
Aggregations