Revision a3b7e786

View differences:

ide/org.omnetpp.sequencechart/src/org/omnetpp/sequencechart/editors/SequenceChartContributor.java
174 174
	protected SequenceChartAction showEventNumbersAction;
175 175
	
176 176
	protected SequenceChartAction showEventOverlappingAction;
177
	protected SequenceChartAction showCriticalPathAction;
177 178
	
178 179
	protected SequenceChartAction previousBottleneckAction;
179 180
	protected SequenceChartAction nextBottleneckAction;
......
221 222
		this.filterAction = createFilterAction();
222 223
		this.showEventNumbersAction = createShowEventNumbersAction();
223 224
		this.showEventOverlappingAction = createShowEventOverlappingAction();
225
		this.showCriticalPathAction = createShowCriticalPathAction();
224 226
		this.previousBottleneckAction = createPreviousBottleneckAction();
225 227
		this.nextBottleneckAction     = createNextBottleneckAction();
226 228
		this.showBottleneckPreferencesAction = createShowBottleneckPreferencesAction();
......
358 360
                showHideSubmenu.add(separatorAction);
359 361
                showHideSubmenu.add(showEventNumbersAction);
360 362
                showHideSubmenu.add(showEventOverlappingAction);
363
                showHideSubmenu.add(showCriticalPathAction);
361 364
                showHideSubmenu.add(showMessageNamesAction);
362 365
                showHideSubmenu.add(showArrowHeadsAction);
363 366
                showHideSubmenu.add(showAxisLabelsAction);
......
431 434
        toolBarManager.add(separatorAction);
432 435
		toolBarManager.add(showEventNumbersAction);
433 436
		toolBarManager.add(showEventOverlappingAction);
437
		toolBarManager.add(showCriticalPathAction);
434 438
		toolBarManager.add(showMessageNamesAction);
435 439
        toolBarManager.add(showMessageSendsAction);
436 440
        toolBarManager.add(showSelfMessagesAction);
......
889 893
			@Override
890 894
			protected void doRun() {
891 895
				sequenceChart.setShowEventOverlapping(!sequenceChart.getShowEventOverlapping());
896
				sequenceChart.setShowCriticalPath(false);
892 897
				update();
893 898
			}
894 899

  
895 900
			@Override
896 901
			public void update() {
897 902
				setChecked(sequenceChart.getShowEventOverlapping());
903
				showCriticalPathAction.setChecked(sequenceChart.getShowCriticalPath());
898 904
			}
899 905
			@Override
900 906
			public boolean isEnabled() {
......
903 909
		};
904 910
	}
905 911

  
912
	private SequenceChartAction createShowCriticalPathAction() {
913
		return new SequenceChartAction("Show Critical Path", Action.AS_CHECK_BOX, SequenceChartPlugin.getImageDescriptor(IMAGE_SHOW_OVERLAPPING_EVENTS)) {
914
			@Override
915
			protected void doRun() {
916
				sequenceChart.setShowCriticalPath(!sequenceChart.getShowCriticalPath());
917
				sequenceChart.setShowEventOverlapping(false);
918
				update();
919
			}
920

  
921
			@Override
922
			public void update() {
923
				setChecked(sequenceChart.getShowCriticalPath());
924
				showEventOverlappingAction.setChecked(sequenceChart.getShowEventOverlapping());
925
			}
926
			@Override
927
			public boolean isEnabled() {
928
				return sequenceChart!=null && !sequenceChart.isLegacyTrace();
929
			}
930
		};
931
	}
932
	
