From 98029bc99e2208e5001191f63f7297fe5519b167 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Wed, 30 Sep 2009 14:09:28 +0000 Subject: [PATCH] - Tweaked the FW a little to accommodate LTTng indexing - Added event cache to the EventsView - Added some troubleshooting code (not all enabled) --- .../lttng/ui/views/project/ProjectView.java | 18 ++- .../lttng/stubs/LTTngEventParserStub.java | 52 +++++--- .../lttng/stubs/LTTngTimestampStub.java | 5 + .../lttng/stubs/LTTngTraceStub.java | 9 +- .../lttng/event/LttngTimestamp.java | 5 + .../linuxtools/lttng/trace/LTTngTrace.java | 9 +- .../tmf/ui/views/TmfEventsView.java | 55 +++++--- .../linuxtools/tmf/event/TmfTimestamp.java | 11 +- .../linuxtools/tmf/trace/TmfExperiment.java | 124 ++++++++---------- .../linuxtools/tmf/trace/TmfTrace.java | 124 ++++++++++++++---- .../linuxtools/tmf/trace/TmfTraceContext.java | 32 +++-- 11 files changed, 277 insertions(+), 167 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java index fdb1a133a9..04cfc1df32 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/project/ProjectView.java @@ -76,8 +76,10 @@ public class ProjectView extends TmfView { * This view needs to react to workspace resource changes */ public ProjectView() { + // TmfTraceContext.init(); - fWorkspace = ResourcesPlugin.getWorkspace(); + + fWorkspace = ResourcesPlugin.getWorkspace(); fResourceChangeListener = new IResourceChangeListener() { public void resourceChanged(IResourceChangeEvent event) { if (event.getType() == IResourceChangeEvent.POST_CHANGE) { @@ -134,20 +136,24 @@ public class ProjectView extends TmfView { * * TODO: Tie the proper parser to the trace */ - private void selectExperiment(Folder folder) { - String expId = folder.getName(); + // FIXME: Troubleshooting hack - start + private boolean waitForCompletion = true; + // FIXME: Troubleshooting hack - end + + private void selectExperiment(Folder folder) { + String expId = folder.getName(); if (fExperiment != null) fExperiment.dispose(); - fExperiment = new TmfExperiment(expId, new ITmfTrace[] { }); + fExperiment = new TmfExperiment(expId, new ITmfTrace[] { }, waitForCompletion); try { for (IResource res : folder.members()) { String traceId = Platform.getLocation() + res.getFullPath().toOSString(); - ITmfTrace trace = new LTTngTrace(traceId); + ITmfTrace trace = new LTTngTrace(traceId, waitForCompletion); fExperiment.addTrace(trace); } broadcastSignal(new TmfExperimentSelectedSignal(this, fExperiment)); } catch (FileNotFoundException e) { - // TODO: Why not tell the user? + // TODO: Why not tell the user? He would appreciate... // e.printStackTrace(); return; } catch (Exception e) { diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java index 8aa16fe27e..2b278095cd 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java @@ -80,28 +80,28 @@ public class LTTngEventParserStub implements ITmfEventParser { String name = eventStream.getName(); name = name.substring(name.lastIndexOf('/') + 1); - synchronized(stream) { + synchronized(stream) { long location = 0; if (context != null) location = (Long) (context.getLocation()); stream.seek(location); - try { - long ts = stream.readLong(); - String source = stream.readUTF(); - String type = stream.readUTF(); - @SuppressWarnings("unused") - int reference = stream.readInt(); + try { + // Read the individual fields + long ts = stream.readLong(); + String source = stream.readUTF(); + String type = stream.readUTF(); + @SuppressWarnings("unused") + int reference = stream.readInt(); + + // Read the event parts int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); String[] fields = new String[typeIndex]; for (int i = 0; i < typeIndex; i++) { fields[i] = stream.readUTF(); } - // Update the context - context.setLocation(stream.getFilePointer()); - context.incrIndex(); - + // Format the content from the individual fields String content = "["; if (typeIndex > 0) { content += fields[0]; @@ -111,14 +111,28 @@ public class LTTngEventParserStub implements ITmfEventParser { } content += "]"; - TmfEvent event = new TmfEvent( - new LTTngTimestampStub(ts), - new TmfEventSource(source), - new TmfEventType(type, fFormats[typeIndex]), - new TmfEventContent(content, fFormats[typeIndex]), - new TmfEventReference(name)); - return event; - } catch (EOFException e) { + // Update the context + context.setLocation(stream.getFilePointer()); + context.incrIndex(); + try { + long ts2 = stream.readLong(); + context.setTimestamp(new LTTngTimestampStub(ts2)); + } catch (EOFException e) { + context.setTimestamp(null); + } + + // Create the event + TmfEvent event = new TmfEvent( + new LTTngTimestampStub(ts), + new TmfEventSource(source), + new TmfEventType(type, fFormats[typeIndex]), + new TmfEventContent(content, fFormats[typeIndex]), + new TmfEventReference(name)); + + return event; + + } catch (EOFException e) { + context.setTimestamp(null); } } return null; diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java index 508026d706..77cdee6a59 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java @@ -12,6 +12,11 @@ import org.eclipse.linuxtools.tmf.event.TmfTimestamp; public class LTTngTimestampStub extends TmfTimestamp { /** + * + */ + private static final long serialVersionUID = 216576768443708259L; + + /** * @param value * @param scale * @param precision diff --git a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java index 2e151b32da..e9cf908507 100644 --- a/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java @@ -85,6 +85,9 @@ public class LTTngTraceStub extends TmfTrace { synchronized(fTrace) { fTrace.seek((location != null) ? (Long) location : 0); context = new TmfTraceContext(getCurrentLocation(), null, 0); + TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), null, 0); + TmfEvent event = parseEvent(context2); + context.setTimestamp(event.getTimestamp()); } } catch (IOException e) { // TODO Auto-generated catch block @@ -115,9 +118,9 @@ public class LTTngTraceStub extends TmfTrace { try { // paserNextEvent updates the context TmfEvent event = fParser.parseNextEvent(this, context); - if (event != null) { - context.setTimestamp(event.getTimestamp()); - } +// if (event != null) { +// context.setTimestamp(event.getTimestamp()); +// } return event; } catch (IOException e) { diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java index 067864c849..5f4834ebb7 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngTimestamp.java @@ -24,6 +24,11 @@ import org.eclipse.linuxtools.tmf.event.TmfTimestamp; public class LttngTimestamp extends TmfTimestamp { /** + * + */ + private static final long serialVersionUID = -7016853105162491273L; + + /** * Constructor with parameters * * @param newEventTime JniTime as long, unit expected to be nanoseconds. diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java index 158769fe1d..62f1189f71 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java @@ -66,7 +66,7 @@ public class LTTngTrace extends TmfTrace { * @see org.eclipse.linuxtools.lttng.jni.JniTrace */ public LTTngTrace(String path) throws Exception { - this(path, true); + this(path, false); } /** @@ -233,8 +233,11 @@ public class LTTngTrace extends TmfTrace { else { System.out.println("ERROR : Location not instance of TmfTimestamp"); } - - return new TmfTraceContext(timestamp, timestamp, 0); + + // FIXME: LTTng hack - start +// return new TmfTraceContext(timestamp, timestamp, 0); // Original + return new TmfTraceContext(timestamp, timestamp, -1); // Hacked + // FIXME: LTTng hack - end } /** diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java index 388773d8ad..eb60620e75 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java @@ -135,17 +135,23 @@ public class TmfEventsView extends TmfView { fTable.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; - int index = fTable.indexOf(item); - final TmfEvent[] evt = new TmfEvent[1]; - TmfDataRequest request = new TmfDataRequest(index, 0, 1) { + final int index = fTable.indexOf(item); + // Note: this works because handleEvent() is called once for each row, in sequence + if ((index >= cacheStartIndex ) && (index < cacheEndIndex)) { + item.setText(extractItemFields(cache[index - cacheStartIndex])); + return; + } + TmfDataRequest request = new TmfDataRequest(index, 0, CACHE_SIZE) { @Override public void handleData() { - TmfEvent[] result = getData(); - evt[0] = (result.length > 0) ? result[0] : null; + // No need to synchronize because the request is synchronous + cache = getData(); + cacheStartIndex = index; + cacheEndIndex = index + cache.length; } }; fExperiment.processRequest(request, true); - item.setText(extractItemFields(evt[0])); + item.setText(extractItemFields(cache[0])); } }); @@ -159,6 +165,13 @@ public class TmfEventsView extends TmfView { } } + // Events cache - temporary stuff + private final int CACHE_SIZE = 100; + private TmfEvent[] cache; + private int cacheStartIndex = 0; + private int cacheEndIndex = 0; + + private TmfTimestamp extractTimestamp(String entry) { TmfTimestamp ts = null; @@ -256,20 +269,20 @@ public class TmfEventsView extends TmfView { }); } - @TmfSignalHandler - public void currentTimeUpdated(TmfTimeSynchSignal signal) { - if (signal.getSource() != fTable && fExperiment != null) { - final int index = (int) fExperiment.getIndex(signal.getCurrentTime()); - // Perform the updates on the UI thread - fTable.getDisplay().asyncExec(new Runnable() { - public void run() { - int pos = (index > fTable.getTopIndex()) ? fTable.getTopIndex() : index; - fTable.setSelection(pos); - TmfTimestamp ts = extractTimestamp(fTable.getSelection()[0].getText()); - broadcastSignal(new TmfTimeSynchSignal(fTable, ts)); - } - }); - } - } +// @TmfSignalHandler +// public void currentTimeUpdated(TmfTimeSynchSignal signal) { +// if (signal.getSource() != fTable && fExperiment != null) { +// final int index = (int) fExperiment.getIndex(signal.getCurrentTime()); +// // Perform the updates on the UI thread +// fTable.getDisplay().asyncExec(new Runnable() { +// public void run() { +// int pos = (index > fTable.getTopIndex()) ? fTable.getTopIndex() : index; +// fTable.setSelection(pos); +// TmfTimestamp ts = extractTimestamp(fTable.getSelection()[0].getText()); +//// broadcastSignal(new TmfTimeSynchSignal(fTable, ts)); +// } +// }); +// } +// } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java index 7315dbac0a..228399cc35 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/event/TmfTimestamp.java @@ -12,6 +12,8 @@ package org.eclipse.linuxtools.tmf.event; +import java.io.Serializable; + /** * TmfTimestamp *

@@ -34,9 +36,14 @@ package org.eclipse.linuxtools.tmf.event; * occurred before t0 of the reference clock. * */ -public class TmfTimestamp { +public class TmfTimestamp implements Serializable { - // ======================================================================== + /** + * + */ + private static final long serialVersionUID = -3196421507276821609L; + + // ======================================================================== // Attributes // ======================================================================== diff --git a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java index a71e40df6e..6ead6ab43a 100644 --- a/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfExperiment.java @@ -272,7 +272,6 @@ public class TmfExperiment extends TmfComponent implements ITmfRequestHandler= nbTraces) { + fIndexing = false; + return Status.OK_STATUS; + } + // FIXME: LTTng hack - start +// indices.add(savedContexts); // TMF + // FIXME: LTTng hack - end + // Get the ordered events and populate the indices - int nbEvents = 0; - while ((getNextEvent(traces, contexts, events)) != null) + // FIXME: LTTng hack - start +// int nbEvents = 0; // TMF + int nbEvents = -1; // LTTng + // FIXME: LTTng hack - end + while ((getNextEvent(traces, contexts)) != null) { -// if (nbEvents % fIndexPageSize == 0) { -// // Udpate the contexts timestamp -// // Special case: if the total number of events is a multiple of the -// // DEFAULT_PAGE_SIZE then all the pending events are null. In that -// // case, we don't store an additional entry in the index array. -// int nullTimestamps = 0; -// for (int i = 0; i < nbTraces; i++) { -// savedContexts[i].setTimestamp((events[i] != null) ? events[i].getTimestamp() : null); -// if (events[i] == null) -// nullTimestamps++; -// } -// if (nullTimestamps < nbTraces) { -// indices.add(savedContexts); -// } -// } -// -// // Prepare the saved contexts for the upcoming save (next iteration) -// // The timestamp will then be set -// if (++nbEvents % fIndexPageSize == 0) { -// savedContexts = new TmfTraceContext[nbTraces]; -// for (int i = 0; i < nbTraces; i++) { -// savedContexts[i] = new TmfTraceContext(contexts[i].getLocation(), null, nbEvents); -// } -// } - - // TODO: LTTng specific (to be generalized) if (++nbEvents % fIndexPageSize == 0) { - // Udpate the contexts timestamp // Special case: if the total number of events is a multiple of the // DEFAULT_PAGE_SIZE then all the pending events are null. In that // case, we don't store an additional entry in the index array. - int nullTimestamps = 0; + nullEvents = 0; savedContexts = new TmfTraceContext[nbTraces]; for (int i = 0; i < nbTraces; i++) { - savedContexts[i] = new TmfTraceContext(contexts[i].getLocation(), (TmfTimestamp) contexts[i].getLocation(), nbEvents); - if (events[i] == null) - nullTimestamps++; + savedContexts[i] = new TmfTraceContext(contexts[i]); + if (contexts[i].getTimestamp() == null) + nullEvents++; } - if (nullTimestamps < nbTraces) { + if (nullEvents < nbTraces) { indices.add(savedContexts); } } @@ -596,17 +568,25 @@ public class TmfExperiment extends TmfComponent implements ITmfRequestHandler offsets[mid]) { +// } else if (key > locations[mid]) { // first = mid + 1; // } else { // return true; -- 2.34.1