Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal |
be222f56 PT |
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 | * Patrick Tasse - Initial API and implementation | |
4999a196 | 11 | * Geneviève Bastien - Move code to provide base classes for time graph view |
be222f56 PT |
12 | *******************************************************************************/ |
13 | ||
eeff806b | 14 | package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources; |
be222f56 | 15 | |
df2597e0 AM |
16 | import java.util.Iterator; |
17 | ||
72221aa4 | 18 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 | 19 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
df2597e0 | 20 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; |
2bdf0193 AM |
21 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; |
22 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
be222f56 PT |
23 | |
24 | /** | |
25 | * An entry, or row, in the resource view | |
26 | * | |
27 | * @author Patrick Tasse | |
28 | */ | |
3e404d51 | 29 | public class ResourcesEntry extends TimeGraphEntry implements Comparable<ITimeGraphEntry> { |
be222f56 PT |
30 | |
31 | /** Type of resource */ | |
32 | public static enum Type { | |
33 | /** Null resources (filler rows, etc.) */ | |
34 | NULL, | |
35 | /** Entries for CPUs */ | |
36 | CPU, | |
37 | /** Entries for IRQs */ | |
38 | IRQ, | |
39 | /** Entries for Soft IRQ */ | |
4999a196 GB |
40 | SOFT_IRQ |
41 | } | |
be222f56 | 42 | |
be222f56 | 43 | private final int fId; |
72221aa4 | 44 | private final @NonNull ITmfTrace fTrace; |
4999a196 GB |
45 | private final Type fType; |
46 | private final int fQuark; | |
be222f56 PT |
47 | |
48 | /** | |
4999a196 | 49 | * Constructor |
be222f56 PT |
50 | * |
51 | * @param quark | |
4999a196 | 52 | * The attribute quark matching the entry |
be222f56 | 53 | * @param trace |
4999a196 GB |
54 | * The trace on which we are working |
55 | * @param name | |
56 | * The exec_name of this entry | |
57 | * @param startTime | |
58 | * The start time of this entry lifetime | |
59 | * @param endTime | |
60 | * The end time of this entry | |
be222f56 | 61 | * @param type |
4999a196 | 62 | * The type of this entry |
be222f56 | 63 | * @param id |
4999a196 | 64 | * The id of this entry |
be222f56 | 65 | */ |
72221aa4 AM |
66 | public ResourcesEntry(int quark, @NonNull ITmfTrace trace, String name, |
67 | long startTime, long endTime, Type type, int id) { | |
1d46dc38 | 68 | super(name, startTime, endTime); |
be222f56 | 69 | fId = id; |
1d46dc38 | 70 | fTrace = trace; |
4999a196 GB |
71 | fType = type; |
72 | fQuark = quark; | |
be222f56 PT |
73 | } |
74 | ||
75 | /** | |
4999a196 | 76 | * Constructor |
be222f56 | 77 | * |
4999a196 GB |
78 | * @param trace |
79 | * The trace on which we are working | |
80 | * @param name | |
81 | * The exec_name of this entry | |
82 | * @param startTime | |
83 | * The start time of this entry lifetime | |
84 | * @param endTime | |
85 | * The end time of this entry | |
86 | * @param id | |
87 | * The id of this entry | |
be222f56 | 88 | */ |
72221aa4 AM |
89 | public ResourcesEntry(@NonNull ITmfTrace trace, String name, |
90 | long startTime, long endTime, int id) { | |
4999a196 | 91 | this(-1, trace, name, startTime, endTime, Type.NULL, id); |
be222f56 PT |
92 | } |
93 | ||
94 | /** | |
4999a196 | 95 | * Constructor |
be222f56 | 96 | * |
4999a196 GB |
97 | * @param quark |
98 | * The attribute quark matching the entry | |
99 | * @param trace | |
100 | * The trace on which we are working | |
101 | * @param startTime | |
102 | * The start time of this entry lifetime | |
103 | * @param endTime | |
104 | * The end time of this entry | |
105 | * @param type | |
106 | * The type of this entry | |
107 | * @param id | |
108 | * The id of this entry | |
be222f56 | 109 | */ |
72221aa4 AM |
110 | public ResourcesEntry(int quark, @NonNull ITmfTrace trace, |
111 | long startTime, long endTime, Type type, int id) { | |
a9f48414 MK |
112 | this(quark, trace, computeEntryName(type, id), startTime, endTime, type, id); |
113 | } | |
114 | ||
115 | private static String computeEntryName(Type type, int id) { | |
116 | if (Type.SOFT_IRQ.equals(type)) { | |
117 | return type.toString() + ' ' + id + ' ' + SoftIrqLabelProvider.getSoftIrq(id); | |
118 | } | |
119 | return type.toString() + ' ' + id; | |
be222f56 PT |
120 | } |
121 | ||
122 | /** | |
4999a196 | 123 | * Get the entry's id |
be222f56 | 124 | * |
4999a196 | 125 | * @return the entry's id |
be222f56 | 126 | */ |
4999a196 GB |
127 | public int getId() { |
128 | return fId; | |
129 | } | |
130 | ||
1d46dc38 | 131 | /** |
1cf25311 | 132 | * Get the entry's trace |
1d46dc38 | 133 | * |
1cf25311 | 134 | * @return the entry's trace |
1d46dc38 | 135 | */ |
72221aa4 | 136 | public @NonNull ITmfTrace getTrace() { |
1d46dc38 | 137 | return fTrace; |
be222f56 PT |
138 | } |
139 | ||
140 | /** | |
141 | * Get the entry Type of this entry. Uses the inner Type enum. | |
142 | * | |
143 | * @return The entry type | |
144 | */ | |
145 | public Type getType() { | |
146 | return fType; | |
147 | } | |
148 | ||
149 | /** | |
4999a196 | 150 | * Retrieve the attribute quark that's represented by this entry. |
be222f56 | 151 | * |
4999a196 | 152 | * @return The integer quark The attribute quark matching the entry |
be222f56 | 153 | */ |
4999a196 GB |
154 | public int getQuark() { |
155 | return fQuark; | |
be222f56 PT |
156 | } |
157 | ||
4999a196 GB |
158 | @Override |
159 | public boolean hasTimeEvents() { | |
160 | if (fType == Type.NULL) { | |
161 | return false; | |
be222f56 | 162 | } |
4999a196 | 163 | return true; |
be222f56 PT |
164 | } |
165 | ||
3e404d51 AM |
166 | @Override |
167 | public int compareTo(ITimeGraphEntry other) { | |
168 | if (!(other instanceof ResourcesEntry)) { | |
a9f48414 MK |
169 | /* |
170 | * Should not happen, but if it does, put those entries at the end | |
171 | */ | |
3e404d51 AM |
172 | return -1; |
173 | } | |
174 | ResourcesEntry o = (ResourcesEntry) other; | |
175 | ||
176 | /* | |
177 | * Resources entry names should all be of type "ABC 123" | |
178 | * | |
179 | * We want to filter on the Type first (the "ABC" part), then on the ID | |
180 | * ("123") in numerical order (so we get 1,2,10 and not 1,10,2). | |
181 | */ | |
182 | int ret = this.getType().compareTo(o.getType()); | |
183 | if (ret != 0) { | |
184 | return ret; | |
185 | } | |
186 | return Integer.compare(this.getId(), o.getId()); | |
be222f56 | 187 | } |
4999a196 | 188 | |
df2597e0 AM |
189 | @Override |
190 | public Iterator<@NonNull ITimeEvent> getTimeEventsIterator() { | |
191 | return super.getTimeEventsIterator(); | |
192 | } | |
193 | ||
be222f56 | 194 | } |