Revision 391dcea0 src/eventlog/sequencechartfacade.cc

View differences:

src/eventlog/sequencechartfacade.cc
648 648
    }
649 649
    return largestComplexity;
650 650
}
651

  
652

  
653
IEvent* SequenceChartFacade::getPreviousBottleneck(IEvent* e, unsigned int threshold) {
654
    IEvent* next = e->getPreviousEvent();
655
    while (next) {
656
        if (isBottleneck(next,threshold)) {
657
            return next;
658
        }
659
        next = next->getPreviousEvent();
660
    }
661
    return e;
662
}
663

  
664
IEvent* SequenceChartFacade::getNextBottleneck(IEvent* e, unsigned int threshold) {
665
    IEvent* next = e->getNextEvent();
666
    while (next) {
667
        if (isBottleneck(next,threshold)) {
668
            return next;
669
        }
670
        next = next->getNextEvent();
671
    }
672
    return e;
673
}
674

  
675
/*
676
 * Returns whether an event not part of a set of parallel events with more than treshold elements.
677
 */
678
bool SequenceChartFacade::isBottleneck(IEvent* event, unsigned int threshold)
679
{
680
    return getLargestParallelSetSize(event) <= threshold;
681
}
682

  
683
unsigned int SequenceChartFacade::getLargestParallelSetSize(IEvent* event)
684
{
685
    IEvent* prev = event;
686
    std::set<ptr_t> parallelSet;
687
    parallelSet.clear();
688
    unsigned int previousSize = 0;
689
    while (prev)
690
    {
691
        previousSize = parallelSet.size();
692

  
693
        getParallelSet(prev, &parallelSet);
694

  
695
        if (parallelSet.find((ptr_t) event) == parallelSet.end())
696
        {
697
            break;
698
        }
699
        prev = prev->getPreviousEvent();
700
    }
701
    return previousSize;
702
}
703

  
704
void SequenceChartFacade::getParallelSet(IEvent* event,
705
        std::set<ptr_t>* parallelSet)
706
{
707
    IEvent* next = event->getNextEvent();
708
    simtime_t smallestParallelEndtime = getSmallestParallelEndtime(event);
709
    parallelSet->clear();
710
    parallelSet->insert((ptr_t) event);
711
    while (next)
712
    {
713
        if ((next->getSimulationTime() >= event->getSimulationTime())
714
                && (smallestParallelEndtime >= next->getSimulationTime()))
715
        {
716
            parallelSet->insert((ptr_t) next);
717
        }
718
        else
719
        {
720
            break;
721
        }
722
        next = next->getNextEvent();
723
    }
724
}
725

  
726
simtime_t SequenceChartFacade::getSmallestParallelEndtime(IEvent* event)
727
{
728
    simtime_t minimum = event->getSimulationTime()
729
            + event->getEventEntry()->duration;
730
    for (IEvent *current = eventLog->getFirstEvent(); current; current
731
            = current->getNextEvent())
732
    {
733
        if (current->getSimulationTime() >= event->getSimulationTime())
734
        {
735
            if ((current->getSimulationTime()
736
                    + current->getEventEntry()->duration)
737
                    > event->getSimulationTime())
738
            {
739
                if (minimum > (current->getSimulationTime()
740
                        + current->getEventEntry()->duration))
741
                {
742
                    minimum = current->getSimulationTime()
743
                            + current->getEventEntry()->duration;
744
                }
745
            }
746
            if (current->getSimulationTime() > minimum)
747
            { // After this, no overlapping can follow
748
                break;
749
            }
750
        }
751
    }
752
    return minimum;
753
}

Also available in: Unified diff