linux.core: fix memory allocation issue.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 14 Dec 2016 22:07:03 +0000 (17:07 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 17 Dec 2016 12:56:05 +0000 (07:56 -0500)
The order field in page alloc/free say how many pages are allocated.
It was ignored, which gave false totals.

It is artificially limited to 2^62 page size, as larger would garanty
an overflow.

With this patch, memory overflows can occur much faster, but only on
systems which trace or report over Long.MAX_VALUE memory.

Change-Id: I5c805115cb3aaa5c6bc6146a6dc0db20f11854ef
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/87181
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernelmemoryusage/KernelMemoryStateProviderTest.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/testfiles/KernelMemoryAnalysis_testTrace.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernelmemoryusage/KernelMemoryStateProvider.java

index 5142dab8329a5e4f8b661b37e8509444304a04e8..93cf0ccef1932090e076a025a217f0d2272ac7fb 100644 (file)
@@ -124,7 +124,7 @@ public class KernelMemoryStateProviderTest {
         threadEvent.put(1L, PAGE_SIZE); // kmem_mm_page_alloc at timestamp = 1
         threadEvent.put(2L, -PAGE_SIZE); // kmem_mm_page_free at timestamp = 2
         threadEvent.put(3L, -PAGE_SIZE); // kmem_mm_page_free at timestamp = 3
-        threadEvent.put(17L, PAGE_SIZE); // kmem_mm_page_alloc at timestamp = 17
+        threadEvent.put(17L, PAGE_SIZE << 2); // kmem_mm_page_alloc at timestamp = 17
         threadEvent.put(22L, -PAGE_SIZE); // kmem_mm_page_free at timestamp = 22
         threadEvent.put(28L, -PAGE_SIZE); // kmem_mm_page_free at timestamp = 28
         threadEvent.put(29L, PAGE_SIZE); // kmem_mm_page_alloc at timestamp = 29
index b82e4d16795170f05785238c58208230a6642dc9..ac08c9b1112f685a5983d7960e30198fe210dc3f 100644 (file)
@@ -8,33 +8,41 @@
 <event timestamp="1" name="kmem_mm_page_alloc">
 <field name="cpu" value="0" type="int" />
 <field name="tid" value="proc1" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="2" name="kmem_mm_page_free">
 <field name="cpu" value="1" type="int" />
 <field name="tid" value="proc2" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="3" name="kmem_mm_page_free">
 <field name="cpu" value="1" type="int" />
 <field name="tid" value="proc1" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="17" name="kmem_mm_page_alloc">
 <field name="cpu" value="0" type="int" />
 <field name="tid" value="proc3" type="string" />
+<field name="order" value="2" type="long" />
 </event>
 <event timestamp="22" name="kmem_mm_page_free">
 <field name="cpu" value="1" type="int" />
 <field name="tid" value="proc4" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="28" name="kmem_mm_page_free">
 <field name="cpu" value="1" type="int" />
 <field name="tid" value="proc2" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="29" name="kmem_mm_page_alloc">
 <field name="cpu" value="0" type="int" />
 <field name="tid" value="proc4" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 <event timestamp="30" name="kmem_mm_page_alloc">
 <field name="cpu" value="0" type="int" />
 <field name="tid" value="proc3" type="string" />
+<field name="order" value="0" type="long" />
 </event>
 </trace>
\ No newline at end of file
index 2847bd2bd76f1dffc27543966f6f9dce07adbd53..bb5d384b7406a59da038c80452416f104c5e1320 100644 (file)
@@ -49,10 +49,12 @@ public class KernelMemoryStateProvider extends AbstractTmfStateProvider {
     public static final String OTHER_TID = "other"; //$NON-NLS-1$
 
     /* Version of this state provider */
-    private static final int VERSION = 1;
+    private static final int VERSION = 2;
 
     private static final int PAGE_SIZE = 4096;
 
+    private static final long MAX_ORDER = 62; // Larger than that would overflow
+
     private IKernelAnalysisEventLayout fLayout;
 
     /**
@@ -92,8 +94,19 @@ public class KernelMemoryStateProvider extends AbstractTmfStateProvider {
         }
 
         try {
+            String fieldOrder = fLayout.fieldOrder();
+            if (fieldOrder != null) {
+                Long value = event.getContent().getFieldValue(Long.class, fieldOrder);
+                if (value != null) {
+                    if (value > MAX_ORDER || value < 0) {
+                        Activator.getDefault().logWarning("Order of alloc is outside of acceptable range : " + value); //$NON-NLS-1$
+                        return;
+                    }
+                    inc <<= value;
+                }
+            }
             ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
-            long ts = event.getTimestamp().getValue();
+            long ts = event.getTimestamp().toNanos();
 
             Integer tidField = KernelTidAspect.INSTANCE.resolve(event);
             String tid;
@@ -121,7 +134,7 @@ public class KernelMemoryStateProvider extends AbstractTmfStateProvider {
                 ss.modifyAttribute(ts, TmfStateValue.newValueLong(currentMemoryValue), lowestMemoryQuark);
             }
         } catch (AttributeNotFoundException e) {
-            Activator.getDefault().logError(e.getMessage(), e);
+            Activator.getDefault().logError(String.valueOf(e.getMessage()), e);
         }
     }
 
This page took 0.027017 seconds and 5 git commands to generate.