Search in sources :

Example 1 with TypeProfileEntry

use of com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry 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);
}
Also used : Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) JSONObject(org.json.JSONObject) Collection(java.util.Collection) TypeProfileEntry(com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry)

Aggregations

Source (com.oracle.truffle.api.source.Source)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 Script (com.oracle.truffle.tools.chromeinspector.types.Script)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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1