lttng: Track user/kernel mode and IRQ types under the CPU status
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesPresentationProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
14
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18
19 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
20 import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
21 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
22 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
23 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
24 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
25 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
26 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
27 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
28 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
29 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
30 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
31 import org.eclipse.swt.graphics.RGB;
32
33 public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {
34
35 private enum State {
36 UNKNOWN (new RGB(100, 100, 100)),
37 IDLE (new RGB(200, 200, 200)),
38 BUSY (new RGB(0, 200, 0)),
39 INTERRUPTED (new RGB(200, 100, 100)),
40 RAISED (new RGB(200, 200, 0)),
41 ACTIVE (new RGB(200, 150, 100));
42
43 public final RGB rgb;
44
45 private State (RGB rgb) {
46 this.rgb = rgb;
47 }
48 }
49
50 @Override
51 public String getStateTypeName() {
52 return Messages.ResourcesView_stateTypeName;
53 }
54
55 @Override
56 public StateItem[] getStateTable() {
57 StateItem[] stateTable = new StateItem[State.values().length];
58 for (int i = 0; i < stateTable.length; i++) {
59 State state = State.values()[i];
60 stateTable[i] = new StateItem(state.rgb, state.toString());
61 }
62 return stateTable;
63 }
64
65 @Override
66 public int getStateTableIndex(ITimeEvent event) {
67 if (event instanceof ResourcesEvent) {
68 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
69 if (resourcesEvent.getType() == Type.CPU) {
70 int status = resourcesEvent.getValue();
71 if (status == StateValues.CPU_STATUS_IDLE) {
72 return State.IDLE.ordinal();
73 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {
74 return State.BUSY.ordinal();
75 } else if (status == StateValues.CPU_STATUS_IRQ) {
76 return State.INTERRUPTED.ordinal();
77 }
78 } else if (resourcesEvent.getType() == Type.IRQ || resourcesEvent.getType() == Type.SOFT_IRQ) {
79 int cpu = resourcesEvent.getValue();
80 if (cpu == StateValues.SOFT_IRQ_RAISED) {
81 return State.RAISED.ordinal();
82 }
83 return State.ACTIVE.ordinal();
84 } else {
85 return -1; // NULL
86 }
87 }
88 return State.UNKNOWN.ordinal();
89 }
90
91 @Override
92 public String getEventName(ITimeEvent event) {
93 if (event instanceof ResourcesEvent) {
94 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
95 if (resourcesEvent.getType() == Type.CPU) {
96 int status = resourcesEvent.getValue();
97 if (status == StateValues.CPU_STATUS_IDLE) {
98 return State.IDLE.toString();
99 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {
100 return State.BUSY.toString();
101 } else if (status == StateValues.CPU_STATUS_IRQ) {
102 return State.INTERRUPTED.toString();
103 }
104 } else if (resourcesEvent.getType() == Type.IRQ || resourcesEvent.getType() == Type.SOFT_IRQ) {
105 int cpu = resourcesEvent.getValue();
106 if (cpu == StateValues.SOFT_IRQ_RAISED) {
107 return State.RAISED.toString();
108 }
109 return State.ACTIVE.toString();
110 } else {
111 return null;
112 }
113 }
114 return State.UNKNOWN.toString();
115 }
116
117 @Override
118 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
119
120 Map<String, String> retMap = new HashMap<String, String>();
121 if (event instanceof ResourcesEvent) {
122
123 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
124
125 // Check for IRQ or Soft_IRQ type
126 if (resourcesEvent.getType().equals(Type.IRQ) || resourcesEvent.getType().equals(Type.SOFT_IRQ)) {
127
128 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
129 int cpu = resourcesEvent.getValue();
130 if (cpu >= 0) {
131 retMap.put(Messages.ResourcesView_attributeCpuName, String.valueOf(cpu));
132 }
133 }
134
135 // Check for type CPU
136 if (resourcesEvent.getType().equals(Type.CPU)) {
137 int status = resourcesEvent.getValue();
138
139 if (status == StateValues.CPU_STATUS_IRQ) {
140 // In interrupted state get the IRQ or SOFT_IRQ that caused the interruption
141 ResourcesEntry entry = (ResourcesEntry) event.getEntry();
142 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
143 int cpu = entry.getId();
144
145 IStateSystemQuerier ss = entry.getTrace().getStateSystem();
146 try {
147 int resultQuark = 0;
148 String attributeName = null;
149
150 // First check for IRQ
151 List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
152 List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
153
154 for (int curQuark : irqQuarks) {
155 if (fullState.get(curQuark).getStateValue().unboxInt() == cpu) {
156 resultQuark = curQuark;
157 attributeName = Messages.ResourcesView_attributeIrqName;
158 break;
159 }
160 }
161
162 // If not found check for SOFT_IRQ
163 if (attributeName == null) {
164 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
165 for (int curQuark : softIrqQuarks) {
166 if (fullState.get(curQuark).getStateValue().unboxInt() == cpu) {
167 resultQuark = curQuark;
168 attributeName = Messages.ResourcesView_attributeSoftIrqName;
169 break;
170 }
171 }
172 }
173
174 if (attributeName != null) {
175 // A IRQ or SOFT_IRQ was found
176 ITmfStateInterval value = ssq.querySingleState(event.getTime(), resultQuark);
177 if (!value.getStateValue().isNull()) {
178 int irq = Integer.parseInt(ssq.getAttributeName(resultQuark));
179 retMap.put(attributeName, String.valueOf(irq));
180 }
181 }
182 } catch (AttributeNotFoundException e) {
183 e.printStackTrace();
184 } catch (TimeRangeException e) {
185 e.printStackTrace();
186 } catch (StateValueTypeException e) {
187 e.printStackTrace();
188 }
189 }
190 }
191 }
192
193 return retMap;
194 }
195
196 }
This page took 0.036804 seconds and 6 git commands to generate.