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