Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Montplaisir2014-05-08 14:02:43 -0400
committerAlexandre Montplaisir2014-05-12 13:26:37 -0400
commit3492681f06713eafc5c5c942d836075316141791 (patch)
tree904c6086fc361c519740f0652f41e1d1736b0fa1
parentac922221fbff1901d22d2d3770fab2abea8ff689 (diff)
downloadorg.eclipse.linuxtools-3492681f06713eafc5c5c942d836075316141791.tar.gz
org.eclipse.linuxtools-3492681f06713eafc5c5c942d836075316141791.tar.xz
org.eclipse.linuxtools-3492681f06713eafc5c5c942d836075316141791.zip
tmf: Don't use ITmfEventField in TmfEventsTable
TmfEventsTable used ITmfEventFields to transfer what it calls the "fields" of an event row in the table. These are simple Strings at their heart though, ITmfEventField is used for event payloads only. This removes many unnecessary object creations. Change-Id: Ieb82651c6dc7b54505e24a1c21cfa3222a193bbf Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/26231 Tested-by: Hudson CI Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java25
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java22
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java14
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java31
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/commands/ExportToTextRequest.java7
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java69
7 files changed, 72 insertions, 108 deletions
diff --git a/lttng/org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java b/lttng/org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java
index 6628a2fe0e..028e35c836 100644
--- a/lttng/org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java
+++ b/lttng/org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java
@@ -22,8 +22,6 @@ import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEvent;
import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEventContent;
import org.eclipse.linuxtools.internal.gdbtrace.core.trace.GdbTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
@@ -106,18 +104,19 @@ public class GdbEventsTable extends TmfEventsTable {
}
@Override
- protected ITmfEventField[] extractItemFields(ITmfEvent event) {
- ITmfEventField[] fields = EMPTY_FIELD_ARRAY;
- if (event != null) {
- GdbTraceEventContent content = (GdbTraceEventContent) event.getContent();
- fields = new TmfEventField[] {
- new TmfEventField(TRACE_FRAME_COLUMN, content.getFrameNumber(), null),
- new TmfEventField(TRACEPOINT_COLUMN, content.getTracepointNumber(), null),
- new TmfEventField(FILE_COLUMN, event.getReference(), null),
- new TmfEventField(CONTENT_COLUMN, content.toString(), null)
- };
+ public String[] getItemStrings(ITmfEvent event) {
+ if (event == null) {
+ return EMPTY_STRING_ARRAY;
}
- return fields;
+ // FIXME Unchecked cast. Null check should be replaced with instanceof
+ // GdbTraceEvent check, and its getContent() should be overriden.
+ GdbTraceEventContent content = (GdbTraceEventContent) event.getContent();
+ return new String[] {
+ String.valueOf(content.getFrameNumber()),
+ String.valueOf(content.getTracepointNumber()),
+ event.getReference(),
+ content.toString()
+ };
}
@Override
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java
index 265ebebf0d..b6cb3e5793 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java
@@ -13,8 +13,6 @@
package org.eclipse.linuxtools.internal.lttng2.kernel.ui.viewers.events;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
import org.eclipse.swt.SWT;
@@ -69,17 +67,15 @@ public class LTTng2EventsTable extends TmfEventsTable {
}
@Override
- protected ITmfEventField[] extractItemFields(ITmfEvent event) {
- ITmfEventField[] fields = EMPTY_FIELD_ARRAY;
- if (event != null) {
- fields = new TmfEventField[] {
- new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, event.getTimestamp().toString(), null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, event.getReference(), null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, event.getType().getName(), null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, event.getContent().toString(), null)
- };
+ public String[] getItemStrings(ITmfEvent event) {
+ if (event == null) {
+ return EMPTY_STRING_ARRAY;
}
- return fields;
+ return new String[] {
+ event.getTimestamp().toString(),
+ event.getReference(),
+ event.getType().getName(),
+ event.getContent().toString()
+ };
}
-
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java
index 95d93aebd6..10ecebe7ac 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java
@@ -13,7 +13,6 @@
package org.eclipse.linuxtools.tmf.core.parsers.custom;
import java.text.ParseException;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -180,13 +179,20 @@ public class CustomEvent extends TmfEvent {
// ------------------------------------------------------------------------
/**
- * @return The event fields
+ * Get the contents of the row in the events table corresponding to this
+ * event. The order of the elements corresponds to the order of the columns.
+ *
+ * @return The event row entries
*/
- public TmfEventField[] extractItemFields() {
+ public String[] getEventStrings() {
if (fData != null) {
processData();
}
- return Arrays.copyOf(fColumnData, fColumnData.length);
+ String[] entries = new String[fColumnData.length];
+ for (int i = 0; i < fColumnData.length; i++) {
+ entries[i] = fColumnData[i].getValue().toString();
+ }
+ return entries;
}
private void processData() {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java
index ad83d45e9c..6485d3775b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java
@@ -14,8 +14,6 @@ package org.eclipse.linuxtools.tmf.ui.tests.experiment.type;
import org.eclipse.linuxtools.internal.tmf.ui.Messages;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
import org.eclipse.swt.SWT;
@@ -68,24 +66,17 @@ public class TmfEventsTableExperimentStub extends TmfEventsTable {
}
@Override
- protected ITmfEventField[] extractItemFields(ITmfEvent event) {
- ITmfEventField[] fields = new TmfEventField[0];
- if (event != null) {
- final String timestamp = event.getTimestamp().toString();
- final String source = event.getSource();
- final String type = event.getType().getName();
- final String reference = event.getReference();
- final String content = event.getContent().toString();
- fields = new TmfEventField[] {
- new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, timestamp, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_SOURCE, source, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, type, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, reference, null),
- new TmfEventField("Trace", event.getTrace().getName(), null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, content, null)
- };
+ public String[] getItemStrings(ITmfEvent event) {
+ if (event == null) {
+ return EMPTY_STRING_ARRAY;
}
- return fields;
+ return new String[] {
+ event.getTimestamp().toString(),
+ event.getSource(),
+ event.getType().getName(),
+ event.getReference(),
+ event.getTrace().getName(),
+ event.getContent().toString()
+ };
}
-
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/commands/ExportToTextRequest.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/commands/ExportToTextRequest.java
index 57d5e74386..b95450e8b0 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/commands/ExportToTextRequest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/commands/ExportToTextRequest.java
@@ -67,14 +67,13 @@ public class ExportToTextRequest extends TmfEventRequest {
try {
if (fFilter == null || fFilter.matches(event)) {
if (fTable != null) {
- ITmfEventField[] fields = fTable.getItemFields(event);
+ String[] entries = fTable.getItemStrings(event);
boolean needTab = false;
- for (ITmfEventField field: fields) {
+ for (String entry : entries) {
if (needTab) {
fWriter.write('\t');
}
- Object value = field.getValue();
- printValue(value);
+ printValue(entry);
needTab = true;
}
} else { // fallback to default formatting
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java
index 0da3953786..6875715a66 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java
@@ -16,7 +16,6 @@ import java.util.LinkedList;
import java.util.List;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomEvent;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
@@ -66,15 +65,10 @@ public class CustomEventsTable extends TmfEventsTable {
}
@Override
- public TmfEventField[] extractItemFields(ITmfEvent event) {
+ public String[] getItemStrings(ITmfEvent event) {
if (event instanceof CustomEvent) {
- TmfEventField[] fields = ((CustomEvent) event).extractItemFields();
-// String[] labels = new String[fields.length];
-// for (int i = 0; i < fields.length; i++) {
-// labels[i] = (String) fields[i].getValue();
-// }
- return fields;
+ return ((CustomEvent) event).getEventStrings();
}
- return new TmfEventField[0];
+ return EMPTY_STRING_ARRAY;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
index ebf69a41d0..d57a0aee24 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
@@ -78,8 +78,6 @@ import org.eclipse.linuxtools.internal.tmf.ui.dialogs.MultiLineInputDialog;
import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider;
import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfCallsite;
import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup;
import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup;
@@ -160,6 +158,12 @@ import org.eclipse.ui.themes.ColorUtil;
*/
public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider {
+ /**
+ * Empty string array, used by {@link #getItemStrings}.
+ * @since 3.0
+ */
+ protected static final String[] EMPTY_STRING_ARRAY = new String[0];
+
private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath(
"icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
@@ -173,11 +177,6 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
private static final String SEARCH_HINT = Messages.TmfEventsTable_SearchHint;
private static final String FILTER_HINT = Messages.TmfEventsTable_FilterHint;
private static final int MAX_CACHE_SIZE = 1000;
- /**
- * Empty ITmfEventField array, used by {@link #extractItemFields(ITmfEvent)}
- * @since 2.2
- */
- public static final ITmfEventField[] EMPTY_FIELD_ARRAY = new TmfEventField[0];
/**
* The events table search/filter keys
@@ -1008,12 +1007,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
* Which rank this event has in the trace/experiment
*/
protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) {
- final ITmfEventField[] fields = extractItemFields(event);
- final String[] content = new String[fields.length];
- for (int i = 0; i < fields.length; i++) {
- content[i] = fields[i].getValue() != null ? fields[i].getValue().toString() : ""; //$NON-NLS-1$
- }
- item.setText(content);
+ item.setText(getItemStrings(event));
item.setData(event);
item.setData(Key.TIMESTAMP, new TmfTimestamp(event.getTimestamp()));
item.setData(Key.RANK, rank);
@@ -1854,43 +1848,28 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
}
/**
- * Extract the fields of an event (item in the table).
+ * Get the contents of the row in the events table corresponding to an
+ * event. The order of the elements corresponds to the order of the columns.
*
- * @param event
- * The event to extract from
- * @return The array of fields
- * @since 2.2
- */
- public final ITmfEventField[] getItemFields(final ITmfEvent event) {
- return extractItemFields(event);
- }
-
- /**
- * Extract the fields of an event (item in the table).
+ * TODO Use column IDs, not indexes, so that the column order can be
+ * re-arranged.
*
* @param event
- * The event to extract from
- * @return The array of fields
- *
- * FIXME: Add support for column selection
+ * The event printed in this row
+ * @return The event row entries
+ * @since 3.0
*/
- protected ITmfEventField[] extractItemFields(final ITmfEvent event) {
- ITmfEventField[] fields = EMPTY_FIELD_ARRAY;
- if (event != null) {
- final String timestamp = event.getTimestamp().toString();
- final String source = event.getSource();
- final String type = event.getType().getName();
- final String reference = event.getReference();
- final String content = event.getContent().toString();
- fields = new TmfEventField[] {
- new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, timestamp, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_SOURCE, source, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, type, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, reference, null),
- new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, content, null)
- };
+ public String[] getItemStrings(ITmfEvent event) {
+ if (event == null) {
+ return EMPTY_STRING_ARRAY;
}
- return fields;
+ return new String[] {
+ event.getTimestamp().toString(),
+ event.getSource(),
+ event.getType().getName(),
+ event.getReference(),
+ event.getContent().toString()
+ };
}
/**

Back to the top