use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TextTraceTest method setUp.
// ------------------------------------------------------------------------
// Housekeeping
// ------------------------------------------------------------------------
@BeforeClass
public static void setUp() throws Exception {
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss");
defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT);
defaultPreferences.put(ITmfTimePreferencesConstants.LOCALE, Locale.US.toLanguageTag());
TmfTimestampFormat.updateDefaultFormats();
if (fTrace == null) {
try {
URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(PATH), null);
URI uri = FileLocator.toFileURL(location).toURI();
fTestFile = new File(uri);
fTrace = new SyslogTrace();
IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(PATH));
fTrace.initTrace(resource, uri.getPath(), SyslogEvent.class);
// Dummy request to force the trace indexing
TmfEventRequest request = new TmfEventRequest(SyslogEvent.class, TmfTimeRange.ETERNITY, 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {
};
fTrace.sendRequest(request);
request.waitForCompletion();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventTableDataProvider method fetchIndex.
/**
* Find the index in the table of an event using the rank in the trace or
* the timestamp value. It will take any filter into consideration.
*
* @param fetchParameters
* Map of parameters that contain the filter applied to the
* table, if any. Everything else is ignored.
* @param traceRank
* Rank of the event in the trace
* @param timeBegin
* Timestamp of the event
* @param monitor
* Progress monitor
* @return Index in the table
*/
public TmfModelResponse<List<Long>> fetchIndex(Map<String, Object> fetchParameters, long traceRank, long timeBegin, @Nullable IProgressMonitor monitor) {
@Nullable ITmfFilter filter = extractFilter(fetchParameters);
long rank;
if (traceRank == -1) {
ITmfContext context = getTrace().seekEvent(TmfTimestamp.fromNanos(timeBegin));
rank = context.getRank();
} else {
rank = traceRank;
}
if (filter == null) {
return new TmfModelResponse<>(Collections.singletonList(rank), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
applyFilter(filter);
Entry<Long, Long> nearestEntry = fRankToIndexMap.floorEntry(rank);
long startingIndex = nearestEntry != null ? nearestEntry.getValue() : 0L;
long startingRank = nearestEntry != null ? nearestEntry.getKey() : 0L;
List<Long> foundIndex = new ArrayList<>();
TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startingRank, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {
private long currentIndex = startingIndex;
private long fRank = startingRank;
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
if (monitor != null && monitor.isCanceled()) {
cancel();
return;
}
if (fRank >= rank) {
foundIndex.add(currentIndex);
done();
return;
}
if (filter.matches(event)) {
currentIndex++;
}
fRank++;
}
};
getTrace().sendRequest(request);
try {
request.waitForCompletion();
} catch (InterruptedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
}
return new TmfModelResponse<>(foundIndex, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest in project tracecompass by tracecompass.
the class TmfEventsCache method getFilteredEventIndex.
/**
* Get the cache index of an event from his rank in the trace. This will
* take in consideration any filter that might be applied.
*
* @param rank
* The rank of the event in the trace
* @return The position (index) this event should use once cached
*/
public int getFilteredEventIndex(final long rank) {
int current;
int startRank;
TmfEventRequest request;
final ITmfFilter filter = fFilter;
synchronized (this) {
int start = 0;
int end = fFilterIndex.size();
if ((fCacheEndIndex - fCacheStartIndex) > 1) {
if (rank < fCache[0].rank) {
end = (fCacheStartIndex / fCacheSize) + 1;
} else if (rank > fCache[fCacheEndIndex - fCacheStartIndex - 1].rank) {
start = fCacheEndIndex / fCacheSize;
} else {
for (int i = 0; i < (fCacheEndIndex - fCacheStartIndex); i++) {
if (fCache[i].rank >= rank) {
return fCacheStartIndex + i;
}
}
return fCacheEndIndex;
}
}
current = (start + end) / 2;
while (current != start) {
if (rank < fFilterIndex.get(current)) {
end = current;
current = (start + end) / 2;
} else {
start = current;
current = (start + end) / 2;
}
}
startRank = fFilterIndex.isEmpty() ? 0 : fFilterIndex.get(current);
}
final int index = current * fCacheSize;
class DataRequest extends TmfEventRequest {
ITmfFilter requestFilter;
TmfCollapseFilter requestCollapsedFilter;
int requestRank;
int requestIndex;
DataRequest(Class<? extends ITmfEvent> dataType, ITmfFilter reqFilter, int start, int nbRequested) {
super(dataType, TmfTimeRange.ETERNITY, start, nbRequested, TmfEventRequest.ExecutionType.FOREGROUND);
requestFilter = reqFilter;
requestRank = start;
requestIndex = index;
requestCollapsedFilter = fCollapseFilterEnabled ? new TmfCollapseFilter() : null;
}
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
if (isCancelled()) {
return;
}
if (requestRank >= rank) {
cancel();
return;
}
requestRank++;
if (requestFilter.matches(event)) {
if (requestCollapsedFilter == null || requestCollapsedFilter.matches(event)) {
requestIndex++;
}
}
}
public int getFilteredIndex() {
return requestIndex;
}
}
request = new DataRequest(ITmfEvent.class, filter, startRank, ITmfEventRequest.ALL_DATA);
((ITmfEventProvider) fTrace).sendRequest(request);
try {
request.waitForCompletion();
return ((DataRequest) request).getFilteredIndex();
} catch (InterruptedException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Filter request interrupted!", e);
Thread.currentThread().interrupt();
}
return 0;
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest 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));
}
}
use of org.eclipse.tracecompass.tmf.core.request.TmfEventRequest 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);
}
Aggregations