Search in sources :

Example 11 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class InspectorProfiler method getCoverage.

private Params getCoverage(Collection<CPUTracer.Payload> payloads) {
    JSONObject json = new JSONObject();
    Map<Source, Map<String, Collection<CPUTracer.Payload>>> sourceToRoots = new LinkedHashMap<>();
    payloads.forEach(payload -> {
        SourceSection sourceSection = payload.getSourceSection();
        if (sourceSection != null) {
            Map<String, Collection<CPUTracer.Payload>> rootsToPayloads = sourceToRoots.computeIfAbsent(sourceSection.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()])));
        });
        Script script = slh.assureLoaded(sourceEntry.getKey());
        return new ScriptCoverage(script.getId(), 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) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Map(java.util.Map) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) CPUSamplerData(com.oracle.truffle.tools.profiler.CPUSamplerData) 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) TruffleContext(com.oracle.truffle.api.TruffleContext) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Source(com.oracle.truffle.api.source.Source) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) CPUSamplerInstrument(com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ConnectionWatcher(com.oracle.truffle.tools.chromeinspector.server.ConnectionWatcher) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) CPUTracerInstrument(com.oracle.truffle.tools.profiler.impl.CPUTracerInstrument) Script(com.oracle.truffle.tools.chromeinspector.types.Script) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) LinkedHashMap(java.util.LinkedHashMap) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) JSONObject(com.oracle.truffle.tools.utils.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) SourceSection(com.oracle.truffle.api.source.SourceSection) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class Params method createContext.

public static Params createContext(long id, String name) {
    JSONObject params = new JSONObject();
    JSONObject context = new JSONObject();
    context.put("id", id);
    context.put("name", name);
    context.put("origin", "");
    params.put("context", context);
    return new Params(params);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 13 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class Params method createContextId.

public static Params createContextId(long id) {
    JSONObject params = new JSONObject();
    params.put("executionContextId", id);
    return new Params(params);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 14 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class Result method toJSON.

public JSONObject toJSON(long id) {
    JSONObject json = new JSONObject();
    json.put("id", id);
    json.put("result", resultJSON);
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 15 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class GraalChannel method loadReleasesIndex.

/**
 * Loads the release index. Must be loaded from a local file.
 *
 * @param releasesIndexPath path to the downloaded releases index.
 * @return list of entries in the index
 * @throws IOException in case of I/O error.
 */
List<ReleaseEntry> loadReleasesIndex(Path releasesIndexPath) throws IOException {
    if (edition == null) {
        edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    }
    List<ReleaseEntry> result = new ArrayList<>();
    try (Reader urlReader = new InputStreamReader(Files.newInputStream(releasesIndexPath))) {
        JSONTokener tokener = new JSONTokener(urlReader);
        JSONObject obj = new JSONObject(tokener);
        JSONObject releases = obj.getJSONObject(KEY_RELEASES);
        if (releases == null) {
            // malformed releases file;
            throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
        }
        Version v = localRegistry.getGraalVersion();
        for (String k : releases.keySet()) {
            JSONObject jo = releases.getJSONObject(k);
            ReleaseEntry e = null;
            try {
                e = jsonToRelease(k, jo);
            } catch (JSONException | IllegalArgumentException ex) {
                fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
            }
            if (e == null) {
                invalidReleases.add(k);
            } else if (!localRegistry.getJavaVersion().equals(e.getJavaVersion())) {
                LOG.log(Level.FINER, "Invalid Java: {0}", k);
            } else if (e.getBasePackages().isEmpty()) {
                LOG.log(Level.FINER, "No distribution packages: {0}", k);
            } else if (edition != null && !edition.equals(e.getEdition())) {
                LOG.log(Level.FINER, "Incorrect edition: {0}", k);
            } else if (!acceptsVersion(v, e.getVersion())) {
                LOG.log(Level.FINER, "Old version: {0}", k);
            } else {
                result.add(e);
            }
        }
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JSONException(com.oracle.truffle.tools.utils.json.JSONException) JSONTokener(com.oracle.truffle.tools.utils.json.JSONTokener) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) IncompatibleException(org.graalvm.component.installer.IncompatibleException)

Aggregations

JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)318 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)71 ArrayList (java.util.ArrayList)20 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)18 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 DebugException (com.oracle.truffle.api.debug.DebugException)11 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)10 SourceSection (com.oracle.truffle.api.source.SourceSection)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collection (java.util.Collection)7 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)6 Source (com.oracle.truffle.api.source.Source)6 Map (java.util.Map)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)5 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)5 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)5 Test (org.junit.Test)5 Location (com.oracle.truffle.tools.chromeinspector.types.Location)4