lttng: Add Trace Viewer RCP application
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeGraphEntry.java
CommitLineData
4999a196
GB
1/*******************************************************************************
2 * Copyright (c) 2012, 2013 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
14package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
15
16import java.util.ArrayList;
17import java.util.Iterator;
18import java.util.List;
19
20import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21
22/**
23 * An entry for use in the time graph views
24 *
25 * @since 2.1
26 */
27public class TimeGraphEntry implements ITimeGraphEntry {
28
29 /** Id field that may be used by views, so they don't have to extend this class if they don't need to */
30 private final int fEntryId;
31 private final ITmfTrace fTrace;
32
33 /** Entry's parent */
34 private TimeGraphEntry fParent = null;
35
36 /** List of child entries */
37 private final List<TimeGraphEntry> fChildren = new ArrayList<TimeGraphEntry>();
38
39 /** Name of this entry (text to show) */
40 private String fName;
41 private long fStartTime = -1;
42 private long fEndTime = -1;
43 private List<ITimeEvent> fEventList = new ArrayList<ITimeEvent>();
44 private List<ITimeEvent> fZoomedEventList = null;
45
46 /**
47 * Constructor
48 *
49 * @param entryid
50 * Some id attribute for the entry whose state is shown on this
51 * row
52 * @param trace
53 * The trace on which we are working
54 * @param name
55 * The exec_name of this entry
56 * @param startTime
57 * The start time of this process's lifetime
58 * @param endTime
59 * The end time of this process
60 */
61 public TimeGraphEntry(int entryid, ITmfTrace trace, String name, long startTime, long endTime) {
62 fEntryId = entryid;
63 fTrace = trace;
64 fName = name;
65 fStartTime = startTime;
66 fEndTime = endTime;
67 }
68
69 // ---------------------------------------------
70 // Getters and setters
71 // ---------------------------------------------
72
73 @Override
74 public ITimeGraphEntry getParent() {
75 return fParent;
76 }
77
78 /**
79 * Sets the entry's parent
80 *
81 * @param entry The new parent entry
82 */
83 protected void setParent(TimeGraphEntry entry) {
84 fParent = entry;
85 }
86
87 @Override
88 public boolean hasChildren() {
89 return fChildren.size() > 0;
90 }
91
92 @Override
93 public List<TimeGraphEntry> getChildren() {
94 return fChildren;
95 }
96
97 @Override
98 public String getName() {
99 return fName;
100 }
101
102 /**
103 * Update the entry name
104 *
105 * @param name
106 * the updated entry name
107 */
108 public void setName(String name) {
109 fName = name;
110 }
111
112 @Override
113 public long getStartTime() {
114 return fStartTime;
115 }
116
117 @Override
118 public long getEndTime() {
119 return fEndTime;
120 }
121
122 @Override
123 public boolean hasTimeEvents() {
124 return true;
125 }
126
127 @Override
128 public Iterator<ITimeEvent> getTimeEventsIterator() {
129 if (hasTimeEvents()) {
130 return new EventIterator(fEventList, fZoomedEventList);
131 }
132 return null;
133 }
134
135 @Override
136 public Iterator<ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
137 if (!hasTimeEvents()) {
138 return null;
139 }
140 return new EventIterator(fEventList, fZoomedEventList, startTime, stopTime);
141 }
142
143 /**
144 * Get the id of this entry
145 *
146 * @return The entry id
147 */
148 public int getEntryId() {
149 return fEntryId;
150 }
151
152 /**
153 * Get the trace object
154 *
155 * @return The trace
156 */
157 public ITmfTrace getTrace() {
158 return fTrace;
159 }
160
161 /**
162 * Add an event to this process's timeline
163 *
164 * @param event
165 * The time event
166 */
167 public void addEvent(ITimeEvent event) {
168 long start = event.getTime();
169 long end = start + event.getDuration();
170 synchronized (fEventList) {
171 fEventList.add(event);
172 if (fStartTime == -1 || start < fStartTime) {
173 fStartTime = start;
174 }
175 if (fEndTime == -1 || end > fEndTime) {
176 fEndTime = end;
177 }
178 }
179 }
180
181 /**
182 * Set the general event list of this entry.
183 *
184 * Creates a copy of the list to avoid the caller still modifying the list
185 *
186 * @param eventList
187 * The list of time events
188 */
189 public void setEventList(List<ITimeEvent> eventList) {
190 fEventList = new ArrayList<ITimeEvent>(eventList);
191 }
192
193 /**
194 * Set the zoomed event list of this entry.
195 *
196 * Creates a copy of the list to avoid the caller still modifying the list
197 *
198 * @param eventList
199 * The list of time events
200 */
201 public void setZoomedEventList(List<ITimeEvent> eventList) {
202 fZoomedEventList = new ArrayList<ITimeEvent>(eventList);
203 }
204
205 /**
206 * Add a child entry to this one (to show relationships between processes as
207 * a tree)
208 *
209 * @param child
210 * The child entry
211 */
212 public void addChild(TimeGraphEntry child) {
213 child.fParent = this;
214 fChildren.add(child);
215 }
216
217}
This page took 0.032153 seconds and 5 git commands to generate.