diff options
author | Jeff Johnston | 2018-04-24 22:43:54 +0000 |
---|---|---|
committer | Jeff Johnston | 2018-04-25 02:59:07 +0000 |
commit | 7a56ef9f3d3ae90c070d8044f80ce016ab072eb1 (patch) | |
tree | f7a8f824c422c987a209a1dea94bf2eadf0ee75b | |
parent | a5c64da383f2a82ce1fa789dd9553d623a46fff2 (diff) | |
download | org.eclipse.linuxtools-7a56ef9f3d3ae90c070d8044f80ce016ab072eb1.tar.gz org.eclipse.linuxtools-7a56ef9f3d3ae90c070d8044f80ce016ab072eb1.tar.xz org.eclipse.linuxtools-7a56ef9f3d3ae90c070d8044f80ce016ab072eb1.zip |
Bug 534011 - OProfile: can't handle non-unique unit masks
- add name field to MaskInfo in OpUnitMask
- in OpUnitMask, keep track of unit-mask names and mark those
masks that are non-unique for an EXCLUSIVE mask type
- modify OpUnitMask setMaskFromIndex() to store the maskName
- add maskName field to OpUnitMask and getter/setter for it
- modify OProfileCounter saveConfiguration() and loadConfiguration()
to store and load the unit mask names
- add attrCounterUnitMaskName to OProfileLaunchPlugin
- in AbstractOprofileLaunchConfigurationDelegate launch(), add
a unit mask name if unit mask is non-unique
- modify InfoAdapter createXML() method to store the name attribute
of a unit-mask
- fix EventListProcessor to parse unit-mask names and store them
Change-Id: I68aa7d7e0f6f4cbcde986cc4d140232e8547a5e5
Reviewed-on: https://git.eclipse.org/r/121695
Tested-by: CI Bot
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
6 files changed, 514 insertions, 434 deletions
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/daemon/OpUnitMask.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/daemon/OpUnitMask.java index 32d0b10971..65de6e58be 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/daemon/OpUnitMask.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/daemon/OpUnitMask.java @@ -12,244 +12,308 @@ package org.eclipse.linuxtools.internal.oprofile.core.daemon; +import java.util.HashSet; +import java.util.Set; + /** * A class representing the unit mask that may be associated with oprofile * events. Note that since this class was originally written, oprofile unit * masks have changed -- a single unit mask may affect several bits at once. - * Hence, instead of a certain bit being flipped, the specific bits to be changed - * are determined by the particular mask's index + * Hence, instead of a certain bit being flipped, the specific bits to be + * changed are determined by the particular mask's index */ public class OpUnitMask { - /** - * A class which describes an individual unit mask value. Used in XML parsing. - */ - public static class MaskInfo { - /** - * The integer value of the mask. - */ - public int value; - - /** - * A description of the mask. - */ - public String description; - } - - public static final int SET_DEFAULT_MASK = -1; - - /** - * Invalid mask type. - */ - public static final int INVALID = -1; - - /** - * The mask is mandatory. It must be used. - */ - public static final int MANDATORY = 1; - - /** - * The mask is exclusive. Only one of its mask values may be used. - */ - public static final int EXCLUSIVE = 2; - - /** - * The mask is a bitmask. Any combination of its values may be used. - */ - public static final int BITMASK = 3; - - - /** - * The current value of this unitmask - */ - private int mask; - - /** - * The default mask provided by the oprofile library - */ - private int defaultMask; - - /** - * The type of this unitmask - */ - private int maskType; - - /** - * Descriptions of the bits of this mask - */ - private String[] maskOptionDescriptions = new String[0]; - - /** - * mask values -- now bit masks have distinct values (eg: an all of the above) - */ - - private int[] maskOptionValues; - - /** - * Set the descriptions and values for this unitmask's mask options. - * Only used from the XML parsers. - * @param masks a list of all the mask options - */ - public void setMaskDescriptions(MaskInfo[] masks) { - maskOptionDescriptions = new String[masks.length]; - maskOptionValues = new int[masks.length]; - - for (int i = 0; i < masks.length; ++i) { - maskOptionDescriptions[i] = masks[i].description; - maskOptionValues[i] = masks[i].value; - } - } - - /** - * Sets the default value for this unitmask, and initializes - * the current unitmask value to this default. - * Only used from the XML parsers. - * @param theDefault the default value - */ - public void setDefault(int theDefault) { - defaultMask = theDefault; - setDefaultMaskValue(); - } - - /** - * Sets the unitmask type. - * Only used from the XML parsers. - * @param type the type - */ - public void setType(int type) { - maskType = type; - } - - /** - * Returns the integer value of this unitmask, suitable for passing to oprofile. - * @return the integer value - */ - public int getMaskValue() { - return mask; - } - - /** - * Tests whether a particular mask is set in the unitmask value, based on the - * value of the mask option at the given index. - * - * @param index the index of the mask option to check - * @return whether the given mask option's value is set - */ - public boolean isMaskSetFromIndex(int index) { - boolean result = false; - - if (index >= 0 && index < maskOptionValues.length) { - switch (maskType) { - case EXCLUSIVE: - result = (mask == maskOptionValues[index]); - break; - - case BITMASK: - result = ((mask & maskOptionValues[index]) != 0); - break; - - default: - result = false; - } - } - - return result; - } - - /** - * Sets the absolute unitmask value. - * - * @param newValue the new value of this unitmask - */ - public void setMaskValue(int newValue) { - if (newValue == SET_DEFAULT_MASK) { - mask = defaultMask; - } else { - mask = newValue; - } - } - - /** - * Sets the bits of the given mask option's value in the unitmask value. - * @param index the index of the mask option to set - */ - public void setMaskFromIndex(int index) { - //mandatory masks only use the default value - if (index >= 0 && index < maskOptionValues.length) { - if (maskType == BITMASK) - mask |= maskOptionValues[index]; - else if (maskType == EXCLUSIVE) { - mask = maskOptionValues[index]; - } - } - } - - /** - * Returns the value of the mask based on the unitmask index. - * @param index the index of the mask option - * @return the mask option's value - */ - public int getMaskFromIndex(int index) { - //mandatory masks only use the default value - if (maskType == BITMASK) { - if (index >= 0 && index < maskOptionValues.length) { - return maskOptionValues[index]; - } - } else if (maskType == EXCLUSIVE) { - if (index >= 0 && index < maskOptionValues.length) { - return maskOptionValues[index]; - } - } else if (maskType == MANDATORY) { - return defaultMask; - } - - //type invalid or unknown, or out of bounds - return -1; - } - - /** - * Unset the bits of the given mask option's value in the unitmask value. - * @param index the index of the mask option to set - */ - public void unSetMaskFromIndex(int index) { - if (index >= 0 && index < maskOptionValues.length && maskType == BITMASK) { - mask = mask & ~maskOptionValues[index]; - } - } - - /** - * Sets the current unitmask value to the default mask value. - */ - public void setDefaultMaskValue() { - mask = defaultMask; - } - - /** - * Returns a description of the requested mask option. - * @param num the mask option index - * @return the description - */ - public String getText(int num) { - if (num >= 0 && num < maskOptionDescriptions.length) { - return maskOptionDescriptions[num]; - } - - return null; - } - - /** - * Returns the number of mask options in this unitmask. - * @return the number of mask options - */ - public int getNumMasks() { - return maskOptionDescriptions.length; - } - - /** - * Returns the mask type for this unit mask. - * @return <code>BITMASK</code>, <code>EXCLUSIVE</code>, or - * <code>MANDATORY</code> - */ - public int getType() { - return maskType; - } + /** + * A class which describes an individual unit mask value. Used in XML parsing. + */ + public static class MaskInfo { + /** + * The integer value of the mask. + */ + public int value; + + /** + * The name of the mask. + */ + public String name; + + /** + * A description of the mask. + */ + public String description; + } + + public static final int SET_DEFAULT_MASK = -1; + + /** + * Invalid mask type. + */ + public static final int INVALID = -1; + + /** + * The mask is mandatory. It must be used. + */ + public static final int MANDATORY = 1; + + /** + * The mask is exclusive. Only one of its mask values may be used. + */ + public static final int EXCLUSIVE = 2; + + /** + * The mask is a bitmask. Any combination of its values may be used. + */ + public static final int BITMASK = 3; + + /** + * The current value of this unitmask + */ + private int mask; + + /** + * The current name of this unitmask (EXCLUSIVE-only) + */ + private String maskName = ""; //$NON-NLS-1$ + + /** + * The default mask provided by the oprofile library + */ + private int defaultMask; + + /** + * The type of this unitmask + */ + private int maskType; + + /** + * Descriptions of the bits of this mask + */ + private String[] maskOptionDescriptions = new String[0]; + + /** + * mask values -- now bit masks have distinct values (eg: an all of the above) + */ + + private int[] maskOptionValues; + + /** + * Name of the bit mask + */ + + private String[] maskOptionNames = new String[0]; + + /** + * Set of non-unique mask values (EXCLUSIVE type only) Some platforms allow + * multiple masks of same value and these need to be identified additionally by + * their name + */ + Set<Integer> nonUniqueValues = new HashSet<>(); + + /** + * Set the descriptions and values for this unitmask's mask options. Only used + * from the XML parsers. + * + * @param masks a list of all the mask options + */ + public void setMaskDescriptions(MaskInfo[] masks) { + maskOptionDescriptions = new String[masks.length]; + maskOptionValues = new int[masks.length]; + maskOptionNames = new String[masks.length]; + + Set<Integer> values = new HashSet<>(); + + for (int i = 0; i < masks.length; ++i) { + Integer val = new Integer(masks[i].value); + if (values.contains(new Integer(val))) { + nonUniqueValues.add(new Integer(val)); + } + values.add(new Integer(val)); + maskOptionDescriptions[i] = masks[i].description; + maskOptionValues[i] = masks[i].value; + maskOptionNames[i] = masks[i].name; + } + } + + /** + * Sets the default value for this unitmask, and initializes the current + * unitmask value to this default. Only used from the XML parsers. + * + * @param theDefault the default value + */ + public void setDefault(int theDefault) { + defaultMask = theDefault; + setDefaultMaskValue(); + } + + /** + * Sets the unitmask type. Only used from the XML parsers. + * + * @param type the type + */ + public void setType(int type) { + maskType = type; + } + + /** + * Returns the integer value of this unitmask, suitable for passing to oprofile. + * + * @return the integer value + */ + public int getMaskValue() { + return mask; + } + + /** + * Returns the unitmask name if this is a non-unique bitmask (EXCLUSIVE-only), + * otherwise returns null. + */ + public String getMaskName() { + if (nonUniqueValues.contains(new Integer(mask))) { + return maskName; + } + return null; + } + + /** + * Tests whether a particular mask is set in the unitmask value, based on the + * value of the mask option at the given index. + * + * @param index the index of the mask option to check + * @return whether the given mask option's value is set + */ + public boolean isMaskSetFromIndex(int index) { + boolean result = false; + + if (index >= 0 && index < maskOptionValues.length) { + switch (maskType) { + case EXCLUSIVE: + result = (mask == maskOptionValues[index] + && (maskName.isEmpty() || maskName.equals(maskOptionNames[index]))); + break; + + case BITMASK: + result = ((mask & maskOptionValues[index]) != 0); + break; + + default: + result = false; + } + } + + return result; + } + + /** + * Sets the absolute unitmask value. + * + * @param newValue the new value of this unitmask + */ + public void setMaskValue(int newValue) { + if (newValue == SET_DEFAULT_MASK) { + mask = defaultMask; + } else { + mask = newValue; + } + } + + /** + * Sets the unitmask name. + * + * @param newName the name of this unitmask + */ + public void setMaskName(String newName) { + maskName = newName; + } + + /** + * Sets the bits of the given mask option's value in the unitmask value. + * + * @param index the index of the mask option to set + */ + public void setMaskFromIndex(int index) { + // mandatory masks only use the default value + if (index >= 0 && index < maskOptionValues.length) { + if (maskType == BITMASK) + mask |= maskOptionValues[index]; + else if (maskType == EXCLUSIVE) { + mask = maskOptionValues[index]; + maskName = maskOptionNames[index]; + } + } + } + + /** + * Returns the value of the mask based on the unitmask index. + * + * @param index the index of the mask option + * @return the mask option's value + */ + public int getMaskFromIndex(int index) { + // mandatory masks only use the default value + if (maskType == BITMASK) { + if (index >= 0 && index < maskOptionValues.length) { + return maskOptionValues[index]; + } + } else if (maskType == EXCLUSIVE) { + if (index >= 0 && index < maskOptionValues.length) { + return maskOptionValues[index]; + } + } else if (maskType == MANDATORY) { + return defaultMask; + } + + // type invalid or unknown, or out of bounds + return -1; + } + + /** + * Unset the bits of the given mask option's value in the unitmask value. + * + * @param index the index of the mask option to set + */ + public void unSetMaskFromIndex(int index) { + if (index >= 0 && index < maskOptionValues.length && maskType == BITMASK) { + mask = mask & ~maskOptionValues[index]; + } + } + + /** + * Sets the current unitmask value to the default mask value. + */ + public void setDefaultMaskValue() { + mask = defaultMask; + } + + /** + * Returns a description of the requested mask option. + * + * @param num the mask option index + * @return the description + */ + public String getText(int num) { + if (num >= 0 && num < maskOptionDescriptions.length) { + return maskOptionDescriptions[num]; + } + + return null; + } + + /** + * Returns the number of mask options in this unitmask. + * + * @return the number of mask options + */ + public int getNumMasks() { + return maskOptionDescriptions.length; + } + + /** + * Returns the mask type for this unit mask. + * + * @return <code>BITMASK</code>, <code>EXCLUSIVE</code>, or + * <code>MANDATORY</code> + */ + public int getType() { + return maskType; + } } diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/EventListProcessor.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/EventListProcessor.java index cfeccc6057..b5dc69f334 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/EventListProcessor.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/EventListProcessor.java @@ -19,206 +19,210 @@ import org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler; import org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor; import org.xml.sax.Attributes; - /** * XML handler class for opxml's "event-list". + * * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.OpxmlRunner */ public class EventListProcessor extends XMLProcessor { - // The current event being constructed - private OpEvent currentEvent; - private int counter; - private ArrayList<OpEvent> currentEventList; - - // An XML processor for reading the unit mask information for an event - private UnitMaskProcessor umProcessor; - - // XML elements recognized by this processor - private static final String EVENT_TAG = "event"; //$NON-NLS-1$ - private static final String UNIT_MASK_TAG = "unit-mask"; //$NON-NLS-1$ - private static final String NAME_TAG = "name"; //$NON-NLS-1$ - private static final String VALUE_TAG = "value"; //$NON-NLS-1$ - private static final String DESCRIPTION_TAG = "description"; //$NON-NLS-1$ - private static final String MASK_TAG = "mask"; //$NON-NLS-1$ - private static final String MINIMUM_COUNT_TAG = "minimum"; //$NON-NLS-1$ - private static final String ATTR_EVENT_LIST_COUNTER = "counter"; //$NON-NLS-1$ - - // This is a special processor which is used to deal with a single mask value - private static class MaskProcessor extends XMLProcessor { - private OpUnitMask.MaskInfo info; - - @Override - public void reset(Object callData) { - info = new OpUnitMask.MaskInfo(); - } - - @Override - public void endElement(String name, Object callData) { - if (name.equals(VALUE_TAG)) { - // Set mask's value - info.value = Integer.parseInt(characters); - } else if (name.equals(DESCRIPTION_TAG)) { - info.description = characters; - } else if (name.equals(MASK_TAG)) { - // Pop and pass mask tag to previous processor (UnitMaskProcessor) - OprofileSAXHandler.getInstance(callData).pop(MASK_TAG); - } - } - - /** - * Returns the information that has been collected about a mask. - * @return the mask information - */ - public OpUnitMask.MaskInfo getResult() { - return info; - } - } - - // This is a special processor to handle unit mask information - private class UnitMaskProcessor extends XMLProcessor { - // An ArrayList to hold all the valid masks for a unit mask. - private ArrayList<OpUnitMask.MaskInfo> masks; - - // The unit mask being constructed - private OpUnitMask unitMask; - - // An XML processor for each individual mask value. - private MaskProcessor maskProcessor; - - // XML elements recognized by this processor - private static final String MASK_TYPE_TAG = "type"; //$NON-NLS-1$ - private static final String MASK_DEFAULT_TAG = "default"; //$NON-NLS-1$ - private static final String MASK_TYPE_BITMASK = "bitmask"; //$NON-NLS-1$ - private static final String MASK_TYPE_MANDATORY = "mandatory"; //$NON-NLS-1$ - private static final String MASK_TYPE_EXCLUSIVE = "exclusive"; //$NON-NLS-1$ - - /** - * Constructor for UnitMaskProcessor. Initializes internal state. - */ - public UnitMaskProcessor() { - super(); - maskProcessor = new MaskProcessor(); - masks = new ArrayList<>(); - } - - @Override - public void reset(Object callData) { - unitMask = new OpUnitMask(); - masks.clear(); - } - - @Override - public void startElement(String name, Attributes attrs, Object callData) { - if (name.equals(MASK_TAG)) { - // Tell SAX handler to use the mask processor - OprofileSAXHandler.getInstance(callData).push(maskProcessor); - } else { - super.startElement(name, attrs, callData); - } - } - - @Override - public void endElement(String name, Object callData) { - if (name.equals(MASK_TYPE_TAG)) { - // Set the mask type - unitMask.setType(getTypeFromString(characters)); - } else if (name.equals(MASK_DEFAULT_TAG)) { - // Set the default mask - unitMask.setDefault(Integer.parseInt(characters)); - } else if (name.equals(MASK_TAG)) { - // Add this mask description to the list of all masks - masks.add(maskProcessor.getResult()); - } else if (name.equals(UNIT_MASK_TAG)) { - // All done. Add the known masks to the unit mask - OpUnitMask.MaskInfo[] descs = new OpUnitMask.MaskInfo[masks.size()]; - masks.toArray(descs); - unitMask.setMaskDescriptions(descs); - - // Pop this processor and pass _UNIT_MASK_TAG to previoius processor - OprofileSAXHandler.getInstance(callData).pop(UNIT_MASK_TAG); - } - } - - /** - * Returns the constructed unit mask. - * @return the unit mask - */ - public OpUnitMask getResult() { - return unitMask; - } - - // Converts a string representing a mask type into an integer - private int getTypeFromString(String string) { - if (string.equals(MASK_TYPE_MANDATORY)) { - return OpUnitMask.MANDATORY; - } else if (string.equals(MASK_TYPE_BITMASK)) { - return OpUnitMask.BITMASK; - } else if (string.equals(MASK_TYPE_EXCLUSIVE)) { - return OpUnitMask.EXCLUSIVE; - } - - return -1; - } - } - - /** - * Constructor for EventListProcessor. Initializes internal state. - */ - public EventListProcessor() { - super(); - umProcessor = new UnitMaskProcessor(); - } - - @Override - public void reset(Object callData) { - currentEventList = new ArrayList<>(); - } - - @Override - public void startElement(String name, Attributes attrs, Object callData) { - if (name.equals(EVENT_TAG)) { - // new event - currentEvent = new OpEvent(); - } else if (name.equals(UNIT_MASK_TAG)) { - // Tell the SAX handler to use the unit mask processor - OprofileSAXHandler.getInstance(callData).push(umProcessor); - } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { - // Our start tag: grab the counter number from the attributes - counter = Integer.parseInt(attrs.getValue(ATTR_EVENT_LIST_COUNTER)); - } else { - super.startElement(name, attrs, callData); - } - } - - @Override - public void endElement(String name, Object callData) { - if (name.equals(EVENT_TAG)) { - // Finished constructing an event. Add it to the list. - currentEventList.add(currentEvent); - } else if (name.equals(UNIT_MASK_TAG)) { - // Set the event's unit mask - currentEvent.setUnitMask(umProcessor.getResult()); - } else if (name.equals(NAME_TAG)) { - // Set event's name - currentEvent.setText(characters); - } else if (name.equals(DESCRIPTION_TAG)) { - // Set event's description - currentEvent.setTextDescription(characters); - } else if (name.equals(MINIMUM_COUNT_TAG)) { - // Set event's minimum count - currentEvent.setMinCount(Integer.parseInt(characters)); - } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { - OprofileSAXHandler.getInstance(callData).pop(name); - } - } - - public int getCounterNum() { - return counter; - } - - public OpEvent[] getEvents() { - OpEvent[] events = new OpEvent[currentEventList.size()]; - currentEventList.toArray(events); - return events; - } + // The current event being constructed + private OpEvent currentEvent; + private int counter; + private ArrayList<OpEvent> currentEventList; + + // An XML processor for reading the unit mask information for an event + private UnitMaskProcessor umProcessor; + + // XML elements recognized by this processor + private static final String EVENT_TAG = "event"; //$NON-NLS-1$ + private static final String UNIT_MASK_TAG = "unit-mask"; //$NON-NLS-1$ + private static final String NAME_TAG = "name"; //$NON-NLS-1$ + private static final String VALUE_TAG = "value"; //$NON-NLS-1$ + private static final String DESCRIPTION_TAG = "description"; //$NON-NLS-1$ + private static final String MASK_TAG = "mask"; //$NON-NLS-1$ + private static final String MINIMUM_COUNT_TAG = "minimum"; //$NON-NLS-1$ + private static final String ATTR_EVENT_LIST_COUNTER = "counter"; //$NON-NLS-1$ + + // This is a special processor which is used to deal with a single mask value + private static class MaskProcessor extends XMLProcessor { + private OpUnitMask.MaskInfo info; + + @Override + public void reset(Object callData) { + info = new OpUnitMask.MaskInfo(); + } + + @Override + public void endElement(String name, Object callData) { + if (name.equals(VALUE_TAG)) { + // Set mask's value + info.value = Integer.parseInt(characters); + } else if (name.equals(DESCRIPTION_TAG)) { + info.description = characters; + } else if (name.equals(NAME_TAG)) { + info.name = characters; + } else if (name.equals(MASK_TAG)) { + // Pop and pass mask tag to previous processor (UnitMaskProcessor) + OprofileSAXHandler.getInstance(callData).pop(MASK_TAG); + } + } + + /** + * Returns the information that has been collected about a mask. + * + * @return the mask information + */ + public OpUnitMask.MaskInfo getResult() { + return info; + } + } + + // This is a special processor to handle unit mask information + private class UnitMaskProcessor extends XMLProcessor { + // An ArrayList to hold all the valid masks for a unit mask. + private ArrayList<OpUnitMask.MaskInfo> masks; + + // The unit mask being constructed + private OpUnitMask unitMask; + + // An XML processor for each individual mask value. + private MaskProcessor maskProcessor; + + // XML elements recognized by this processor + private static final String MASK_TYPE_TAG = "type"; //$NON-NLS-1$ + private static final String MASK_DEFAULT_TAG = "default"; //$NON-NLS-1$ + private static final String MASK_TYPE_BITMASK = "bitmask"; //$NON-NLS-1$ + private static final String MASK_TYPE_MANDATORY = "mandatory"; //$NON-NLS-1$ + private static final String MASK_TYPE_EXCLUSIVE = "exclusive"; //$NON-NLS-1$ + + /** + * Constructor for UnitMaskProcessor. Initializes internal state. + */ + public UnitMaskProcessor() { + super(); + maskProcessor = new MaskProcessor(); + masks = new ArrayList<>(); + } + + @Override + public void reset(Object callData) { + unitMask = new OpUnitMask(); + masks.clear(); + } + + @Override + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(MASK_TAG)) { + // Tell SAX handler to use the mask processor + OprofileSAXHandler.getInstance(callData).push(maskProcessor); + } else { + super.startElement(name, attrs, callData); + } + } + + @Override + public void endElement(String name, Object callData) { + if (name.equals(MASK_TYPE_TAG)) { + // Set the mask type + unitMask.setType(getTypeFromString(characters)); + } else if (name.equals(MASK_DEFAULT_TAG)) { + // Set the default mask + unitMask.setDefault(Integer.parseInt(characters)); + } else if (name.equals(MASK_TAG)) { + // Add this mask description to the list of all masks + masks.add(maskProcessor.getResult()); + } else if (name.equals(UNIT_MASK_TAG)) { + // All done. Add the known masks to the unit mask + OpUnitMask.MaskInfo[] descs = new OpUnitMask.MaskInfo[masks.size()]; + masks.toArray(descs); + unitMask.setMaskDescriptions(descs); + + // Pop this processor and pass _UNIT_MASK_TAG to previoius processor + OprofileSAXHandler.getInstance(callData).pop(UNIT_MASK_TAG); + } + } + + /** + * Returns the constructed unit mask. + * + * @return the unit mask + */ + public OpUnitMask getResult() { + return unitMask; + } + + // Converts a string representing a mask type into an integer + private int getTypeFromString(String string) { + if (string.equals(MASK_TYPE_MANDATORY)) { + return OpUnitMask.MANDATORY; + } else if (string.equals(MASK_TYPE_BITMASK)) { + return OpUnitMask.BITMASK; + } else if (string.equals(MASK_TYPE_EXCLUSIVE)) { + return OpUnitMask.EXCLUSIVE; + } + + return -1; + } + } + + /** + * Constructor for EventListProcessor. Initializes internal state. + */ + public EventListProcessor() { + super(); + umProcessor = new UnitMaskProcessor(); + } + + @Override + public void reset(Object callData) { + currentEventList = new ArrayList<>(); + } + + @Override + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(EVENT_TAG)) { + // new event + currentEvent = new OpEvent(); + } else if (name.equals(UNIT_MASK_TAG)) { + // Tell the SAX handler to use the unit mask processor + OprofileSAXHandler.getInstance(callData).push(umProcessor); + } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { + // Our start tag: grab the counter number from the attributes + counter = Integer.parseInt(attrs.getValue(ATTR_EVENT_LIST_COUNTER)); + } else { + super.startElement(name, attrs, callData); + } + } + + @Override + public void endElement(String name, Object callData) { + if (name.equals(EVENT_TAG)) { + // Finished constructing an event. Add it to the list. + currentEventList.add(currentEvent); + } else if (name.equals(UNIT_MASK_TAG)) { + // Set the event's unit mask + currentEvent.setUnitMask(umProcessor.getResult()); + } else if (name.equals(NAME_TAG)) { + // Set event's name + currentEvent.setText(characters); + } else if (name.equals(DESCRIPTION_TAG)) { + // Set event's description + currentEvent.setTextDescription(characters); + } else if (name.equals(MINIMUM_COUNT_TAG)) { + // Set event's minimum count + currentEvent.setMinCount(Integer.parseInt(characters)); + } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { + OprofileSAXHandler.getInstance(callData).pop(name); + } + } + + public int getCounterNum() { + return counter; + } + + public OpEvent[] getEvents() { + OpEvent[] events = new OpEvent[currentEventList.size()]; + currentEventList.toArray(events); + return events; + } } diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/InfoAdapter.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/InfoAdapter.java index 258ed3dcee..3beb56b227 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/InfoAdapter.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/opxml/info/InfoAdapter.java @@ -131,9 +131,8 @@ public class InfoAdapter extends AbstractDataAdapter { /** * Set up the DOM for later manipulation * - * @param is - * the InpuStream resulting from running the ophelp command. This - * will be passed in as null for timer mode. + * @param is the InpuStream resulting from running the ophelp command. This will + * be passed in as null for timer mode. */ private void createDOM(InputStream is) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -405,12 +404,15 @@ public class InfoAdapter extends AbstractDataAdapter { Element unitMask = (Element) unitMaskList.item(j); String maskVal = unitMask.getAttribute(MASK); String maskDesc = unitMask.getAttribute(DESC); + String maskName = unitMask.getAttribute(NAME); Element newMask = newDoc.createElement(MASK); Element newVal = newDoc.createElement(VALUE); newVal.setTextContent(maskVal); Element newDesc = newDoc.createElement(DESCRIPTION); newDesc.setTextContent(maskDesc); + Element newName = newDoc.createElement(NAME); + newName.setTextContent(maskName); newMask.appendChild(newVal); newMask.appendChild(newDesc); diff --git a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/OprofileLaunchPlugin.java b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/OprofileLaunchPlugin.java index 0fa1c39318..522bfd0d26 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/OprofileLaunchPlugin.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/OprofileLaunchPlugin.java @@ -52,6 +52,7 @@ public class OprofileLaunchPlugin extends AbstractUIPlugin { public static final String attrCounterProfileUser(int nr) { return attrCounter(nr) + ".PROFILE_USER"; } //$NON-NLS-1$ public static final String attrCounterCount(int nr) { return attrCounter(nr) + ".COUNT"; } //$NON-NLS-1$ public static final String attrCounterUnitMask(int nr) { return attrCounter(nr) + ".UNIT_MASK"; } //$NON-NLS-1$ + public static final String attrCounterUnitMaskName(int nr) { return attrCounter(nr) + ".UNIT_MASK_NAME"; } //$NON-NLS-1$ public static final String attrNumberOfEvents(int nr) { return attrCounter(nr) + ".EVENTS"; } //$NON-NLS-1$ diff --git a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/configuration/OprofileCounter.java b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/configuration/OprofileCounter.java index e0512f031d..b76a589600 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/configuration/OprofileCounter.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/configuration/OprofileCounter.java @@ -154,6 +154,7 @@ public class OprofileCounter { if (daemonEvent[i].getEvent() != null) { config.setAttribute(OprofileLaunchPlugin.attrConterEvent(number, i), daemonEvent[i].getEvent().getText()); config.setAttribute(OprofileLaunchPlugin.attrCounterUnitMask(number), daemonEvent[i].getEvent().getUnitMask().getMaskValue()); + config.setAttribute(OprofileLaunchPlugin.attrCounterUnitMaskName(number), daemonEvent[i].getEvent().getUnitMask().getMaskName()); } config.setAttribute(OprofileLaunchPlugin.attrCounterProfileKernel(number), daemonEvent[i].getProfileKernel()); config.setAttribute(OprofileLaunchPlugin.attrCounterProfileUser(number), daemonEvent[i].getProfileUser()); @@ -174,6 +175,7 @@ public class OprofileCounter { for (int i = 0; i < numEvents; i++) { String str = config.getAttribute(OprofileLaunchPlugin.attrConterEvent(number, i), ""); //$NON-NLS-1$ int maskValue = config.getAttribute(OprofileLaunchPlugin.attrCounterUnitMask(number), OpUnitMask.SET_DEFAULT_MASK); + String maskName = config.getAttribute(OprofileLaunchPlugin.attrCounterUnitMaskName(number), ""); //$NON-NLS-1$ daemonEvent[i] = new OprofileDaemonEvent(); daemonEvent[i].setEvent(eventFromString(str)); @@ -183,6 +185,7 @@ public class OprofileCounter { } daemonEvent[i].getEvent().getUnitMask().setMaskValue(maskValue); + daemonEvent[i].getEvent().getUnitMask().setMaskName(maskName); daemonEvent[i].setProfileKernel(config.getAttribute(OprofileLaunchPlugin.attrCounterProfileKernel(number), false)); daemonEvent[i].setProfileUser(config.getAttribute(OprofileLaunchPlugin.attrCounterProfileUser(number), false)); diff --git a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java index 1f8789e5b1..44981b95fd 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/internal/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java @@ -130,6 +130,12 @@ public abstract class AbstractOprofileLaunchConfigurationDelegate extends Abstra spec.append(event.getResetCount()); spec.append(OPD_SETUP_EVENT_SEPARATOR); spec.append(event.getEvent().getUnitMask().getMaskValue()); + // Some platforms allow EXCLUSIVE masks with same bit value, but + // different names and thus, the name is needed when specifying. + if (event.getEvent().getUnitMask().getMaskName() != null) { + spec.append(OPD_SETUP_EVENT_SEPARATOR); + spec.append(event.getEvent().getUnitMask().getMaskName()); + } spec.append(OPD_SETUP_EVENT_SEPARATOR); spec.append((event.getProfileKernel() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE)); spec.append(OPD_SETUP_EVENT_SEPARATOR); |