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