@Override public boolean isActive(ITimeGraphEntry element) { if (element instanceof ControlFlowEntry) { ControlFlowEntry cfe = (ControlFlowEntry) element; TmfTraceManager traceManager = TmfTraceManager.getInstance(); TmfTraceContext traceContext = traceManager.getCurrentTraceContext(); TmfTimeRange winRange = traceContext.getWindowRange(); TmfTimeRange selRange = traceContext.getSelectionRange(); /* Take precedence of selection over window range. */ long beginTS = selRange.getStartTime().getValue(); long endTS = selRange.getEndTime().getValue(); /* No selection, take window range */ if (beginTS == endTS) { beginTS = winRange.getStartTime().getValue(); endTS = winRange.getEndTime().getValue(); } ITmfTrace trace = cfe.getTrace(); ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID); if (ssq != null) { beginTS = Math.max(beginTS, ssq.getStartTime()); endTS = Math.min(endTS, ssq.getCurrentEndTime()); if (beginTS > endTS) { return false; } try { int statusQuark = ssq.getQuarkRelative(cfe.getThreadQuark(), Attributes.STATUS); /* Get the initial state at beginTS */ ITmfStateInterval currentInterval = ssq.querySingleState(beginTS, statusQuark); if (isIntervalInStateActive(currentInterval)) { return true; } /* Get the following state changes */ long ts = currentInterval.getEndTime(); while (ts != -1 && ts < endTS) { ts++; /* To "jump over" to the next state in the history */ currentInterval = ssq.querySingleState(ts, statusQuark); if (isIntervalInStateActive(currentInterval)) { return true; } ts = currentInterval.getEndTime(); } } catch (AttributeNotFoundException | StateSystemDisposedException e) { /* Ignore ... */ } } } return false; }
@Override protected @Nullable List<ITimeEvent> getEventList( @NonNull TimeGraphEntry entry, ITmfStateSystem ssq, @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) { List<ITimeEvent> eventList = null; // List<List<ITimeEvent>> List = new ArrayList<>(fullStates.size()); OPS_NEUTRON_ENTRY resourcesEntry = (OPS_NEUTRON_ENTRY) entry; int quark = resourcesEntry.getQuark(); if (resourcesEntry.getType().equals(Type.SERVICE)) { int statusQuark; try { statusQuark = ssq.getQuarkRelative(quark, "Action"); // $NON-NLS-1$ } catch (AttributeNotFoundException e) { e.printStackTrace(); return null; } eventList = new ArrayList<>(fullStates.size()); ITmfStateInterval lastInterval = prevFullState == null || statusQuark >= prevFullState.size() ? null : prevFullState.get(statusQuark); long lastStartTime = lastInterval == null ? -1 : lastInterval.getStartTime(); long lastEndTime = lastInterval == null ? -1 : lastInterval.getEndTime() + 1; for (List<ITmfStateInterval> fullState : fullStates) { if (monitor.isCanceled()) { return null; } if (statusQuark >= fullState.size()) { // No information on this CPU (yet?), skip it for now continue; } ITmfStateInterval statusInterval = fullState.get(statusQuark); int status = statusInterval.getStateValue().unboxInt(); long time = statusInterval.getStartTime(); long duration = statusInterval.getEndTime() - time + 1; if (time == lastStartTime) { continue; } if (!statusInterval.getStateValue().isNull()) { if (lastEndTime != time && lastEndTime != -1) { eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); } eventList.add(new TimeEvent(entry, time, duration, status)); } else { eventList.add(new NullTimeEvent(entry, time, duration)); } lastStartTime = time; lastEndTime = time + duration; } } return eventList; }
private static boolean isIntervalInStateActive(ITmfStateInterval ival) { int value = ival.getStateValue().unboxInt(); /* An entry is only active when running */ if (value == StateValues.PROCESS_STATUS_RUN_USERMODE || value == StateValues.PROCESS_STATUS_RUN_SYSCALL || value == StateValues.PROCESS_STATUS_INTERRUPTED) { return true; } return false; }
/** * The method to fill up the stateInfo (passed on from the Current State Tree when it does a query * on the SHT). We'll replace the data in that vector with whatever relevant we can find from this * node * * @param stateInfo The same stateInfo that comes from SHT's doQuery() * @param t The timestamp for which the query is for. Only return intervals that intersect t. * @throws TimeRangeException If 't' is invalid */ public void writeInfoFromNode(List<ITmfStateInterval> stateInfo, long t) throws TimeRangeException { /* This is from a state system query, we are "reading" this node */ fRwl.readLock().lock(); try { for (int i = getStartIndexFor(t); i < fIntervals.size(); i++) { /* * Now we only have to compare the Start times, since we now the * End times necessarily fit. * * Second condition is to ignore new attributes that might have * been created after stateInfo was instantiated (they would be * null anyway). */ ITmfStateInterval interval = fIntervals.get(i); if (interval.getStartTime() <= t && interval.getAttribute() < stateInfo.size()) { stateInfo.set(interval.getAttribute(), interval); } } } finally { fRwl.readLock().unlock(); } }