Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / model / trange / TimeRangeResourceFactory.java
CommitLineData
6e512b93
ASL
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 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.model.trange;
13
e31e01e8 14
6c13869b
FC
15import org.eclipse.linuxtools.lttng.core.state.StateStrings;
16import org.eclipse.linuxtools.lttng.core.state.model.LTTngCPUState;
17import org.eclipse.linuxtools.lttng.core.state.model.LttngIRQState;
18import org.eclipse.linuxtools.lttng.core.state.model.LttngTraceState;
19import org.eclipse.linuxtools.lttng.core.state.model.LttngTrapState;
6e512b93
ASL
20import org.eclipse.linuxtools.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 */
33public 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 // =======================================================================
63eecb47 57 public TimeRangeEventResource createResource(int newId, long newStartTime,
6e512b93 58 long newStopTime, String newName, String newGroupName,
63eecb47
FC
59 String newClassName, ResourceTypes type, Long newResourceId,
60 long insertionTime) {
6e512b93
ASL
61
62 TimeRangeEventResource resource = null;
63 switch (type) {
64 case CPU:
65 resource = createCpuResource(newId, newStartTime, newStopTime,
63eecb47
FC
66 newName, newGroupName, newClassName, type, newResourceId,
67 insertionTime);
6e512b93
ASL
68 break;
69 case IRQ:
70 resource = createIrqResource(newId, newStartTime, newStopTime,
63eecb47
FC
71 newName, newGroupName, newClassName, type, newResourceId,
72 insertionTime);
6e512b93
ASL
73 break;
74 case SOFT_IRQ:
75 resource = createSoftIrqResource(newId, newStartTime, newStopTime,
63eecb47
FC
76 newName, newGroupName, newClassName, type, newResourceId,
77 insertionTime);
6e512b93
ASL
78 break;
79 case TRAP:
80 resource = createTrapResource(newId, newStartTime, newStopTime,
63eecb47
FC
81 newName, newGroupName, newClassName, type, newResourceId,
82 insertionTime);
6e512b93
ASL
83 break;
84 case BDEV:
85 resource = createBdevResource(newId, newStartTime, newStopTime,
63eecb47
FC
86 newName, newGroupName, newClassName, type, newResourceId,
87 insertionTime);
6e512b93
ASL
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,
63eecb47 102 Long newResourceId, long insertionTime) {
6e512b93
ASL
103
104 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
63eecb47
FC
105 newStartTime, newStopTime, newName, newGroupName, newClassName,
106 newType, newResourceId, insertionTime) {
6e512b93
ASL
107
108 @Override
109 public String getStateMode(LttngTraceState traceSt) {
110 LttngIRQState irqState = traceSt.getIrq_states().get(
111 getResourceId());
9c4eb5f7 112 String statemode = ""; //$NON-NLS-1$
6e512b93
ASL
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,
63eecb47 127 Long newResourceId, long insertionTime) {
6e512b93
ASL
128
129 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
130 newStartTime, newStopTime, newName, newGroupName, newClassName,
63eecb47 131 newType, newResourceId, insertionTime) {
6e512b93
ASL
132
133 @Override
134 public String getStateMode(LttngTraceState traceSt) {
135 // Determine the trap state.
9c4eb5f7 136 String trapStateMode = ""; //$NON-NLS-1$
e31e01e8
FC
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 }
6e512b93 152 }
e31e01e8
FC
153 else {
154 trapStateMode = StateStrings.TrapMode.LTTV_TRAP_BUSY.getInName();
155 }
156
6e512b93
ASL
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,
63eecb47 167 Long newResourceId, long insertionTime) {
6e512b93
ASL
168
169 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
170 newStartTime, newStopTime, newName, newGroupName, newClassName,
63eecb47 171 newType, newResourceId, insertionTime) {
6e512b93
ASL
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,
63eecb47 206 Long newResourceId, long insertionTime) {
6e512b93
ASL
207
208 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
209 newStartTime, newStopTime, newName, newGroupName, newClassName,
63eecb47 210 newType, newResourceId, insertionTime) {
6e512b93
ASL
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,
63eecb47 229 Long newResourceId, long insertionTime) {
6e512b93
ASL
230
231 TimeRangeEventResource resource = new TimeRangeEventResource(newId,
232 newStartTime, newStopTime, newName, newGroupName, newClassName,
63eecb47 233 newType, newResourceId, insertionTime) {
6e512b93
ASL
234
235 @Override
236 public String getStateMode(LttngTraceState traceSt) {
237 // Get the resource state mode
c1c69938
FC
238 LTTngCPUState cpuState = traceSt.getCpu_states().get(
239 getResourceId());
240
9c4eb5f7 241 String cpuStateMode = ""; //$NON-NLS-1$
c1c69938
FC
242 if (cpuState != null) {
243 cpuStateMode = traceSt.getCpu_states().get(
244 getResourceId())
245 .peekFromCpuStack().getInName();
246 }
6e512b93
ASL
247
248 return cpuStateMode;
249 }
250
251 };
252
253 return resource;
254 }
255}
This page took 0.041766 seconds and 5 git commands to generate.