Search in sources :

Example 1 with ITmfSyncSequenceDiagramEvent

use of org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method moveToPage.

/**
 * Moves to a certain page.
 *
 * @param notifyAll
 *            true to broadcast time range signal to other signal handlers
 *            else false
 */
protected void moveToPage(boolean notifyAll) {
    TmfTimeRange window = null;
    fLock.lock();
    try {
        // Safety check
        if (fCurrentPage > fCheckPoints.size()) {
            return;
        }
        window = fCheckPoints.get(fCurrentPage);
    } finally {
        fLock.unlock();
    }
    if (window == null) {
        window = TmfTimeRange.ETERNITY;
    }
    fPageRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.FOREGROUND) {

        private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<>();

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
            if (sdEvent != null) {
                fSdEvent.add(sdEvent);
            }
        }

        @Override
        public void handleSuccess() {
            fillCurrentPage(fSdEvent);
            super.handleSuccess();
        }
    };
    fTrace.sendRequest(fPageRequest);
    if (notifyAll) {
        TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime());
        broadcast(new TmfWindowRangeUpdatedSignal(this, timeRange, fTrace));
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)

Example 2 with ITmfSyncSequenceDiagramEvent

use of org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method loadTrace.

/**
 * Method for loading the current selected trace into the view. Sub-class
 * need to override this method to add the view specific implementation.
 */
protected void loadTrace() {
    ITmfEventRequest indexRequest = null;
    fLock.lock();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        final Job job = new IndexingJob("Indexing " + getName() + "...");
        job.setUser(false);
        job.schedule();
        indexRequest = fIndexRequest;
        cancelOngoingRequests();
        TmfTimeRange window = TmfTimeRange.ETERNITY;
        fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {

            private ITmfTimestamp fFirstTime = null;

            private ITmfTimestamp fLastTime = null;

            private int fNbSeqEvents = 0;

            private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<>(MAX_NUM_OF_MSG);

            @Override
            public void handleData(ITmfEvent event) {
                super.handleData(event);
                ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
                ITmfTimestamp firstTime = fFirstTime;
                ITmfTimestamp lastTime = fLastTime;
                if (sdEvent != null) {
                    ++fNbSeqEvents;
                    if (firstTime == null) {
                        firstTime = event.getTimestamp();
                        fFirstTime = firstTime;
                    }
                    lastTime = event.getTimestamp();
                    fLastTime = lastTime;
                    if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
                        fLock.lock();
                        try {
                            fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                            if (fView != null) {
                                fView.updateCoolBar();
                            }
                        } finally {
                            fLock.unlock();
                        }
                        fFirstTime = null;
                    }
                    if (fNbSeqEvents > MAX_NUM_OF_MSG) {
                        // page is full
                        return;
                    }
                    fSdEvents.add(sdEvent);
                    if (fNbSeqEvents == MAX_NUM_OF_MSG) {
                        fillCurrentPage(fSdEvents);
                    }
                }
            }

            @Override
            public void handleSuccess() {
                final ITmfTimestamp firstTime = fFirstTime;
                final ITmfTimestamp lastTime = fLastTime;
                if ((firstTime != null) && (lastTime != null)) {
                    fLock.lock();
                    try {
                        fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
                        if (fView != null) {
                            fView.updateCoolBar();
                        }
                    } finally {
                        fLock.unlock();
                    }
                }
                if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
                    fillCurrentPage(fSdEvents);
                }
                super.handleSuccess();
            }

            @Override
            public void handleCompleted() {
                if (fEvents.isEmpty()) {
                    fFrame = new Frame();
                    // make sure that view is not null when setting frame
                    SDView sdView;
                    fLock.lock();
                    try {
                        sdView = fView;
                    } finally {
                        fLock.unlock();
                    }
                    if (sdView != null) {
                        sdView.setFrameSync(fFrame);
                    }
                }
                super.handleCompleted();
                job.cancel();
            }
        };
    } finally {
        fLock.unlock();
    }
    if (indexRequest != null && !indexRequest.isCompleted()) {
        indexRequest.cancel();
    }
    resetLoader();
    fTrace.sendRequest(fIndexRequest);
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) Job(org.eclipse.core.runtime.jobs.Job) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) SDView(org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)

Example 3 with ITmfSyncSequenceDiagramEvent

use of org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method fillCurrentPage.

/**
 * Fills current page with sequence diagram content.
 *
 * @param events
 *            sequence diagram events
 */
protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) {
    fLock.lock();
    try {
        fEvents = new ArrayList<>(events);
        if (fView != null && !events.isEmpty()) {
            fView.toggleWaitCursorAsync(true);
        }
    } finally {
        fLock.unlock();
    }
    final Frame frame = new Frame();
    if (!events.isEmpty()) {
        Map<String, Lifeline> nodeToLifelineMap = new HashMap<>();
        frame.setName(Messages.TmfUml2SDSyncLoader_FrameName);
        for (int i = 0; i < events.size(); i++) {
            ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
            if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) {
                Lifeline lifeline = new Lifeline();
                lifeline.setName(sdEvent.getSender());
                nodeToLifelineMap.put(sdEvent.getSender(), lifeline);
                frame.addLifeLine(lifeline);
            }
            if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) {
                Lifeline lifeline = new Lifeline();
                lifeline.setName(sdEvent.getReceiver());
                nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline);
                frame.addLifeLine(lifeline);
            }
        }
        int eventOccurence = 1;
        for (int i = 0; i < events.size(); i++) {
            ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
            // Check message filter
            if (filterMessage(sdEvent)) {
                continue;
            }
            // Set the message sender and receiver
            Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender());
            Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver());
            // Check if any of the lifelines were filtered
            if ((startLifeline == null) || (endLifeline == null)) {
                continue;
            }
            int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence());
            eventOccurence = Math.max(eventOccurence, tmp);
            startLifeline.setCurrentEventOccurrence(eventOccurence);
            endLifeline.setCurrentEventOccurrence(eventOccurence);
            TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++);
            message.setStartLifeline(startLifeline);
            message.setEndLifeline(endLifeline);
            message.setTime(sdEvent.getStartTime());
            // add the message to the frame
            frame.addMessage(message);
        }
        fLock.lock();
        try {
            if (!fView.getSDWidget().isDisposed()) {
                fView.getSDWidget().getDisplay().asyncExec(() -> {
                    fLock.lock();
                    try {
                        // check if view was disposed in the meanwhile
                        if ((fView != null) && (!fView.getSDWidget().isDisposed())) {
                            fFrame = frame;
                            fView.setFrame(fFrame);
                            if (fCurrentTime != null) {
                                moveToMessageInPage();
                            }
                            if (fFindCriteria != null) {
                                find(fFindCriteria);
                            }
                            fView.toggleWaitCursorAsync(false);
                        }
                    } finally {
                        fLock.unlock();
                    }
                });
            }
        } finally {
            fLock.unlock();
        }
    }
}
Also used : Frame(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame) HashMap(java.util.HashMap) Lifeline(org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Lifeline) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent)

Example 4 with ITmfSyncSequenceDiagramEvent

use of org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent in project tracecompass by tracecompass.

the class TmfUml2SDSyncLoader method getSequenceDiagramEvent.

/**
 * Returns sequence diagram event if details in given event are available
 * else null.
 *
 * @param tmfEvent
 *            Event to parse for sequence diagram event details
 * @return sequence diagram event if details are available else null
 */
protected ITmfSyncSequenceDiagramEvent getSequenceDiagramEvent(ITmfEvent tmfEvent) {
    // type = .*RECEIVE.* or .*SEND.*
    // content = sender:<sender name>:receiver:<receiver
    // name>,signal:<signal name>
    String eventName = tmfEvent.getName();
    if (eventName.contains(Messages.TmfUml2SDSyncLoader_EventTypeSend) || eventName.contains(Messages.TmfUml2SDSyncLoader_EventTypeReceive)) {
        Object sender = tmfEvent.getContent().getFieldValue(Object.class, NonNullUtils.checkNotNull(Messages.TmfUml2SDSyncLoader_FieldSender));
        Object receiver = tmfEvent.getContent().getFieldValue(Object.class, NonNullUtils.checkNotNull(Messages.TmfUml2SDSyncLoader_FieldReceiver));
        ITmfEventField content = tmfEvent.getContent();
        Object name = content.getFieldValue(Object.class, NonNullUtils.checkNotNull(Messages.TmfUml2SDSyncLoader_FieldSignal));
        if ((sender != null) && (receiver != null) && (name != null)) {
            ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent, sender.toString(), receiver.toString(), name.toString());
            return sdEvent;
        }
    }
    return null;
}
Also used : ITmfEventField(org.eclipse.tracecompass.tmf.core.event.ITmfEventField) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent) TmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent) ITmfSyncSequenceDiagramEvent(org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent)

Aggregations

ITmfSyncSequenceDiagramEvent (org.eclipse.tracecompass.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent)4 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)2 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)2 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)2 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)2 Frame (org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame)2 HashMap (java.util.HashMap)1 Job (org.eclipse.core.runtime.jobs.Job)1 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)1 TmfWindowRangeUpdatedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal)1 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)1 TmfSyncSequenceDiagramEvent (org.eclipse.tracecompass.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent)1 SDView (org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView)1 Lifeline (org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Lifeline)1