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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations