1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
;
15 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LTTngCPUState
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngIRQState
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTrapState
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
.ResourceTypes
;
23 * Creates Resources with custom implementation to obtain its corresponding
26 * The state mode resolution is needed at the end of a data request, as well as
27 * in the before and after handlers
33 public class TimeRangeResourceFactory
{
34 // ========================================================================
36 // =======================================================================
37 private static TimeRangeResourceFactory instance
= null;
39 // ========================================================================
41 // =======================================================================
47 public static TimeRangeResourceFactory
getInstance() {
48 if (instance
== null) {
49 instance
= new TimeRangeResourceFactory();
54 // ========================================================================
56 // =======================================================================
57 public TimeRangeEventResource
createResource(int newId
, long newStartTime
,
58 long newStopTime
, String newName
, String newGroupName
,
59 String newClassName
, ResourceTypes type
, Long newResourceId
,
62 TimeRangeEventResource resource
= null;
65 resource
= createCpuResource(newId
, newStartTime
, newStopTime
,
66 newName
, newGroupName
, newClassName
, type
, newResourceId
,
70 resource
= createIrqResource(newId
, newStartTime
, newStopTime
,
71 newName
, newGroupName
, newClassName
, type
, newResourceId
,
75 resource
= createSoftIrqResource(newId
, newStartTime
, newStopTime
,
76 newName
, newGroupName
, newClassName
, type
, newResourceId
,
80 resource
= createTrapResource(newId
, newStartTime
, newStopTime
,
81 newName
, newGroupName
, newClassName
, type
, newResourceId
,
85 resource
= createBdevResource(newId
, newStartTime
, newStopTime
,
86 newName
, newGroupName
, newClassName
, type
, newResourceId
,
96 // ========================================================================
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
) {
104 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
105 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
106 newType
, newResourceId
, insertionTime
) {
109 public String
getStateMode(LttngTraceState traceSt
) {
110 LttngIRQState irqState
= traceSt
.getIrq_states().get(
112 String statemode
= ""; //$NON-NLS-1$
113 if (irqState
!= null) {
114 statemode
= irqState
.peekFromIrqStack().getInName();
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
) {
129 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
130 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
131 newType
, newResourceId
, insertionTime
) {
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());
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)
145 Long trapState
= ts
.getRunning();
147 if (trapState
== 0) {
148 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_IDLE
.getInName();
150 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_BUSY
.getInName();
154 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_BUSY
.getInName();
157 return trapStateMode
;
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
) {
169 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
170 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
171 newType
, newResourceId
, insertionTime
) {
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();
183 String softIrqStateMode
;
185 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_BUSY
187 } else if (pending
> 0) {
188 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_PENDING
191 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_IDLE
195 return softIrqStateMode
;
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
) {
208 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
209 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
210 newType
, newResourceId
, insertionTime
) {
213 public String
getStateMode(LttngTraceState traceSt
) {
214 // Get the resource state mode
215 String bdevStateMode
= traceSt
.getBdev_states().get(
216 getResourceId()).peekFromBdevStack().getInName();
218 return bdevStateMode
;
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
) {
231 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
232 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
233 newType
, newResourceId
, insertionTime
) {
236 public String
getStateMode(LttngTraceState traceSt
) {
237 // Get the resource state mode
238 LTTngCPUState cpuState
= traceSt
.getCpu_states().get(
241 String cpuStateMode
= ""; //$NON-NLS-1$
242 if (cpuState
!= null) {
243 cpuStateMode
= traceSt
.getCpu_states().get(
245 .peekFromCpuStack().getInName();