1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
21 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.Attributes
;
22 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.CtfKernelTrace
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateSystemQuerier
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphProvider
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
40 import org
.eclipse
.swt
.SWT
;
41 import org
.eclipse
.swt
.widgets
.Composite
;
42 import org
.eclipse
.swt
.widgets
.Display
;
44 public class ResourcesView
extends TmfView
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
53 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 // The time graph viewer
60 TimeGraphViewer fTimeGraphViewer
;
62 // The selected experiment
63 private TmfExperiment
<ITmfEvent
> fSelectedExperiment
;
65 // The time graph entry list
66 private ArrayList
<ITimeGraphEntry
> fEntryList
;
69 private long fStartTime
;
72 private long fEndTime
;
75 private int fDisplayWidth
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
81 private class GroupEntry
implements ITimeGraphEntry
{
82 public ITimeGraphEntry fParent
;
83 public ArrayList
<ITimeGraphEntry
> fChildren
;
86 public GroupEntry(ITimeGraphEntry parent
, String name
) {
88 fChildren
= new ArrayList
<ITimeGraphEntry
>();
93 public ITimeGraphEntry
getParent() {
98 public boolean hasChildren() {
99 return fChildren
!= null && fChildren
.size() > 0;
103 public ITimeGraphEntry
[] getChildren() {
104 return fChildren
.toArray(new ITimeGraphEntry
[0]);
108 public String
getName() {
113 public long getStartTime() {
118 public long getStopTime() {
123 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
128 public <T
extends ITimeEvent
> Iterator
<T
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
132 public void addChild(ITimeGraphEntry entry
) {
133 fChildren
.add(entry
);
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
141 public ResourcesView() {
143 fDisplayWidth
= Display
.getDefault().getBounds().width
;
146 // ------------------------------------------------------------------------
148 // ------------------------------------------------------------------------
151 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
154 public void createPartControl(Composite parent
) {
155 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
157 fTimeGraphViewer
.setTimeGraphProvider(new TimeGraphProvider() {
159 public String
getTraceClassName(ITimeGraphEntry trace
) {
160 return "trace class"; //$NON-NLS-1$
164 public String
getStateName(StateColor color
) {
165 return "state name"; //$NON-NLS-1$
169 public String
getEventName(ITimeEvent event
, boolean upper
, boolean extInfo
) {
170 return "event name"; //$NON-NLS-1$
174 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
175 return new HashMap
<String
, String
>();
179 public StateColor
getEventColor(ITimeEvent event
) {
180 if (event
.getTime() % 2 == 0) {
181 return StateColor
.BLACK
;
183 return StateColor
.GRAY
;
188 final Thread thread
= new Thread() {
191 if (TmfExperiment
.getCurrentExperiment() != null) {
192 selectExperiment(TmfExperiment
.getCurrentExperiment());
200 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
203 public void setFocus() {
204 fTimeGraphViewer
.setFocus();
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 public void experimentSelected(final TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
213 if (signal
.getExperiment().equals(fSelectedExperiment
)) {
217 final Thread thread
= new Thread() {
220 selectExperiment(signal
.getExperiment());
225 @SuppressWarnings("unchecked")
226 private void selectExperiment(TmfExperiment
<?
> experiment
) {
227 fStartTime
= Long
.MAX_VALUE
;
228 fEndTime
= Long
.MIN_VALUE
;
229 fSelectedExperiment
= (TmfExperiment
<ITmfEvent
>) experiment
;
230 fEntryList
= new ArrayList
<ITimeGraphEntry
>();
231 for (ITmfTrace
<?
> trace
: experiment
.getTraces()) {
232 GroupEntry groupEntry
= new GroupEntry(null, trace
.getPath());
233 fEntryList
.add(groupEntry
);
235 if (trace
instanceof CtfKernelTrace
) {
236 CtfKernelTrace ctfKernelTrace
= (CtfKernelTrace
) trace
;
237 IStateSystemQuerier ssq
= ctfKernelTrace
.getStateSystem();
238 long start
= ssq
.getStartTime();
239 long end
= ssq
.getCurrentEndTime();
240 fStartTime
= Math
.min(fStartTime
, start
);
241 fEndTime
= Math
.max(fEndTime
, end
);
242 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
243 for (int cpuQuark
: cpuQuarks
) {
244 String cpuName
= "CPU " + ssq
.getAttributeName(cpuQuark
);
245 ResourcesEntry entry
= new ResourcesEntry(groupEntry
, ctfKernelTrace
, cpuName
);
247 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
248 long resolution
= (end
- start
) / fDisplayWidth
;
249 List
<ITmfStateInterval
> currentThreadIntervals
= ssq
.queryHistoryRange(currentThreadQuark
, start
, end
, resolution
);
250 for (ITmfStateInterval currentThreadInterval
: currentThreadIntervals
) {
251 if (!currentThreadInterval
.getStateValue().isNull() && currentThreadInterval
.getStateValue().getType() == 0) {
252 int currentThread
= currentThreadInterval
.getStateValue().unboxInt();
253 long startTime
= currentThreadInterval
.getStartTime();
254 long endTime
= currentThreadInterval
.getEndTime();
255 entry
.addTraceEvent(new TimeEvent(entry
, startTime
, endTime
- startTime
));
258 } catch (AttributeNotFoundException e
) {
260 } catch (TimeRangeException e
) {
262 } catch (StateValueTypeException e
) {
265 groupEntry
.addChild(entry
);
272 private void refresh() {
273 Display
.getDefault().asyncExec(new Runnable() {
276 if (fTimeGraphViewer
.getControl().isDisposed()) {
279 fTimeGraphViewer
.setInput(fEntryList
.toArray(new ITimeGraphEntry
[0]));
280 fTimeGraphViewer
.setTimeBounds(fStartTime
, fEndTime
);
281 fTimeGraphViewer
.setStartFinishTime(fStartTime
, fEndTime
);