xml analysis: internalize strings.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 18 Apr 2016 20:37:29 +0000 (16:37 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 2 May 2016 17:47:59 +0000 (13:47 -0400)
Stings are currently taking a major amount of memory. This patch reduces
the memory usage by making the strings internal (cached) so duplicates
are no longer copied in memory.

Change-Id: Id686ea8c0648ddf2a7d041b6975ffbab6607167c
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/70908
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java

index 7b6c1771078672aa08b52ed026c90f664d43f2ad..d04068c2cb343f08a647c719fd5c2ed3d95d5461 100644 (file)
@@ -146,7 +146,7 @@ public class TmfXmlPatternSegmentBuilder {
      */
     private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map<String, ITmfStateValue> fields, @Nullable TmfXmlScenarioInfo scenarioInfo) {
         for (TmfXmlPatternSegmentField field : fFields) {
-            fields.put(field.getName(), field.getValue(event, scenarioInfo));
+            fields.put(field.getName().intern(), field.getValue(event, scenarioInfo));
         }
         if (scenarioInfo != null) {
             addStoredFieldsContent(event, fields, scenarioInfo);
@@ -169,7 +169,7 @@ public class TmfXmlPatternSegmentBuilder {
             for (Entry<String, String> entry : ((XmlPatternStateProvider) fContainer).getStoredFields().entrySet()) {
                 ITmfStateValue value = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getStoredFieldValue(fContainer, entry.getValue(), info, event);
                 if (!value.isNull()) {
-                    fields.put(entry.getValue(), value);
+                    fields.put(entry.getValue().intern(), value);
                 }
             }
         }
@@ -338,7 +338,7 @@ public class TmfXmlPatternSegmentBuilder {
             } else {
                 name.append(fSegmentNameAttribute);
             }
-            return name.toString();
+            return name.toString().intern();
         }
     }
 }
index 6e9e6caad9d44949828f5828fb5b120e8fa01a3e..bae5c4e1fae25ff3c3affff8e0dc853d9de0833e 100644 (file)
@@ -94,15 +94,15 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute {
         switch (attribute.getAttribute(TmfXmlStrings.TYPE)) {
         case TmfXmlStrings.TYPE_CONSTANT:
             fType = StateAttributeType.CONSTANT;
-            fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE));
+            fName = getAttributeName(attribute);
             break;
         case TmfXmlStrings.EVENT_FIELD:
             fType = StateAttributeType.EVENTFIELD;
-            fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE));
+            fName = getAttributeName(attribute);
             break;
         case TmfXmlStrings.TYPE_LOCATION:
             fType = StateAttributeType.LOCATION;
-            fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE));
+            fName = getAttributeName(attribute);
             break;
         case TmfXmlStrings.TYPE_QUERY:
             List<@Nullable Element> childElements = XmlUtils.getChildElements(attribute);
@@ -118,7 +118,7 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute {
             break;
         case TmfXmlStrings.TYPE_EVENT_NAME:
             fType = StateAttributeType.EVENTNAME;
-            fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE));
+            fName = getAttributeName(attribute);
             break;
         case TmfXmlStrings.NULL:
             fType = StateAttributeType.NONE;
@@ -133,6 +133,10 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute {
         }
     }
 
+    private String getAttributeName(Element attribute) {
+        return fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)).intern();
+    }
+
     /**
      * @since 2.0
      */
index b80f0095ff749209691e965c490d8714cc87bed9..f32406ab594b09dbda6a852a8f29c1353134e53c 100644 (file)
@@ -185,7 +185,7 @@ public class TmfXmlPatternSegment implements ISegment {
             int length = in.readInt();
             byte[] bytes = new byte[length];
             in.read(bytes, 0, length);
-            String name = new String(bytes);
+            String name = new String(bytes).intern();
 
             Byte type = in.readByte();
             ITmfStateValue value;
@@ -203,7 +203,7 @@ public class TmfXmlPatternSegment implements ISegment {
                 length = in.readInt();
                 bytes = new byte[length];
                 in.read(bytes, 0, length);
-                value = TmfStateValue.newValueString(new String(bytes));
+                value = TmfStateValue.newValueString(new String(bytes).intern());
                 break;
             default:
                 throw new IOException("Read object failed : Invalid data"); //$NON-NLS-1$
This page took 0.029944 seconds and 5 git commands to generate.