Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / widgetStubs / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / test / stub / model / TraceModelImplFactory.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model;
13
14 import java.util.Date;
15
16 @SuppressWarnings("nls")
17 public class TraceModelImplFactory {
18
19 // ========================================================================
20 // Data
21 // ========================================================================
22 private int count = 0;
23 private TraceStrings[] traceNames;
24 private static final long msTons = 1000000;
25 private Long timeRef = new Date().getTime() * msTons;
26
27 // ========================================================================
28 // Constructor
29 // ========================================================================
30 public TraceModelImplFactory() {
31 traceNames = new TraceStrings[17];
32 loadTraceNameStrings();
33 }
34
35 // ========================================================================
36 // Methods
37 // ========================================================================
38 public TraceImpl[] createTraces() {
39 TraceImpl trace;
40 TraceImpl[] traceArr = new TraceImpl[17];
41 for (int i = 0; i < traceArr.length; i++) {
42 trace = new TraceImpl(traceNames[i].name, timeRef, timeRef + 40,
43 traceNames[i].classNmme);
44 count = i;
45 createEvents(trace);
46 traceArr[i] = trace;
47 }
48 return traceArr;
49 }
50
51 /**
52 * 5000 Events per Trace.
53 * @param number
54 * @return
55 */
56 public TraceImpl[] createLargeTraces(int number) {
57 TraceImpl trace;
58 TraceImpl[] traceArr = new TraceImpl[number];
59 for (int i = 0; i < traceArr.length; i++) {
60 int count = i%17;
61 long sTime = i * (long) 1E6;
62 trace = new TraceImpl(traceNames[count].name, sTime , sTime + 20000,
63 traceNames[count].classNmme);
64 create5000Events(trace);
65 traceArr[i] = trace;
66 }
67 return traceArr;
68 }
69
70 private void create5000Events(TraceImpl trace) {
71 EventImpl event;
72 Long eventTime;
73 int numEvents = 5000;
74 long sTime = trace.getStartTime();
75 long eTime = trace.getStopTime();
76 long duration = (long) ((eTime - sTime)/numEvents);
77 for (int i = 0; i < numEvents; i++) {
78 eventTime = sTime + (i * duration);
79 // eventTime = timeRef + (5 * (count % 4) + (5 * (int) (i/2) ));
80 // System.out.println("Trace: " + trace.getName() + " EventTime: "
81 // + eventTime);
82 // duration = i * msTons + (long) ((i % 4));
83
84 event = new EventImpl(eventTime, trace, getEventType(i%16));
85 event.setDuration(duration);
86 trace.addTraceEvent(event);
87 }
88 }
89
90 private void createEvents(TraceImpl trace) {
91 EventImpl event;
92 Long eventTime;
93 int numEvents = 17;
94 long duration = 0;
95 for (int i = 0; i < numEvents; i++) {
96 eventTime = timeRef + msTons * i + (5 * msTons * count) + (5 * i);
97 duration = msTons + i * msTons + (long) ((i % 4));
98 // duration = i + (long) ((i % 4));
99 event = new EventImpl(eventTime, trace, getEventType(i));
100 event.setDuration(duration);
101 trace.addTraceEvent(event);
102 }
103 }
104
105 private EventImpl.Type getEventType(int val) {
106 if (EventImpl.Type.ALARM.ordinal() == val)
107 return EventImpl.Type.ALARM;
108 if (EventImpl.Type.ERROR.ordinal() == val)
109 return EventImpl.Type.ERROR;
110 if (EventImpl.Type.EVENT.ordinal() == val)
111 return EventImpl.Type.EVENT;
112 if (EventImpl.Type.INFORMATION.ordinal() == val)
113 return EventImpl.Type.INFORMATION;
114 if (EventImpl.Type.TIMEADJUSTMENT.ordinal() == val)
115 return EventImpl.Type.TIMEADJUSTMENT;
116 if (EventImpl.Type.WARNING.ordinal() == val)
117 return EventImpl.Type.WARNING;
118 if (EventImpl.Type.INFO1.ordinal() == val)
119 return EventImpl.Type.INFO1;
120 if (EventImpl.Type.INFO2.ordinal() == val)
121 return EventImpl.Type.INFO2;
122 if (EventImpl.Type.INFO3.ordinal() == val)
123 return EventImpl.Type.INFO3;
124 if (EventImpl.Type.INFO4.ordinal() == val)
125 return EventImpl.Type.INFO4;
126 if (EventImpl.Type.INFO5.ordinal() == val)
127 return EventImpl.Type.INFO5;
128 if (EventImpl.Type.INFO6.ordinal() == val)
129 return EventImpl.Type.INFO6;
130 if (EventImpl.Type.INFO7.ordinal() == val)
131 return EventImpl.Type.INFO7;
132 if (EventImpl.Type.INFO8.ordinal() == val)
133 return EventImpl.Type.INFO8;
134 if (EventImpl.Type.INFO9.ordinal() == val)
135 return EventImpl.Type.INFO9;
136 return EventImpl.Type.UNKNOWN;
137 }
138
139 private void loadTraceNameStrings() {
140 traceNames[0] = new TraceStrings();
141 traceNames[0].name = "TE Log - TATA BSC11";
142 traceNames[0].classNmme = "All Boards";
143
144 traceNames[1] = new TraceStrings();
145 traceNames[1].name = "System Log";
146 traceNames[1].classNmme = "BSC11";
147
148 traceNames[2] = new TraceStrings();
149 traceNames[2].name = "Alarm Log";
150 traceNames[2].classNmme = "BSC11";
151
152 traceNames[3] = new TraceStrings();
153 traceNames[3].name = "Events Log";
154 traceNames[3].classNmme = "BSC 11";
155
156 traceNames[4] = new TraceStrings();
157 traceNames[4].name = "CPU Load";
158 traceNames[4].classNmme = "All Boards";
159
160 traceNames[5] = new TraceStrings();
161 traceNames[5].name = "Performance Log";
162 traceNames[5].classNmme = "BSC11";
163
164 traceNames[6] = new TraceStrings();
165 traceNames[6].name = "TE Log - TATA BSC14";
166 traceNames[6].classNmme = "Board 24";
167
168 traceNames[7] = new TraceStrings();
169 traceNames[7].name = "TE Log - TATA BSC14";
170 traceNames[7].classNmme = "Board 23";
171
172 traceNames[8] = new TraceStrings();
173 traceNames[8].name = "TE Log - TATA BSC14";
174 traceNames[8].classNmme = "Board 11";
175
176 traceNames[9] = new TraceStrings();
177 traceNames[9].name = "TE Log - TATA BSC14";
178 traceNames[9].classNmme = "Board 14, SPO";
179
180 traceNames[10] = new TraceStrings();
181 traceNames[10].name = "INFO 1";
182 traceNames[10].classNmme = "All Boards";
183
184 traceNames[11] = new TraceStrings();
185 traceNames[11].name = "INFO2";
186 traceNames[11].classNmme = "BSC11";
187
188 traceNames[12] = new TraceStrings();
189 traceNames[12].name = "INFO3";
190 traceNames[12].classNmme = "Board 24";
191
192 traceNames[13] = new TraceStrings();
193 traceNames[13].name = "MISC1";
194 traceNames[13].classNmme = "Board 23";
195
196 traceNames[14] = new TraceStrings();
197 traceNames[14].name = "MISC2";
198 traceNames[14].classNmme = "Board 11";
199
200 traceNames[15] = new TraceStrings();
201 traceNames[15].name = "MISC3";
202 traceNames[15].classNmme = "Board 23";
203
204 traceNames[16] = new TraceStrings();
205 traceNames[16].name = "MISC4";
206 traceNames[16].classNmme = "Board 11";
207
208 }
209
210 // ========================================================================
211 // Inner Class
212 // ========================================================================
213 private static class TraceStrings {
214 public String name = "";
215 public String classNmme = name + " class";
216 }
217 }
This page took 0.036103 seconds and 6 git commands to generate.