906 933
	private SequenceChartAction createPreviousBottleneckAction() {
907 934
		return new SequenceChartAction("Jump to previous Bottleneck", Action.AS_PUSH_BUTTON, SequenceChartPlugin.getImageDescriptor(IMAGE_JUMP_TO_PREVIOUS_BOTTLENECK)) {
908 935
			@Override
ide/org.omnetpp.sequencechart/src/org/omnetpp/sequencechart/widgets/SequenceChart.java
151 151
	private static final Color SELF_EVENT_BORDER_COLOR = ColorFactory.GREEN4;
152 152
	private static final Color OVERLAPPING_EVENT_BACKGROUND_COLOR = ColorFactory.DARK_BLUE;
153 153
	private static final Color NON_OVERLAPPING_EVENT_BACKGROUND_COLOR = ColorFactory.LIGHT_BLUE;
154
	
155
	private static final Color CRITICAL_EVENT_BACKGROUND_COLOR = ColorFactory.DARK_RED;
156
	private static final Color NON_CRITICAL_EVENT_BACKGROUND_COLOR = ColorFactory.LIGHT_PINK;
157
	
154 158
	private static final Color SELF_EVENT_BACKGROUND_COLOR = ColorFactory.GREEN2;
155 159

  
156 160
	private static final Color EVENT_SELECTION_COLOR = ColorFactory.RED;
......
211 215
    private boolean showModuleMethodCalls = false; // show or hide module method call arrows
212 216
	private boolean showEventNumbers = true;
213 217
	private boolean showEventOverlapping = false;
218
	private boolean showCriticalPath = false;
214 219
    private boolean showZeroSimulationTimeRegions = true;
215 220
    private boolean showAxisLabels = true;
216 221
    private boolean showAxesWithoutEvents = false;
......
634 639
	}
635 640

  
636 641
	/**
637
	 * Shows/Hides event numbers.
642
	 * Shows/Hides event overlappings.
638 643
	 */
639 644
	public void setShowEventOverlapping(boolean showEventOverlapping) {
640 645
		this.showEventOverlapping = showEventOverlapping;
641 646
		clearCanvasCacheAndRedraw();
642 647
	}
643 648

  
649
	/**
650
	 * Returns whether critical path shown on the chart.
651
	 */
652
	public boolean getShowCriticalPath() {
653
		return showCriticalPath;
654
	}
655

  
656
	/**
657
	 * Shows/Hides critical path.
658
	 */
659
	public void setShowCriticalPath(boolean showCriticalPath) {
660
		this.showCriticalPath = showCriticalPath;
661
		clearCanvasCacheAndRedraw();
662
	}
644 663
	
645 664
	/**
646 665
	 * Shows/hides arrow heads.
......
2842 2861
			return 5;
2843 2862
		}
2844 2863
	}
2845

  
2846
	/**
2847
	 * Draws a single event at the given coordinates and axis module.
2848
	 */
2849
	private void drawEvent(Graphics graphics, long eventPtr,
2850
			int axisModuleIndex, int x, int y) {
2851
		if (!showEventOverlapping) {
2864
	
2865
	private void configureGraphics(Graphics graphics, long eventPtr) {
2866
		if (!showEventOverlapping && ! showCriticalPath) {
2852 2867
			switch (eventLengthMode) {
2853 2868
			case NONE: // Show default colors
2854 2869
				if (isInitializationEvent(eventPtr)) {
......
2888 2903
										.getEventEntry().getDuration()))), 0));
2889 2904
				break;
2890 2905
			}
2891
		} else {
2906
		} else if (showCriticalPath){ 
2907
			graphics.setForegroundColor(EVENT_BORDER_COLOR);
2908
			
2909
			if (sequenceChartFacade.isOnCriticalPath(sequenceChartFacade.IEvent_getEvent(eventPtr))) {
2910
				graphics.setBackgroundColor(CRITICAL_EVENT_BACKGROUND_COLOR);
2911
			} else {
2912
				graphics.setBackgroundColor(NON_CRITICAL_EVENT_BACKGROUND_COLOR);
2913
			}
2914
			
2915
		} else { //showEventOverlapping:
2892 2916
			graphics.setForegroundColor(EVENT_BORDER_COLOR);
2893

  
2894 2917
			if (isParallelWithSelection(eventPtr)) {
2895 2918
				graphics.setBackgroundColor(OVERLAPPING_EVENT_BACKGROUND_COLOR);
2896 2919
			} else {
2897 2920
				graphics.setBackgroundColor(NON_OVERLAPPING_EVENT_BACKGROUND_COLOR);
2898 2921
			}
2899
			/*
2900
			 * if(isOverlappingWithSelection(eventPtr)) {
2901
			 * graphics.setBackgroundColor(EVENT_BACKGROUND_COLOR); } else {
2902
			 * graphics.setBackgroundColor(SELF_EVENT_BACKGROUND_COLOR); }
2903
			 */
2904

  
2905 2922
		}
2923
	}
2924
	
2925
	/**
2926
	 * Draws a single event at the given coordinates and axis module.
2927
	 */
2928
	private void drawEvent(Graphics graphics, long eventPtr,
2929
			int axisModuleIndex, int x, int y) {
2930
	
2931
		configureGraphics(graphics, eventPtr);
2932
		
2906 2933
		int length = getEventLength(eventPtr);
2907

  
2934
		
2908 2935
		graphics.fillRectangle(x - 2, y - 3, length, 10);
2909 2936
		graphics.setLineStyle(SWT.LINE_SOLID);
2910 2937
		graphics.drawRectangle(x - 2, y - 3, length - 1, 9);
src/eventlog/event.cc
75 75
    consequences = NULL;
76 76

  
77 77
    eventLogEntries.clear();
78

  
79
    earliestProcessingTime = 0;
78 80
}
79 81

  
80 82
void Event::synchronize()
src/eventlog/event.h
59 59
        IMessageDependencyList *consequences; // message sends in this event
