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