Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.model.trange; | |
13 | ||
6e512b93 ASL |
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; | |
6e512b93 ASL |
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 | // ======================================================================= | |
dfaf8391 FC |
54 | public TimeRangeEventResource createResource(int newId, |
55 | long newStartTime, | |
6e512b93 | 56 | long newStopTime, String newName, String newGroupName, |
dfaf8391 | 57 | String newClassName, ResourceTypes type, Long newResourceId) { |
6e512b93 ASL |
58 | |
59 | TimeRangeEventResource resource = null; | |
60 | switch (type) { | |
61 | case CPU: | |
62 | resource = createCpuResource(newId, newStartTime, newStopTime, | |
dfaf8391 FC |
63 | newName, |
64 | newGroupName, newClassName, type, newResourceId); | |
6e512b93 ASL |
65 | break; |
66 | case IRQ: | |
67 | resource = createIrqResource(newId, newStartTime, newStopTime, | |
dfaf8391 FC |
68 | newName, |
69 | newGroupName, newClassName, type, newResourceId); | |
6e512b93 ASL |
70 | break; |
71 | case SOFT_IRQ: | |
72 | resource = createSoftIrqResource(newId, newStartTime, newStopTime, | |
dfaf8391 FC |
73 | newName, |
74 | newGroupName, newClassName, type, newResourceId); | |
6e512b93 ASL |
75 | break; |
76 | case TRAP: | |
77 | resource = createTrapResource(newId, newStartTime, newStopTime, | |
dfaf8391 FC |
78 | newName, |
79 | newGroupName, newClassName, type, newResourceId); | |
6e512b93 ASL |
80 | break; |
81 | case BDEV: | |
82 | resource = createBdevResource(newId, newStartTime, newStopTime, | |
dfaf8391 FC |
83 | newName, |
84 | newGroupName, newClassName, type, newResourceId); | |
6e512b93 ASL |
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, | |
dfaf8391 | 99 | Long newResourceId) { |
6e512b93 ASL |
100 | |
101 | TimeRangeEventResource resource = new TimeRangeEventResource(newId, | |
dfaf8391 FC |
102 | newStartTime, newStopTime, |
103 | newName, newGroupName, newClassName, newType, newResourceId) { | |
6e512b93 ASL |
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, | |
dfaf8391 | 124 | Long newResourceId) { |
6e512b93 ASL |
125 | |
126 | TimeRangeEventResource resource = new TimeRangeEventResource(newId, | |
127 | newStartTime, newStopTime, newName, newGroupName, newClassName, | |
dfaf8391 | 128 | newType, newResourceId) { |
6e512b93 ASL |
129 | |
130 | @Override | |
131 | public String getStateMode(LttngTraceState traceSt) { | |
132 | // Determine the trap state. | |
8035003b ASL |
133 | long trapState = traceSt.getTrap_states().get(getResourceId()) |
134 | .getRunning().longValue(); | |
6e512b93 | 135 | String trapStateMode = ""; |
8035003b ASL |
136 | if (trapState == 0) { |
137 | trapStateMode = StateStrings.TrapMode.LTTV_TRAP_IDLE | |
138 | .getInName(); | |
139 | } else { | |
140 | trapStateMode = StateStrings.TrapMode.LTTV_TRAP_BUSY | |
141 | .getInName(); | |
6e512b93 | 142 | } |
8035003b | 143 | |
6e512b93 ASL |
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, | |
dfaf8391 | 154 | Long newResourceId) { |
6e512b93 ASL |
155 | |
156 | TimeRangeEventResource resource = new TimeRangeEventResource(newId, | |
157 | newStartTime, newStopTime, newName, newGroupName, newClassName, | |
dfaf8391 | 158 | newType, newResourceId) { |
6e512b93 ASL |
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, | |
dfaf8391 | 193 | Long newResourceId) { |
6e512b93 ASL |
194 | |
195 | TimeRangeEventResource resource = new TimeRangeEventResource(newId, | |
196 | newStartTime, newStopTime, newName, newGroupName, newClassName, | |
dfaf8391 | 197 | newType, newResourceId) { |
6e512b93 ASL |
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, | |
dfaf8391 | 216 | Long newResourceId) { |
6e512b93 ASL |
217 | |
218 | TimeRangeEventResource resource = new TimeRangeEventResource(newId, | |
219 | newStartTime, newStopTime, newName, newGroupName, newClassName, | |
dfaf8391 | 220 | newType, newResourceId) { |
6e512b93 ASL |
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 | } |