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
;
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
;
20 * Creates Resources with custom implementation to obtain its corresponding
23 * The state mode resolution is needed at the end of a data request, as well as
24 * in the before and after handlers
30 public class TimeRangeResourceFactory
{
31 // ========================================================================
33 // =======================================================================
34 private static TimeRangeResourceFactory instance
= null;
36 // ========================================================================
38 // =======================================================================
44 public static TimeRangeResourceFactory
getInstance() {
45 if (instance
== null) {
46 instance
= new TimeRangeResourceFactory();
51 // ========================================================================
53 // =======================================================================
54 public TimeRangeEventResource
createResource(int newId
, long newStartTime
,
55 long newStopTime
, String newName
, String newGroupName
,
56 String newClassName
, ResourceTypes type
, Long newResourceId
,
59 TimeRangeEventResource resource
= null;
62 resource
= createCpuResource(newId
, newStartTime
, newStopTime
,
63 newName
, newGroupName
, newClassName
, type
, newResourceId
,
67 resource
= createIrqResource(newId
, newStartTime
, newStopTime
,
68 newName
, newGroupName
, newClassName
, type
, newResourceId
,
72 resource
= createSoftIrqResource(newId
, newStartTime
, newStopTime
,
73 newName
, newGroupName
, newClassName
, type
, newResourceId
,
77 resource
= createTrapResource(newId
, newStartTime
, newStopTime
,
78 newName
, newGroupName
, newClassName
, type
, newResourceId
,
82 resource
= createBdevResource(newId
, newStartTime
, newStopTime
,
83 newName
, newGroupName
, newClassName
, type
, newResourceId
,
93 // ========================================================================
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
) {
101 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
102 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
103 newType
, newResourceId
, insertionTime
) {
106 public String
getStateMode(LttngTraceState traceSt
) {
107 LttngIRQState irqState
= traceSt
.getIrq_states().get(
109 String statemode
= "";
110 if (irqState
!= null) {
111 statemode
= irqState
.peekFromIrqStack().getInName();
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
) {
126 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
127 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
128 newType
, newResourceId
, insertionTime
) {
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
140 trapStateMode
= StateStrings
.TrapMode
.LTTV_TRAP_BUSY
144 return trapStateMode
;
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
) {
156 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
157 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
158 newType
, newResourceId
, insertionTime
) {
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();
170 String softIrqStateMode
;
172 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_BUSY
174 } else if (pending
> 0) {
175 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_PENDING
178 softIrqStateMode
= StateStrings
.SoftIRQMode
.LTTV_SOFT_IRQ_IDLE
182 return softIrqStateMode
;
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
) {
195 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
196 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
197 newType
, newResourceId
, insertionTime
) {
200 public String
getStateMode(LttngTraceState traceSt
) {
201 // Get the resource state mode
202 String bdevStateMode
= traceSt
.getBdev_states().get(
203 getResourceId()).peekFromBdevStack().getInName();
205 return bdevStateMode
;
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
) {
218 TimeRangeEventResource resource
= new TimeRangeEventResource(newId
,
219 newStartTime
, newStopTime
, newName
, newGroupName
, newClassName
,
220 newType
, newResourceId
, insertionTime
) {
223 public String
getStateMode(LttngTraceState traceSt
) {
224 // Get the resource state mode
225 String cpuStateMode
= traceSt
.getCpu_states().get(
227 .peekFromCpuStack().getInName();