[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / model / trange / TimeRangeResourceFactory.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.model.trange;
13
14
15 import org.eclipse.linuxtools.lttng.state.StateStrings;
16 import org.eclipse.linuxtools.lttng.state.model.LttngIRQState;
17 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
18 import org.eclipse.linuxtools.lttng.state.model.LttngTrapState;
19 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes;
20
21 /**
22 * Creates Resources with custom implementation to obtain its corresponding
23 * state mode
24 * <p>
25 * The state mode resolution is needed at the end of a data request, as well as
26 * in the before and after handlers
27 * </p>
28 *
29 * @author alvaro
30 *
31 */
32 public class TimeRangeResourceFactory {
33 // ========================================================================
34 // Data
35 // =======================================================================
36 private static TimeRangeResourceFactory instance = null;
37
38 // ========================================================================
39 // Create instance
40 // =======================================================================
41 /**
42 * Factory singleton
43 *
44 * @return
45 */
46 public static TimeRangeResourceFactory getInstance() {
47 if (instance == null) {
48 instance = new TimeRangeResourceFactory();
49 }
50 return instance;
51 }
52
53 // ========================================================================
54 // Public methods
55 // =======================================================================
56 public TimeRangeEventResource createResource(int newId, long newStartTime,
57 long newStopTime, String newName, String newGroupName,
58 String newClassName, ResourceTypes type, Long newResourceId,
59 long insertionTime) {
60
61 TimeRangeEventResource resource = null;
62 switch (type) {
63 case CPU:
64 resource = createCpuResource(newId, newStartTime, newStopTime,
65 newName, newGroupName, newClassName, type, newResourceId,
66 insertionTime);
67 break;
68 case IRQ:
69 resource = createIrqResource(newId, newStartTime, newStopTime,
70 newName, newGroupName, newClassName, type, newResourceId,
71 insertionTime);
72 break;
73 case SOFT_IRQ:
74 resource = createSoftIrqResource(newId, newStartTime, newStopTime,
75 newName, newGroupName, newClassName, type, newResourceId,
76 insertionTime);
77 break;
78 case TRAP:
79 resource = createTrapResource(newId, newStartTime, newStopTime,
80 newName, newGroupName, newClassName, type, newResourceId,
81 insertionTime);
82 break;
83 case BDEV:
84 resource = createBdevResource(newId, newStartTime, newStopTime,
85 newName, newGroupName, newClassName, type, newResourceId,
86 insertionTime);
87 break;
88 default:
89 break;
90 }
91
92 return resource;
93 }
94
95 // ========================================================================
96 // Private methods
97 // =======================================================================
98 private TimeRangeEventResource createIrqResource(int newId,
99 long newStartTime, long newStopTime, String newName,
100 String newGroupName, String newClassName, ResourceTypes newType,
101 Long newResourceId, long insertionTime) {
102
103 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
104 newStartTime, newStopTime, newName, newGroupName, newClassName,
105 newType, newResourceId, insertionTime) {
106
107 @Override
108 public String getStateMode(LttngTraceState traceSt) {
109 LttngIRQState irqState = traceSt.getIrq_states().get(
110 getResourceId());
111 String statemode = "";
112 if (irqState != null) {
113 statemode = irqState.peekFromIrqStack().getInName();
114 }
115
116 return statemode;
117 }
118 };
119
120 return resource;
121 }
122
123 private TimeRangeEventResource createTrapResource(int newId,
124 long newStartTime, long newStopTime, String newName,
125 String newGroupName, String newClassName, ResourceTypes newType,
126 Long newResourceId, long insertionTime) {
127
128 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
129 newStartTime, newStopTime, newName, newGroupName, newClassName,
130 newType, newResourceId, insertionTime) {
131
132 @Override
133 public String getStateMode(LttngTraceState traceSt) {
134 // Determine the trap state.
135 String trapStateMode = "";
136 LttngTrapState ts = traceSt.getTrap_states().get(getResourceId());
137
138 // *** Note :
139 // Ts might not have been created yet.
140 // This is because the state system will be updated next to this before hook
141 // It should be correct to create it here as Busy
142 // (traps are created with running++ so it wont be idle)
143 if ( ts != null ) {
144 Long trapState = ts.getRunning();
145
146 if (trapState == 0) {
147 trapStateMode = StateStrings.TrapMode.LTTV_TRAP_IDLE.getInName();
148 } else {
149 trapStateMode = StateStrings.TrapMode.LTTV_TRAP_BUSY.getInName();
150 }
151 }
152 else {
153 trapStateMode = StateStrings.TrapMode.LTTV_TRAP_BUSY.getInName();
154 }
155
156 return trapStateMode;
157 }
158 };
159
160 return resource;
161 }
162
163 private TimeRangeEventResource createSoftIrqResource(int newId,
164 long newStartTime, long newStopTime, String newName,
165 String newGroupName, String newClassName, ResourceTypes newType,
166 Long newResourceId, long insertionTime) {
167
168 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
169 newStartTime, newStopTime, newName, newGroupName, newClassName,
170 newType, newResourceId, insertionTime) {
171
172 @Override
173 public String getStateMode(LttngTraceState traceSt) {
174 // Get the resource id.
175 Long softIrqId = getResourceId();
176 // Get the resource state mode
177 long running = traceSt.getSoft_irq_states().get(softIrqId)
178 .getRunning().longValue();
179 long pending = traceSt.getSoft_irq_states().get(softIrqId)
180 .getPending().longValue();
181
182 String softIrqStateMode;
183 if (running > 0) {
184 softIrqStateMode = StateStrings.SoftIRQMode.LTTV_SOFT_IRQ_BUSY
185 .getInName();
186 } else if (pending > 0) {
187 softIrqStateMode = StateStrings.SoftIRQMode.LTTV_SOFT_IRQ_PENDING
188 .getInName();
189 } else {
190 softIrqStateMode = StateStrings.SoftIRQMode.LTTV_SOFT_IRQ_IDLE
191 .getInName();
192 }
193
194 return softIrqStateMode;
195 }
196
197 };
198
199 return resource;
200 }
201
202 private TimeRangeEventResource createBdevResource(int newId,
203 long newStartTime, long newStopTime, String newName,
204 String newGroupName, String newClassName, ResourceTypes newType,
205 Long newResourceId, long insertionTime) {
206
207 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
208 newStartTime, newStopTime, newName, newGroupName, newClassName,
209 newType, newResourceId, insertionTime) {
210
211 @Override
212 public String getStateMode(LttngTraceState traceSt) {
213 // Get the resource state mode
214 String bdevStateMode = traceSt.getBdev_states().get(
215 getResourceId()).peekFromBdevStack().getInName();
216
217 return bdevStateMode;
218 }
219
220 };
221
222 return resource;
223 }
224
225 private TimeRangeEventResource createCpuResource(int newId,
226 long newStartTime, long newStopTime, String newName,
227 String newGroupName, String newClassName, ResourceTypes newType,
228 Long newResourceId, long insertionTime) {
229
230 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
231 newStartTime, newStopTime, newName, newGroupName, newClassName,
232 newType, newResourceId, insertionTime) {
233
234 @Override
235 public String getStateMode(LttngTraceState traceSt) {
236 // Get the resource state mode
237 String cpuStateMode = traceSt.getCpu_states().get(
238 getResourceId())
239 .peekFromCpuStack().getInName();
240
241 return cpuStateMode;
242 }
243
244 };
245
246 return resource;
247 }
248 }
This page took 0.036098 seconds and 5 git commands to generate.