tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / internal / lttng / core / state / model / LTTngCPUState.java
CommitLineData
5d10d135
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 *******************************************************************************/
5945cec9 12package org.eclipse.linuxtools.internal.lttng.core.state.model;
5d10d135
ASL
13
14import java.util.Stack;
15
5945cec9
FC
16import org.eclipse.linuxtools.internal.lttng.core.state.StateStrings;
17import org.eclipse.linuxtools.internal.lttng.core.state.StateStrings.CpuMode;
5d10d135
ASL
18
19/**
20 * <b><u>LTTngCPUState</u></b>
21 * <p>
22 *
23 */
24public class LTTngCPUState implements Cloneable {
25 // ========================================================================
26 // Data
27 // =======================================================================
28 private Stack<StateStrings.CpuMode> mode_stack = new Stack<StateStrings.CpuMode>();
29 private Stack<Long> irq_stack = new Stack<Long>();
30 private Stack<Long> softirq_stack = new Stack<Long>();
31 private Stack<Long> trap_stack = new Stack<Long>();
32
33 // ========================================================================
34 // Constructor
35 // =======================================================================
36 public LTTngCPUState() {
37 mode_stack.push(CpuMode.LTTV_CPU_UNKNOWN);
38 irq_stack.push(-1L);
39 softirq_stack.push(-1L);
40 trap_stack.push(-1L);
41 }
42
cc6eec3e 43 @Override
5d10d135
ASL
44 @SuppressWarnings("unchecked")
45 public LTTngCPUState clone() {
46 LTTngCPUState newState = null;
47
48 try {
49 newState = (LTTngCPUState) super.clone();
50
51 // // *** IMPORTANT ***
52 // // Basic type in java are immutable!
53 // // Thus, using assignation ("=") on basic type is CORRECT,
54 // // but we should ALWAYS use "new" or "clone()" on "non basic"
55 // type
56
57 // Clone should work correctly for all stack object that contain
58 // basic java object (String, Long, etc...)
59 newState.mode_stack = (Stack<StateStrings.CpuMode>) this.mode_stack
60 .clone();
61 newState.irq_stack = (Stack<Long>) this.irq_stack.clone();
62 newState.softirq_stack = (Stack<Long>) this.softirq_stack.clone();
63 newState.trap_stack = (Stack<Long>) this.trap_stack.clone();
64 } catch (CloneNotSupportedException e) {
9c4eb5f7 65 System.out.println("Cloning failed with : " + e.getMessage()); //$NON-NLS-1$
5d10d135
ASL
66 }
67
68 return newState;
69 }
70
71 // ========================================================================
72 // Methods
73 public void clearAndSetBaseToCpuStack(StateStrings.CpuMode newCpuMode) {
74 mode_stack.clear();
75 irq_stack.clear();
76 softirq_stack.clear();
77 trap_stack.clear();
78
79 // Ensure that there is always at least 1 item in the stack
80 mode_stack.push(newCpuMode);
81 irq_stack.push(-1L);
82 softirq_stack.push(-1L);
83 trap_stack.push(-1L);
84 }
85
86 // Push to stacks
87 public void pushToCpuStack(StateStrings.CpuMode newCpuMode) {
88 mode_stack.push(newCpuMode);
89 }
90
91 public void pushToIrqStack(Long irqID) {
92 irq_stack.push(irqID);
93 }
94
95 public void pushToSoftIrqStack(Long softIrqID) {
96 softirq_stack.push(softIrqID);
97 }
98
99 public void pushToTrapStack(Long trapID) {
100 trap_stack.push(trapID);
101 }
102
103 // Pop from stacks
104 public StateStrings.CpuMode popFromCpuStack() {
105
106 StateStrings.CpuMode returnedMode = mode_stack.pop();
107
108 if (mode_stack.size() < 1) {
109 // Ensure that there is always at least 1 item in the stack
110 mode_stack.push(StateStrings.CpuMode.LTTV_CPU_UNKNOWN);
111 }
112
113 return returnedMode;
114
115 }
116
117 public Long popFromIrqStack() {
118 Long irq = irq_stack.pop();
119
120 if (irq_stack.size() < 1) {
121 // make sure the stack is not empty
122 irq_stack.push(-1L);
123 }
124 return irq;
125 }
126
127 public Long popFromSoftIrqStack() {
128 Long softirq = softirq_stack.pop();
129
130 if (softirq_stack.size() < 1) {
131 // make sure the stack is not empty
132 softirq_stack.push(-1L);
133 }
134 return softirq;
135 }
136
137 public Long popFromTrapStack() {
138 Long trap = trap_stack.pop();
139
140 if (trap_stack.size() < 1) {
141 // make sure the stack is not empty
142 trap_stack.push(-1L);
143 }
144 return trap;
145 }
146
147 // Peek from stacks
148 public StateStrings.CpuMode peekFromCpuStack() {
149 return mode_stack.peek();
150 }
151
152 public Long peekFromIrqStack() {
153 return irq_stack.peek();
154 }
155
156 public Long peekFromSoftIrqStack() {
157 return softirq_stack.peek();
158 }
159
160 public Long peekFromTrapStack() {
161 return trap_stack.peek();
162 }
163
164
165 public void reset() {
166 mode_stack.clear();
167 irq_stack.clear();
168 softirq_stack.clear();
169 trap_stack.clear();
170
171 // Ensure that there is always at least 1 item in the stack
172 mode_stack.push(CpuMode.LTTV_CPU_UNKNOWN);
173 irq_stack.push(-1L);
174 softirq_stack.push(-1L);
175 trap_stack.push(-1L);
176 }
177
178}
This page took 0.051791 seconds and 5 git commands to generate.