Revision a3b7e786 src/eventlog/sequencechartfacade.cc

View differences:

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

  

Also available in: Unified diff