From df854ddb27550ed4c040d5e4b2d978a117db24d9 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 6 Feb 2015 11:25:00 -0500 Subject: [PATCH] btf: Fix BTF event property source The BTF UI plug-in is now started through the org.eclipse.core.runtime.adapters extension, since no class would trigger the plug-in start. This allows the BTF event adapter factory to be registered. To force loading the plug-in, we let BtfEvent load the adapter instead of simply getting it which in turn creates the factory and loads the plug-in. The BTF event property source is updated to display the Notes field into its own property. The BTF event reference member is renamed to target. Change-Id: I37fe006cece41f9b470da714314cef932ab7e9a8 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/41302 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann Reviewed-by: Matthew Khouzam --- .../btf/core/analysis/BtfStateProvider.java | 4 +- .../btf/core/event/BTFPayload.java | 17 +-- .../tracecompass/btf/core/event/BtfEvent.java | 30 ++++-- .../btf/core/event/BtfEventType.java | 13 +-- .../btf/core/trace/BtfEventAspects.java | 7 +- org.eclipse.tracecompass.btf.ui/plugin.xml | 10 ++ .../tracecompass/btf/ui/Activator.java | 6 -- .../btf/ui/BtfEventPropertySource.java | 100 +++++++++--------- 8 files changed, 101 insertions(+), 86 deletions(-) diff --git a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/analysis/BtfStateProvider.java b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/analysis/BtfStateProvider.java index c84277a202..752ab9cc57 100644 --- a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/analysis/BtfStateProvider.java +++ b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/analysis/BtfStateProvider.java @@ -141,7 +141,7 @@ public class BtfStateProvider extends AbstractTmfStateProvider { final long ts = event.getTimestamp().getValue(); final String eventType = (String) event.getContent().getField(BtfColumnNames.EVENT.toString()).getValue(); final String source = event.getSource(); - final String target = event.getReference(); + final String target = event.getTarget(); String task; int quark; try { @@ -262,7 +262,7 @@ public class BtfStateProvider extends AbstractTmfStateProvider { throws AttributeNotFoundException { String name = event.getType().getName(); if (name.equals("Task")) { //$NON-NLS-1$ - String task = event.getReference(); + String task = event.getTarget(); int quark = ssb.getQuarkAbsoluteAndAdd(ATTRIBUTE_TASKS, task); ssb.modifyAttribute(ts, stateValue.getValue(), quark); } diff --git a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BTFPayload.java b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BTFPayload.java index a902565ee4..58960646d4 100644 --- a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BTFPayload.java +++ b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BTFPayload.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Matthew Khouzam - Initial API and implementation + * Patrick Tasse - Update empty descriptions *******************************************************************************/ package org.eclipse.tracecompass.btf.core.event; @@ -27,10 +28,13 @@ import com.google.common.collect.ImmutableMap.Builder; */ public class BTFPayload { + /** Description subfield name */ + public static final String DESCRIPTION = "description"; //$NON-NLS-1$ + private static final Map EVENT_DESCRIPTIONS; - private static final String EMPTY = "TBA"; //$NON-NLS-1$ + private static final String EMPTY = ""; //$NON-NLS-1$ private static final Map FIELDS; - private static final TmfEventField[] TBA_FIELD = new TmfEventField[] { new TmfEventField(EMPTY, EMPTY, new TmfEventField[] { new TmfEventField(EMPTY, EMPTY, null) }) }; + private static final TmfEventField[] EMPTY_DESCRIPTION = new TmfEventField[] { new TmfEventField(DESCRIPTION, EMPTY, null) }; static { ImmutableMap.Builder builder = new Builder<>(); @@ -84,7 +88,7 @@ public class BTFPayload { EVENT_DESCRIPTIONS = builder.build(); ImmutableMap.Builder fieldBuilder = new Builder<>(); for (String key : EVENT_DESCRIPTIONS.keySet()) { - fieldBuilder.put(key, new TmfEventField[] { new TmfEventField("description", EVENT_DESCRIPTIONS.get(key), null) }); //$NON-NLS-1$ + fieldBuilder.put(key, new TmfEventField[] { new TmfEventField(DESCRIPTION, EVENT_DESCRIPTIONS.get(key), null) }); } FIELDS = fieldBuilder.build(); } @@ -97,9 +101,8 @@ public class BTFPayload { * @return the description */ public static TmfEventField[] getFieldDescription(String key) { - String shortKey = key.split(",", 2)[0]; //$NON-NLS-1$ - TmfEventField[] retVal = FIELDS.get(shortKey); - return (retVal == null) ? TBA_FIELD : retVal; + TmfEventField[] retVal = FIELDS.get(key); + return (retVal == null) ? EMPTY_DESCRIPTION : retVal; } } diff --git a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEvent.java b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEvent.java index e4ac31c3c6..0e968504bb 100644 --- a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEvent.java +++ b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,10 +8,12 @@ * * Contributors: * Matthew Khouzam - Initial API and implementation + * Patrick Tasse - Rename reference to target *******************************************************************************/ package org.eclipse.tracecompass.btf.core.event; +import org.eclipse.core.runtime.Platform; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; import org.eclipse.tracecompass.tmf.core.event.TmfEvent; @@ -19,8 +21,8 @@ import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; /** - * A Btf event, basically a wrapper for the TmfEvent with the additional field - * of "description" + * A Btf event, basically a wrapper for the TmfEvent with the additional fields + * source, target and description. * * @author Matthew Khouzam */ @@ -28,7 +30,7 @@ public class BtfEvent extends TmfEvent { private final String fDescription; private final String fSource; - private final String fReference; + private final String fTarget; /** * Standard constructor. @@ -47,7 +49,7 @@ public class BtfEvent extends TmfEvent { * a description of the type * @param content * the event content (payload) - * @param reference + * @param target * the event reference */ public BtfEvent(final ITmfTrace trace, @@ -57,11 +59,11 @@ public class BtfEvent extends TmfEvent { final ITmfEventType type, final String description, final ITmfEventField content, - final String reference) { + final String target) { super(trace, rank, timestamp, type, content); fDescription = description; fSource = source; - fReference = reference; + fTarget = target; } /** @@ -73,6 +75,12 @@ public class BtfEvent extends TmfEvent { return fDescription; } + @Override + public Object getAdapter(Class adapter) { + // Force loading the adapters otherwise some plugins might not load + return Platform.getAdapterManager().loadAdapter(this, adapter.getName()); + } + /** * Returns the source of this event. * @@ -83,11 +91,11 @@ public class BtfEvent extends TmfEvent { } /** - * Returns the reference of this event. + * Returns the target of this event. * - * @return This event's reference + * @return This event's target */ - public String getReference() { - return fReference; + public String getTarget() { + return fTarget; } } diff --git a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEventType.java b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEventType.java index 9d7dba3a2b..6336d35d0a 100644 --- a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEventType.java +++ b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/event/BtfEventType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Matthew Khouzam - Initial API and implementation + * Patrick Tasse - Fix target instance field *******************************************************************************/ package org.eclipse.tracecompass.btf.core.event; @@ -110,16 +111,16 @@ public class BtfEventType extends TmfEventType { public ITmfEventField generateContent(String event, long sourceInstance, long targetInstance) { String[] data; TmfEventField retField; - TmfEventField sourceInstanceField = new TmfEventField(fCols.get(1), sourceInstance, null); - TmfEventField targetInstanceField = new TmfEventField(fCols.get(2), sourceInstance, null); + TmfEventField sourceInstanceField = new TmfEventField(BtfColumnNames.SOURCE_INSTANCE.toString(), sourceInstance, null); + TmfEventField targetInstanceField = new TmfEventField(BtfColumnNames.TARGET_INSTANCE.toString(), targetInstance, null); if (fHasNotes) { data = event.split(",", 2); //$NON-NLS-1$ - TmfEventField eventField = new TmfEventField(fCols.get(0), data[0], BTFPayload.getFieldDescription(data[0])); - TmfEventField notesField = new TmfEventField(fCols.get(3), data[1], null); + TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0])); + TmfEventField notesField = new TmfEventField(BtfColumnNames.NOTES.toString(), data[1], null); retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField, notesField }); } else { data = new String[] { event }; - TmfEventField eventField = new TmfEventField(fCols.get(0), data[0], BTFPayload.getFieldDescription(data[0])); + TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0])); retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField }); } return retField; diff --git a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfEventAspects.java b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfEventAspects.java index e3463aa313..873793c253 100644 --- a/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfEventAspects.java +++ b/org.eclipse.tracecompass.btf.core/src/org/eclipse/tracecompass/btf/core/trace/BtfEventAspects.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,6 +9,7 @@ * Contributors: * Matthew Khouzam - Initial API and implementation * Alexandre Montplaisir - Update to new Event Table API + * Patrick Tasse - Update for renamed target field *******************************************************************************/ package org.eclipse.tracecompass.btf.core.trace; @@ -70,7 +71,7 @@ public final class BtfEventAspects { /** * The "target" aspect, taking its value from - * {@link ITmfEvent#getReference()}. + * {@link ITmfEvent#getTarget()}. */ private static class BtfTargetAspect implements ITmfEventAspect { @@ -89,7 +90,7 @@ public final class BtfEventAspects { if (!(event instanceof BtfEvent)) { return EMPTY_STRING; } - String ret = ((BtfEvent) event).getReference(); + String ret = ((BtfEvent) event).getTarget(); return (ret == null ? EMPTY_STRING : ret); } } diff --git a/org.eclipse.tracecompass.btf.ui/plugin.xml b/org.eclipse.tracecompass.btf.ui/plugin.xml index 594c5fa0ba..c33ca44c53 100644 --- a/org.eclipse.tracecompass.btf.ui/plugin.xml +++ b/org.eclipse.tracecompass.btf.ui/plugin.xml @@ -8,4 +8,14 @@ tracetype="org.eclipse.linuxtools.btf.trace"> + + + + + + diff --git a/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/Activator.java b/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/Activator.java index 3e769f899e..b09e9a9f42 100644 --- a/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/Activator.java +++ b/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/Activator.java @@ -13,10 +13,8 @@ package org.eclipse.tracecompass.btf.ui; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; -import org.eclipse.tracecompass.btf.core.event.BtfEvent; import org.osgi.framework.BundleContext; /** @@ -42,8 +40,6 @@ public class Activator extends Plugin { */ private static Activator fPlugin; - private BtfEventAdapterFactory fBtfEventAdapterFactory; - // ------------------------------------------------------------------------ // Constructors @@ -82,8 +78,6 @@ public class Activator extends Plugin { public void start(BundleContext context) throws Exception { super.start(context); setDefault(this); - fBtfEventAdapterFactory = new BtfEventAdapterFactory(); - Platform.getAdapterManager().registerAdapters(fBtfEventAdapterFactory, BtfEvent.class); } @Override diff --git a/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java b/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java index 34d37659c6..8aae9d9b92 100644 --- a/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java +++ b/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,14 +8,16 @@ * * Contributors: * Matthew Khouzam - Initial API and implementation + * Patrick Tasse - Update properties *******************************************************************************/ package org.eclipse.tracecompass.btf.ui; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; +import org.eclipse.tracecompass.btf.core.event.BTFPayload; import org.eclipse.tracecompass.btf.core.event.BtfEvent; +import org.eclipse.tracecompass.btf.core.trace.BtfColumnNames; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventPropertySource; @@ -34,6 +36,19 @@ public class BtfEventPropertySource extends TmfEventPropertySource { private static final String ID_EVENT_SOURCE = "event_source"; //$NON-NLS-1$ private static final String ID_EVENT_TYPE = "event_type"; //$NON-NLS-1$ private static final String ID_EVENT_TARGET = "event_target"; //$NON-NLS-1$ + private static final String ID_EVENT_NOTES = "event_notes"; //$NON-NLS-1$ + private static final IPropertyDescriptor[] DESCRIPTORS = new IPropertyDescriptor[] { + new ReadOnlyTextPropertyDescriptor(ID_EVENT_TIMESTAMP, "Timestamp"), //$NON-NLS-1$ + new ReadOnlyTextPropertyDescriptor(ID_EVENT_SOURCE, "Source"), //$NON-NLS-1$ + new ReadOnlyTextPropertyDescriptor(ID_EVENT_TYPE, "Type"), //$NON-NLS-1$ + new ReadOnlyTextPropertyDescriptor(ID_EVENT_TARGET, "Target"), //$NON-NLS-1$ + new ReadOnlyTextPropertyDescriptor(ID_EVENT_EVENT, "Event"), //$NON-NLS-1$ + new ReadOnlyTextPropertyDescriptor(ID_EVENT_NOTES, "Notes") //$NON-NLS-1$ + }; + private static final IPropertyDescriptor[] DESCRIPTORS_WITHOUT_NOTES = Arrays.copyOf(DESCRIPTORS, DESCRIPTORS.length - 1); + private static final String DESCRIPTION = "Description"; //$NON-NLS-1$ + private static final String INSTANCE = "Instance"; //$NON-NLS-1$ + private final BtfEvent fEvent; /** @@ -50,28 +65,24 @@ public class BtfEventPropertySource extends TmfEventPropertySource { @Override public IPropertyDescriptor[] getPropertyDescriptors() { - return new IPropertyDescriptor[] { - new ReadOnlyTextPropertyDescriptor(ID_EVENT_TIMESTAMP, "Timestamp"), //$NON-NLS-1$ - new ReadOnlyTextPropertyDescriptor(ID_EVENT_SOURCE, "Source"), //$NON-NLS-1$ - new ReadOnlyTextPropertyDescriptor(ID_EVENT_TYPE, "Type"), //$NON-NLS-1$ - new ReadOnlyTextPropertyDescriptor(ID_EVENT_TARGET, "Target"), //$NON-NLS-1$ - new ReadOnlyTextPropertyDescriptor(ID_EVENT_EVENT, "event") //$NON-NLS-1$ - }; + if (fEvent.getContent().getField(BtfColumnNames.NOTES.toString()) == null) { + return DESCRIPTORS_WITHOUT_NOTES; + } + return DESCRIPTORS; } - private class TargetPropertySource implements IPropertySource { - private static final String INSTANCE = "Instance"; //$NON-NLS-1$ - private final String fTarget; + private class EntityPropertySource implements IPropertySource { + private final String fName; private final String fInstance; - public TargetPropertySource(String target, String instance) { - fTarget = target; + public EntityPropertySource(String name, String instance) { + fName = name; fInstance = instance; } @Override public Object getEditableValue() { - return fTarget; + return fName; } @Override @@ -91,7 +102,7 @@ public class BtfEventPropertySource extends TmfEventPropertySource { @Override public boolean isPropertySet(Object id) { - return INSTANCE.equals(id); + return false; } @Override @@ -105,7 +116,6 @@ public class BtfEventPropertySource extends TmfEventPropertySource { } private class TypePropertySource implements IPropertySource { - private static final String DESCRIPTION = "Description"; //$NON-NLS-1$ private final String fType; private final String fDescr; @@ -136,7 +146,7 @@ public class BtfEventPropertySource extends TmfEventPropertySource { @Override public boolean isPropertySet(Object id) { - return DESCRIPTION.equals(id); + return false; } @Override @@ -149,47 +159,29 @@ public class BtfEventPropertySource extends TmfEventPropertySource { } private class EventPropertySource implements IPropertySource { - private static final String DESCRIPTION = "Description"; //$NON-NLS-1$ - private static final String NOTE = "Note"; //$NON-NLS-1$ - private final String fEventName; - private final String fNote; - private final String fEventDescription; - - public EventPropertySource(String event, String note) { - fEventName = event; - fNote = note; + private final ITmfEventField fEventField; - ITmfEventField content = fEvent.getContent(); - String first = content.getFieldNames().iterator().next(); - content = content.getField(first); - first = content.getFieldNames().iterator().next(); - fEventDescription = content.getField(first).getValue().toString(); + public EventPropertySource(ITmfEventField eventField) { + fEventField = eventField; } @Override public Object getEditableValue() { - return fEventName; + return fEventField.getValue(); } @Override public IPropertyDescriptor[] getPropertyDescriptors() { - if (fNote == null) { - return new IPropertyDescriptor[] { - new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION) - }; - } return new IPropertyDescriptor[] { - new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION), - new ReadOnlyTextPropertyDescriptor(NOTE, NOTE) + new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION) }; } @Override public Object getPropertyValue(Object id) { - if (NOTE.equals(id)) { - return fNote; - } else if (DESCRIPTION.equals(id)) { - return fEventDescription; + if (DESCRIPTION.equals(id)) { + ITmfEventField description = fEventField.getField(BTFPayload.DESCRIPTION); + return description == null ? null : description.getValue(); } return null; } @@ -214,17 +206,23 @@ public class BtfEventPropertySource extends TmfEventPropertySource { if (id instanceof String) { String id2 = (String) id; final ITmfEventField content = fEvent.getContent(); - List fieldNames = new ArrayList<>(content.getFieldNames()); switch (id2) { - case ID_EVENT_TARGET: - return new TargetPropertySource(fEvent.getReference(), content.getField(fieldNames.get(2)).toString()); case ID_EVENT_SOURCE: - return new TargetPropertySource(fEvent.getSource(), content.getField(fieldNames.get(1)).toString()); + String source = fEvent.getSource(); + ITmfEventField sourceInstance = content.getField(BtfColumnNames.SOURCE_INSTANCE.toString()); + return new EntityPropertySource(source, sourceInstance.getValue().toString()); case ID_EVENT_TYPE: return new TypePropertySource(fEvent.getType().getName(), fEvent.getEventDescription()); + case ID_EVENT_TARGET: + String target = fEvent.getTarget(); + ITmfEventField targetInstance = content.getField(BtfColumnNames.TARGET_INSTANCE.toString()); + return new EntityPropertySource(target, targetInstance.getValue().toString()); case ID_EVENT_EVENT: - ITmfEventField noteField = (fieldNames.size() > 3) ? content.getField(fieldNames.get(3)) : null; - return new EventPropertySource(content.getField(fieldNames.get(0)).getValue().toString(), (noteField == null) ? null : noteField.getValue().toString()); + ITmfEventField event = content.getField(BtfColumnNames.EVENT.toString()); + return event == null ? null : new EventPropertySource(event); + case ID_EVENT_NOTES: + ITmfEventField notes = content.getField(BtfColumnNames.NOTES.toString()); + return notes == null ? null : notes.getValue(); default: break; } -- 2.34.1