Package: TraceFileRunner

TraceFileRunner

nameinstructionbranchcomplexitylinemethod
TraceFileRunner(TraceData, ConjectureData)
M: 59 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
drawArchitecture(GenericTabItem)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
drawCpu(GenericTabItem, Long, Long)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
drawOverview(GenericTabItem, Long)
M: 56 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
drawView(GenericTabItem, Long, TraceEventViewer, EventFilter)
M: 126 C: 0
0%
M: 19 C: 0
0%
M: 11 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
getCpuIds()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCpuName(Long)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * RT Trace Viewer Plugin
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.rttraceviewer.view;
23:
24: import java.util.HashMap;
25: import java.util.List;
26: import java.util.Map;
27: import java.util.Vector;
28:
29: import org.overture.ide.plugins.rttraceviewer.data.Conjecture;
30: import org.overture.ide.plugins.rttraceviewer.data.ConjectureData;
31: import org.overture.ide.plugins.rttraceviewer.data.TraceCPU;
32: import org.overture.ide.plugins.rttraceviewer.data.TraceData;
33: import org.overture.ide.plugins.rttraceviewer.data.TraceEventManager;
34: import org.overture.ide.plugins.rttraceviewer.data.TraceThread;
35: import org.overture.ide.plugins.rttraceviewer.draw.ArchitectureViewer;
36: import org.overture.ide.plugins.rttraceviewer.draw.CpuEventViewer;
37: import org.overture.ide.plugins.rttraceviewer.draw.DummyViewer;
38: import org.overture.ide.plugins.rttraceviewer.draw.OverviewEventViewer;
39: import org.overture.ide.plugins.rttraceviewer.draw.TraceEventViewer;
40: import org.overture.ide.plugins.rttraceviewer.event.BusMessageEventHandler;
41: import org.overture.ide.plugins.rttraceviewer.event.BusMessageReplyEventHandler;
42: import org.overture.ide.plugins.rttraceviewer.event.CPUEventFilter;
43: import org.overture.ide.plugins.rttraceviewer.event.EventFilter;
44: import org.overture.ide.plugins.rttraceviewer.event.EventHandler;
45: import org.overture.ide.plugins.rttraceviewer.event.OperationEventHandler;
46: import org.overture.ide.plugins.rttraceviewer.event.OverviewEventFilter;
47: import org.overture.ide.plugins.rttraceviewer.event.ThreadEventHandler;
48: import org.overture.ide.plugins.rttraceviewer.event.ThreadSwapEventHandler;
49: import org.overture.interpreter.messages.rtlog.nextgen.INextGenEvent;
50: import org.overture.interpreter.messages.rtlog.nextgen.NextGenBusMessageEvent;
51: import org.overture.interpreter.messages.rtlog.nextgen.NextGenBusMessageReplyRequestEvent;
52: import org.overture.interpreter.messages.rtlog.nextgen.NextGenOperationEvent;
53: import org.overture.interpreter.messages.rtlog.nextgen.NextGenThreadEvent;
54: import org.overture.interpreter.messages.rtlog.nextgen.NextGenThreadSwapEvent;
55:
56: public class TraceFileRunner
57: {
58:         private TraceData data;
59:         private Map<Class<?>, EventHandler> eventHandlers;
60:         private ConjectureData conjectures;
61:         
62:         public TraceFileRunner(TraceData data, ConjectureData conjectures)
63:         {
64:                 this.data = data;
65:                 this.eventHandlers = new HashMap<Class<?>, EventHandler>();
66:                 this.conjectures = conjectures;
67:                 
68:                 //Register Events
69:                 eventHandlers.put(NextGenThreadEvent.class, new ThreadEventHandler(data));
70:                 eventHandlers.put(NextGenThreadSwapEvent.class, new ThreadSwapEventHandler(data));
71:                 eventHandlers.put(NextGenOperationEvent.class, new OperationEventHandler(data));
72:                 eventHandlers.put(NextGenBusMessageEvent.class, new BusMessageEventHandler(data));
73:                 eventHandlers.put(NextGenBusMessageReplyRequestEvent.class, new BusMessageReplyEventHandler(data));
74:         }
75:
76:         public void drawArchitecture(GenericTabItem tab) throws Exception
77:         {
78:                 data.reset();
79:                 ArchitectureViewer viewer = new ArchitectureViewer();
80:                 viewer.drawArchitecture(tab, data.getCPUs(), data.getBuses());        
81:         }
82:
83:         public void drawOverview(GenericTabItem tab, Long eventStartTime)
84:                         throws Exception
85:         {
86:                 data.reset();
87:                 TraceEventViewer viewer = new OverviewEventViewer();
88:                 viewer.drawStaticItems(tab, data.getCPUs(), data.getBuses());
89:                 
90:                 drawView(tab, eventStartTime, viewer, new OverviewEventFilter());
91:                 
92:                 //FIXME - MVQ: Dirty hack in order to extend the blue line (Active/Blocked) to the end of canvas.
93:•                for(TraceCPU cpu : data.getCPUs())
94:                 {
95:                         TraceThread tThread = null;
96:                         Long threadId = cpu.getCurrentThread();
97:•                        if(threadId != null)
98:                         {
99:                                 tThread = data.getThread(threadId);
100:                         }
101:                         ((OverviewEventViewer)viewer).updateCpu(tab, cpu, tThread);
102:                 }
103:         }
104:
105:         public void drawCpu(GenericTabItem tab, Long cpuId, Long eventStartTime)
106:                         throws Exception
107:         {
108:                 data.reset();
109:                 TraceEventViewer viewer = new CpuEventViewer();
110:                 viewer.drawStaticItems(tab, null, data.getConnectedBuses(cpuId));
111:                 
112:                 drawView(tab, eventStartTime, viewer, new CPUEventFilter(cpuId));                
113:         }
114:         
115:         private void drawView(GenericTabItem tab, Long eventStartTime, TraceEventViewer viewer, EventFilter filter) throws Exception
116:         {                
117:                 //Draw events as long as there is room and time
118:                 TraceEventManager eventManager = data.getEventManager();
119:                 TraceEventViewer dummyViewer = new DummyViewer();
120:                 TraceEventViewer currentView = null;
121:                 List<INextGenEvent> events = eventManager.getEvents(0L); //First series of events
122:                 
123:•                while(!tab.isCanvasOverrun() && events != null)
124:                 {
125:                         //TODO: Remove DUMMY. Introduced to hack time travels
126:•                        currentView = (eventManager.getCurrentEventTime() < eventStartTime) ? dummyViewer : viewer;
127:                         
128:                         //Draw conjectures on the overview
129:•                        if(viewer instanceof OverviewEventViewer)
130:                         {
131:                                 Vector<Conjecture> cons = conjectures.getConjecture(eventManager.getCurrentEventTime());
132:                                 
133:•                                for(Conjecture c : cons)
134:                                 {
135:                                         TraceCPU cpu = data.getCpuFromThreadId(c.getThreadID());
136:•                                        switch(c.getType())
137:                                         {
138:                                                 case SOURCE: ((OverviewEventViewer)viewer).drawSourceConjecture(tab, cpu, c.getName()); break;
139:                                                 case DESTINATION: ((OverviewEventViewer)viewer).drawDestinationConjecture(tab, cpu, c.getName()); break;
140:                                         }
141:                                 }
142:                         }
143:                         
144:•                        for(INextGenEvent event : events)
145:                         {        
146:•                                if(filter.apply(event)) {
147:                                         EventHandler handler = eventHandlers.get(event.getClass());
148:                                         handler.handleEvent(event, currentView, tab);
149:                                 }                                
150:                         }
151:
152:                         events = eventManager.getEvents();
153:                 }
154:                 
155:                 //Draw a final time marker indicating the time for the next (not drawn) series of events
156:•                if(events != null) {
157:                         viewer.drawTimeMarker(tab, events.get(0).getTime().getAbsoluteTime());
158:                 }
159:                                 
160:                 //Finally add timelines
161:                 viewer.drawTimelines(tab);
162:         }
163:         
164:         public Vector<Long> getCpuIds()
165:         {
166:                 return data.getOrderedCpus();
167:         }
168:
169:         public String getCpuName(Long cpuId)
170:         {
171:                 return data.getCPU(cpuId).getName();
172:         }
173: }