60 60

  
61 61
    public:
62

  
62 63
        Event(EventLog *eventLog);
63 64
        ~Event();
64 65

  
src/eventlog/ievent.h
35 35
        double cachedTimelineCoordinate;
36 36
        long cachedTimelineCoordinateSystemVersion;
37 37

  
38
        long earliestProcessingTime; //The earliest time the event can be finished, as defined in "A Critical Path Tool for Parallel Simulation Performance Optimization"
39

  
40

  
41

  
38 42
    public:
39 43
        IEvent();
40 44
        virtual ~IEvent() {}
src/eventlog/sequencechartfacade.cc
43 43
    largestDuration = -1;
44 44

  
45 45
    cachedParallelSet.clear();
46
    cachedCriticalPath.clear();
46 47
}
47 48

  
48 49
void SequenceChartFacade::synchronize(FileReader::FileChangedState change)
......
850 851
    }
851 852
    return minimum;
852 853
}
854

  
855
/*
856
 * Determines whether the event lies on the critical path
857
 */
858
bool SequenceChartFacade::isOnCriticalPath(IEvent* event) {
859
    if (cachedCriticalPath.empty()) {
860
        calculateCriticalPath();
861
    }
862
    return (cachedCriticalPath.find((ptr_t)event) != cachedCriticalPath.end());
863
}
864

  
865
/*
866
 * Calculates the critical path of the run and stores it in the set cachedCriticalPath
867
 */
868
void SequenceChartFacade::calculateCriticalPath() {
869
    long maxEarliestProcessingTime = 0;
870
    IEvent* maxEarliestProcessingTimeEvent;
871

  
872
    for (IEvent *current = eventLog->getFirstEvent(); current; current = current->getNextEvent()) {
873
        simtime_t startTime = current->getSimulationTime();
874
        if(current->getEventEndEntry()) {
875
            current->earliestProcessingTime = current->getComplexity();
876
        }
877
        for (IEvent *antecessor = eventLog->getFirstEvent(); antecessor; antecessor = antecessor->getNextEvent()) {
878
            if(antecessor==current) {
879
                break; //We have to consider earlier events only
880
            }
881
            if(antecessor->getSimulationTime() + antecessor->getEventEntry()->duration > startTime) {
882
                continue; // Check if this is an antecesor
883
            }
884
            if(antecessor->earliestProcessingTime+current->getComplexity() > current->earliestProcessingTime) {
885
                current->earliestProcessingTime = antecessor->earliestProcessingTime+current->getComplexity();
886
            }
887
        }
888
        // Memorize max event
889
        if (maxEarliestProcessingTime < current->earliestProcessingTime) {
890
            maxEarliestProcessingTime = current->earliestProcessingTime;
891
            maxEarliestProcessingTimeEvent = current;
892
        }
893
    }
894
    //Now produce the convex hull of predecessors:
895
    cachedCriticalPath.clear();
896
    for (IEvent *predecessor = maxEarliestProcessingTimeEvent; predecessor; predecessor = predecessor->getCauseEvent()) {
897
        cachedCriticalPath.insert((ptr_t)predecessor);
898
    }
899
}
900

  
src/eventlog/sequencechartfacade.h
54 54
        std::set<ptr_t> cachedParallelSet;
55 55
        IEvent* lastSelected;
56 56

  
57
        std::set<ptr_t> cachedCriticalPath;
57 58
    public:
58 59
        SequenceChartFacade(IEventLog *eventLog);
59 60
        virtual ~SequenceChartFacade() {}
......
119 120
        IEvent* getPreviousBottleneck(IEvent* e, unsigned int threshold);
120 121
        IEvent* getNextBottleneck(IEvent* e, unsigned int threshold);
121 122

  
123
        bool isOnCriticalPath(IEvent* event);
124

  
122 125
        /**
123 126
         * Timeline coordinate can be given in the range (-infinity, +infinity).
124 127
         * Simulation time will be in the range [0, lastEventSimulationTime].
......
150 153
        void getParallelSet(IEvent* event, std::set<ptr_t>* parallelSet);
151 154

  
152 155
        simtime_t getSmallestParallelEndtime(IEvent* event);
156

  
157
        void calculateCriticalPath();
153 158
};
154 159

  
155 160
NAMESPACE_END

Also available in: Unified diff