Search in sources :

Example 1 with Params

use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.

the class TruffleDebugger method getPossibleBreakpoints.

@Override
public Params getPossibleBreakpoints(Location start, Location end, boolean restrictToFunction) throws CommandProcessException {
    int scriptId = start.getScriptId();
    if (scriptId != end.getScriptId()) {
        throw new CommandProcessException("Different location scripts: " + scriptId + ", " + end.getScriptId());
    }
    Script script = slh.getScript(scriptId);
    if (script == null) {
        throw new CommandProcessException("Unknown scriptId: " + scriptId);
    }
    Source source = script.getSource();
    int o1 = source.getLineStartOffset(start.getLine());
    if (start.getColumn() > 0) {
        o1 += start.getColumn() - 1;
    }
    int o2;
    if (end.getLine() > source.getLineCount()) {
        o2 = source.getLength();
    } else {
        o2 = source.getLineStartOffset(end.getLine());
        if (end.getColumn() > 0) {
            o2 += end.getColumn() - 1;
        }
    }
    SourceSection range = source.createSection(o1, o2 - o1);
    Iterable<SourceSection> locations = SuspendableLocationFinder.findSuspendableLocations(range, restrictToFunction, context.getEnv());
    JSONObject json = new JSONObject();
    JSONArray arr = new JSONArray();
    for (SourceSection ss : locations) {
        arr.put(new Location(scriptId, ss.getStartLine(), ss.getStartColumn()).toJSON());
    }
    json.put("locations", arr);
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Source(com.oracle.truffle.api.source.Source) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

Example 2 with Params

use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.

the class TruffleProfiler method stop.

@Override
public Params stop() {
    long time = System.currentTimeMillis();
    synchronized (sampler) {
        sampler.setCollecting(false);
        sampler.setGatherSelfHitTimes(oldGatherSelfHitTimes);
        long idleHitCount = (time - startTimestamp) / sampler.getPeriod() - sampler.getSampleCount();
        Params profile = getProfile(sampler.getRootNodes(), idleHitCount, startTimestamp, time);
        sampler.clearData();
        return profile;
    }
}
Also used : Params(com.oracle.truffle.tools.chromeinspector.commands.Params)

Example 3 with Params

use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.

the class TruffleProfiler method getProfile.

private Params getProfile(Collection<ProfilerNode<CPUSampler.Payload>> rootProfilerNodes, long idleHitCount, long startTime, long endTime) {
    Map<ProfilerNode<CPUSampler.Payload>, Integer> node2id = new HashMap<>();
    List<ProfileNode> nodes = new ArrayList<>();
    List<Profile.TimeLineItem> timeLine = new ArrayList<>();
    int[] counter = { 1 };
    ProfileNode root = new ProfileNode(counter[0]++, new RuntimeCallFrame("(root)", 0, "", 0, 0), idleHitCount);
    nodes.add(root);
    fillChildren(root, rootProfilerNodes, node2id, nodes, timeLine, counter);
    Collections.sort(timeLine, (item1, item2) -> Long.compare(item1.getTimestamp(), item2.getTimestamp()));
    JSONObject json = new JSONObject();
    json.put("profile", new Profile(nodes.toArray(new ProfileNode[nodes.size()]), startTime, endTime, timeLine.toArray(new Profile.TimeLineItem[timeLine.size()])).toJSON());
    return new Params(json);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) RuntimeCallFrame(com.oracle.truffle.tools.chromeinspector.types.RuntimeCallFrame) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) Profile(com.oracle.truffle.tools.chromeinspector.types.Profile) ProfilerNode(com.oracle.truffle.tools.profiler.ProfilerNode) JSONObject(org.json.JSONObject) ProfileNode(com.oracle.truffle.tools.chromeinspector.types.ProfileNode) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler)

Example 4 with Params

use of com.oracle.truffle.tools.chromeinspector.commands.Params 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);
}
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) JSONObject(org.json.JSONObject) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) Map(java.util.Map) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) 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) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Source(com.oracle.truffle.api.source.Source) CPUSamplerInstrument(com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) Collections(java.util.Collections) JSONArray(org.json.JSONArray) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) CPUTracerInstrument(com.oracle.truffle.tools.profiler.impl.CPUTracerInstrument) Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) JSONObject(org.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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with Params

use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.

the class TruffleProfiler method getBestEffortCoverage.

@Override
public Params getBestEffortCoverage() {
    synchronized (tracer) {
        Params coverage = getCoverage(tracer.getPayloads());
        tracer.clearData();
        return coverage;
    }
}
Also used : Params(com.oracle.truffle.tools.chromeinspector.commands.Params)

Aggregations

Params (com.oracle.truffle.tools.chromeinspector.commands.Params)19 JSONObject (org.json.JSONObject)15 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)9 JSONArray (org.json.JSONArray)7 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)5 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)5 Script (com.oracle.truffle.tools.chromeinspector.types.Script)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 Source (com.oracle.truffle.api.source.Source)4 SourceSection (com.oracle.truffle.api.source.SourceSection)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 Location (com.oracle.truffle.tools.chromeinspector.types.Location)3 ScriptTypeProfile (com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)2 Profile (com.oracle.truffle.tools.chromeinspector.types.Profile)2