Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 68eea172cf084c4d192ec31e7cce0f384a3b869f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*******************************************************************************
 * Copyright (c) 2018 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.tracecompass.incubator.internal.traceevent.core.analysis.context;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.SelectionTimeQueryFilter;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.TimeQueryFilter;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.AbstractTimeGraphDataProvider;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.ITimeGraphArrow;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.ITimeGraphRowModel;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.ITimeGraphState;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.TimeGraphEntryModel;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.TimeGraphRowModel;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.TimeGraphState;
import org.eclipse.tracecompass.internal.provisional.tmf.core.response.ITmfResponse.Status;
import org.eclipse.tracecompass.internal.provisional.tmf.core.response.TmfModelResponse;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;

/**
 * Context analysis datasource. Provides the locations of contexts.
 *
 * @author Matthew Khouzam
 */
public class ContextDataProvider extends AbstractTimeGraphDataProvider<@NonNull ContextAnalysis, @NonNull TimeGraphEntryModel> {

    public static final @NonNull String ID = ContextAnalysis.ID + ".dataprovider"; //$NON-NLS-1$

    /**
     * Model of a marker, not necessarily bound to a timegraph, denotes an area
     * that's interesting.
     *
     * Note: Do we have anything that already does this?
     */
    public static class MarkerModel extends TimeGraphState {

        private final String fAnnotation;
        private final String fCategory;

        /**
         * Constructor, used for internal reasons, as the array is hard coded
         *
         * @param startTime
         *            the start time
         * @param duration
         *            the duration
         *
         * @param string
         *            {category, name, annotation}
         */
        private MarkerModel(long startTime, long duration, String[] sections) {
            super(startTime, duration, 0, sections[1]);
            fCategory = sections[0];
            fAnnotation = sections[2];
        }

        /**
         * Gets the category of the marker
         *
         * @return the category
         */
        public String getCategory() {
            return fCategory;
        }

        /**
         * Gets the annotation of the marker
         *
         * @return the annotation
         */
        public String getAnnotation() {
            return fAnnotation;
        }

    }

    /**
     * Constructor
     *
     * @param trace
     *            the trace this provider represents
     * @param analysisModule
     *            the analysis encapsulated by this provider
     */
    public ContextDataProvider(ITmfTrace trace, ContextAnalysis analysisModule) {
        super(trace, analysisModule);
    }

    @Override
    public @NonNull String getId() {
        return ID;
    }

    @Override
    protected boolean isCacheable() {
        return true;
    }

    @Override
    public @NonNull TmfModelResponse<@NonNull List<@NonNull ITimeGraphArrow>> fetchArrows(@NonNull TimeQueryFilter filter, @Nullable IProgressMonitor monitor) {
        return new TmfModelResponse<>(null, Status.COMPLETED, "Not supported");
    }

    @Override
    public @NonNull TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(@NonNull SelectionTimeQueryFilter filter, @Nullable IProgressMonitor monitor) {
        return new TmfModelResponse<>(null, Status.COMPLETED, "Not supported");
    }

    @Override
    protected @Nullable List<@NonNull ITimeGraphRowModel> getRowModel(@NonNull ITmfStateSystem ss, @NonNull SelectionTimeQueryFilter filter, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
        /*
         * Order is not important here
         */
        Map<Integer, String[]> paths = new HashMap<>();
        List<ITimeGraphState> markerList = new ArrayList<>();

        Collection<Long> times = getTimes(filter, ss.getStartTime(), ss.getCurrentEndTime());
        Set<Integer> quarks = new HashSet<>();
        for (Integer quark : getSelectedQuarks(filter)) {
            quarks.addAll(ss.getSubAttributes(quark, true));
        }
        /* resolve the names */
        for (Integer quark : quarks) {
            paths.put(quark, ss.getFullAttributePathArray(quark));
        }
        /* Do the actual query */
        for (ITmfStateInterval interval : ss.query2D(quarks, times)) {
            if (monitor != null && monitor.isCanceled()) {
                return Collections.emptyList();
            }
            if (interval.getValue() instanceof Integer) {
                long startTime = interval.getStartTime();
                long duration = interval.getEndTime() - startTime + 1;

                markerList.add(new MarkerModel(startTime, duration, paths.get(interval.getAttribute())));
            }
        }

        if (monitor != null && monitor.isCanceled()) {
            return Collections.emptyList();
        }
        return Collections.singletonList(new TimeGraphRowModel(getId(ITmfStateSystem.ROOT_ATTRIBUTE), markerList));
    }

    @Override
    protected @NonNull List<@NonNull TimeGraphEntryModel> getTree(@NonNull ITmfStateSystem ss, @NonNull TimeQueryFilter filter, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
        long rootId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
        List<@NonNull Integer> attribs = ss.getSubAttributes(ITmfStateSystem.ROOT_ATTRIBUTE, false);
        List<@NonNull TimeGraphEntryModel> retVal = new ArrayList<>();
        for (Integer attrib : attribs) {
            String[] strings = ss.getFullAttributePathArray(attrib);
            retVal.add(new TimeGraphEntryModel(getId(attrib), rootId, strings[0], ss.getStartTime(), ss.getCurrentEndTime()));
        }
        return retVal;
    }

}

Back to the top