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
.LttngIRQState
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTrapState
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
.ResourceTypes
;
22 * Creates Resources with custom implementation to obtain its corresponding
25 * The state mode resolution is needed at the end of a data request, as well as
26 * in the before and after handlers
32 public class TimeRangeResourceFactory
{
33 // ========================================================================
35 // =======================================================================
36 private static TimeRangeResourceFactory instance
= null;
38 // ========================================================================
40 // =======================================================================
46 public static TimeRangeResourceFactory
getInstance() {
47 if (instance
== null) {
48 instance
= new TimeRangeResourceFactory();
53 // ========================================================================
55 // =======================================================================
56 public TimeRangeEventResource
createResource(int newId
, long newStartTime
,
57 long newStopTime
, String newName
, String newGroupName
,
58 String newClassName
, ResourceTypes type
, Long newResourceId
,
61 TimeRangeEventResource resource
= null;
64 resource
= createCpuResource(newId
, newStartTime
, newStopTime
,
65 newName
, newGroupName
, newClassName
, type
, newResourceId
,
69 resource
= createIrqResource(newId
, newStartTime
, newStopTime
,
70 newName
, newGroupName
, newClassName
, type
, newResourceId
,
74 resource
= createSoftIrqResource(newId
, newStartTime
, newStopTime
,
75 newName
, newGroupName
, newClassName
, type
, newResourceId
,
79 resource
= createTrapResource(newId
, newStartTime
, newStopTime
,
80 newName
, newGroupName
, newClassName
, type
, newResourceId
,
84 resource
= createBdevResource(newId
, newStartTime
, newStopTime
,
85 newName
, newGroupName
, newClassName
, type
, newResourceId
,
95 // ========================================================================
97 // =======================================================================
98 private TimeRangeEventResource
createIrqResource(int newId
,
99 long newStartTime
, long newStopTime
, String newName
,
100 String newGroupName
, String newClassName
, ResourceTypes newType
,
101 Long newResourceId
, long insertionTime
) {
103 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
104 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
105 newType
, newResourceId
, insertionTime
) {
108 public String
getStateMode(LttngTraceState traceSt
) {
109 LttngIRQState irqState
= traceSt
.getIrq_states().get(
111 String statemode
= "";
112 if (irqState
!= null) {
113 statemode
= irqState
.peekFromIrqStack().getInName();
123 private TimeRangeEventResource
createTrapResource(int newId
,
124 long newStartTime
, long newStopTime
, String newName
,
125 String newGroupName
, String newClassName
, ResourceTypes newType
,
126 Long newResourceId
, long insertionTime
) {
128 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
129 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
130 newType
, newResourceId
, insertionTime
) {
133 public String
getStateMode(LttngTraceState traceSt
) {
134 // Determine the trap state.
135 String trapStateMode
= "";
136 LttngTrapState ts
= traceSt
.getTrap_states().get(getResourceId());
139 // Ts might not have been created yet.
140 // This is because the state system will be updated next to this before hook
141 // It should be correct to create it here as Busy
142 // (traps are created with running++ so it wont be idle)
144 Long trapState
= ts
.getRunning();
146 if (trapState
== 0) {
147 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_IDLE
.getInName();
149 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_BUSY
.getInName();
153 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_BUSY
.getInName();
156 return trapStateMode
;
163 private TimeRangeEventResource
createSoftIrqResource(int newId
,
164 long newStartTime
, long newStopTime
, String newName
,
165 String newGroupName
, String newClassName
, ResourceTypes newType
,
166 Long newResourceId
, long insertionTime
) {
168 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
169 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
170 newType
, newResourceId
, insertionTime
) {
173 public String
getStateMode(LttngTraceState traceSt
) {
174 // Get the resource id.
175 Long softIrqId
= getResourceId();
176 // Get the resource state mode
177 long running
= traceSt
.getSoft_irq_states().get(softIrqId
)
178 .getRunning().longValue();
179 long pending
= traceSt
.getSoft_irq_states().get(softIrqId
)
180 .getPending().longValue();
182 String softIrqStateMode
;
184 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_BUSY
186 } else if (pending
> 0) {
187 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_PENDING
190 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_IDLE
194 return softIrqStateMode
;
202 private TimeRangeEventResource
createBdevResource(int newId
,
203 long newStartTime
, long newStopTime
, String newName
,
204 String newGroupName
, String newClassName
, ResourceTypes newType
,
205 Long newResourceId
, long insertionTime
) {
207 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
208 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
209 newType
, newResourceId
, insertionTime
) {
212 public String
getStateMode(LttngTraceState traceSt
) {
213 // Get the resource state mode
214 String bdevStateMode
= traceSt
.getBdev_states().get(
215 getResourceId()).peekFromBdevStack().getInName();
217 return bdevStateMode
;
225 private TimeRangeEventResource
createCpuResource(int newId
,
226 long newStartTime
, long newStopTime
, String newName
,
227 String newGroupName
, String newClassName
, ResourceTypes newType
,
228 Long newResourceId
, long insertionTime
) {
230 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
231 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
232 newType
, newResourceId
, insertionTime
) {
235 public String
getStateMode(LttngTraceState traceSt
) {
236 // Get the resource state mode
237 String cpuStateMode
= traceSt
.getCpu_states().get(
239 .peekFromCpuStack().getInName();