use of com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile in project graal by oracle.
the class TruffleProfiler method getTypeProfile.
private Params getTypeProfile(Collection<TypeHandler.SectionTypeProfile> profiles) {
JSONObject json = new JSONObject();
Map<Source, Collection<TypeHandler.SectionTypeProfile>> sourceToProfiles = new HashMap<>();
profiles.forEach(profile -> {
Collection<TypeHandler.SectionTypeProfile> pfs = sourceToProfiles.computeIfAbsent(profile.getSourceSection().getSource(), t -> new LinkedList<>());
pfs.add(profile);
});
JSONArray result = new JSONArray();
sourceToProfiles.entrySet().forEach(entry -> {
List<TypeProfileEntry> entries = new ArrayList<>();
entry.getValue().forEach(sectionProfile -> {
List<TypeObject> types = new ArrayList<>();
sectionProfile.getTypes().forEach(type -> {
types.add(new TypeObject(type));
});
if (!types.isEmpty()) {
entries.add(new TypeProfileEntry(sectionProfile.getSourceSection().getCharEndIndex(), types.toArray(new TypeObject[types.size()])));
}
});
int scriptId = slh.getScriptId(entry.getKey());
Script script = scriptId < 0 ? null : slh.getScript(scriptId);
result.put(new ScriptTypeProfile(script != null ? script.getId() : 0, script != null ? script.getUrl() : "", entries.toArray(new TypeProfileEntry[entries.size()])).toJSON());
});
json.put("result", result);
return new Params(json);
}
Aggregations