]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow tab-separated columnized logging of memory use 54/454/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 23 Apr 2017 10:23:43 +0000 (13:23 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 23 Apr 2017 10:23:43 +0000 (13:23 +0300)
refs #7166

Change-Id: I6a7f38757db1c3cfcd0d04cfedfd963fde4c5a4d

bundles/org.simantics.nativemem/src/org/simantics/nativemem/NativeMem.java
bundles/org.simantics.nativemem/src/org/simantics/nativemem/ProcessMemoryInfo.java
bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/CMemoryInfo.java
bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/DummyProcessMemoryInfo.java
bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/Util.java
bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/win/ProcessMemoryCounters.java

index bf761380312de52f69e32e574a3dc4dc16ab9482..5f7190f08ee588451e50f7322203dcb0da809b54 100644 (file)
@@ -28,7 +28,9 @@ import org.simantics.nativemem.internal.win.Psapi64;
 import com.sun.jna.platform.win32.Kernel32;
 import com.sun.jna.platform.win32.WinNT.HANDLE;
 
-
+/**
+ * @author Tuukka Lehtonen
+ */
 public class NativeMem {
 
     /**
index fb7a17a6126d8f3717bddac84559b95b4d729619..29eabb07f1c7b6710ab63d595114cc631bce8a48 100644 (file)
@@ -19,6 +19,21 @@ package org.simantics.nativemem;
  */
 public interface ProcessMemoryInfo {
 
-    public String toHumanReadableString();
+    /**
+     * @return a non-structured human readable string representation of this instances contents
+     */
+    String toHumanReadableString();
+
+    /**
+     * @return tab-separated row of text containing N columns of explanatory
+     *         header text for writing a tab-separated "CSV" file
+     */
+    String headerRow();
+
+    /**
+     * @return tab-separated row of text containing N columns of data values
+     *         that match the explanations provided by {@link #headerRow()}
+     */
+    String dataRow();
 
 }
\ No newline at end of file
index aca7fa9e559a655554326665d22ddd90fda0c365..7412a73ffc6b2cb1c1be89567cb27dc9e82aaef4 100644 (file)
@@ -28,12 +28,29 @@ public class CMemoryInfo implements ProcessMemoryInfo {
                 + peakRSS + "]";
     }
 
+    @Override
     public String toHumanReadableString() {
         StringBuilder sb = new StringBuilder();
-        sb.append("Memory Use [Current RSS = ").append(currentRSS)
-        .append(" MB, Peak RSS = ").append(Util.toMb(peakRSS))
-        .append(" MB]");
+        sb.append("RSS ").append(Util.toMb(currentRSS))
+        .append("M / ").append(Util.toMb(peakRSS))
+        .append("M");
         return sb.toString();
     }
 
+    @Override
+    public String headerRow() {
+        return "RSS [MB]\tPeak RSS [MB]";
+    }
+
+    @Override
+    public String dataRow() {
+        return Util.toMb(currentRSS) + "\t" + Util.toMb(peakRSS);
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new CMemoryInfo().toHumanReadableString());
+        System.out.println(new CMemoryInfo().headerRow());
+        System.out.println(new CMemoryInfo().dataRow());
+    }
+
 }
\ No newline at end of file
index 8f001c47b49267d92a4e1fbe73b7715a4c7039ee..032d4fb5d2649cd7bfea638ae42880546d07aa27 100644 (file)
@@ -21,7 +21,17 @@ public enum DummyProcessMemoryInfo implements ProcessMemoryInfo {
 
        @Override
        public String toHumanReadableString() {
-               return "Memory consumption information not available for this platform (" + OS.calculate() + "; " + Arch.calculate() + ")";
+               return "Native process memory consumption information not available for this platform (" + OS.calculate() + "; " + Arch.calculate() + ")";
+       }
+
+       @Override
+       public String headerRow() {
+               return "";
+       }
+
+       @Override
+       public String dataRow() {
+               return "";
        }
 
 }
index fcfb07f18503b6bb97f7d70202c3bc5a4d77d51f..666537630c2a09c142941c8dc8b051ac8d078185 100644 (file)
@@ -16,8 +16,14 @@ package org.simantics.nativemem.internal;
  */
 public class Util {
 
-    public static double toMb(long bytes) {
-        return (double) bytes / 1048576.0;
+    public static final String NL = String.format("%n");
+
+    public static long toMb(long numBytes) {
+        return (numBytes + (512 * 1024)) / (1024 * 1024);
+    }
+
+    public static long toKb(long numBytes) {
+        return (numBytes + 512) / 1024;
     }
 
 }
\ No newline at end of file
index 9c68a54483a437616562823c89d9b8d88757ebf8..9f9129aabd671be3418884b2f61316f81f6d1552 100644 (file)
@@ -45,20 +45,40 @@ public class ProcessMemoryCounters implements ProcessMemoryInfo {
                 + PeakPagefileUsage + ", PrivateUsage=" + PrivateUsage + "]";
     }
 
+    @Override
     public String toHumanReadableString() {
         StringBuilder sb = new StringBuilder();
-        sb.append("ProcessMemoryCounters [\n\tPageFaultCount             = ").append(PageFaultCount)
-        .append(",\n\tPeakWorkingSetSize         = ").append(Util.toMb(PeakWorkingSetSize))
-        .append(" MB,\n\tWorkingSetSize             = ").append(Util.toMb(WorkingSetSize))
-        .append(" MB,\n\tQuotaPeakPagedPoolUsage    = ").append(Util.toMb(QuotaPeakPagedPoolUsage))
-        .append(" MB,\n\tQuotaPagedPoolUsage        = ").append(Util.toMb(QuotaPagedPoolUsage))
-        .append(" MB,\n\tQuotaPeakNonPagedPoolUsage = ").append(Util.toMb(QuotaPeakNonPagedPoolUsage))
-        .append(" MB,\n\tQuotaNonPagedPoolUsage     = ").append(Util.toMb(QuotaNonPagedPoolUsage))
-        .append(" MB,\n\tPagefileUsage              = ").append(Util.toMb(PagefileUsage))
-        .append(" MB,\n\tPeakPagefileUsage          = ").append(Util.toMb(PeakPagefileUsage))
-        .append(" MB,\n\tPrivateUsage               = ").append(Util.toMb(PrivateUsage))
-        .append(" MB]");
+        sb.append("RSS                 ").append(Util.toMb(WorkingSetSize))
+        .append("M / ").append(Util.toMb(PeakWorkingSetSize))
+        .append("M").append(Util.NL)
+        .append("Paged/Nonpaged Pool ").append(Util.toKb(QuotaPagedPoolUsage)).append("K / ")
+        .append(Util.toKb(QuotaPeakPagedPoolUsage)).append("K  /  ")
+        .append(Util.toKb(QuotaNonPagedPoolUsage)).append("K / ")
+        .append(Util.toKb(QuotaPeakNonPagedPoolUsage)).append("K").append(Util.NL)
+        .append("Page File           ").append(Util.toMb(PagefileUsage))
+        .append("M / ").append(Util.toMb(PeakPagefileUsage))
+        .append("M (").append(PageFaultCount).append(" faults)");
         return sb.toString();
     }
 
+    @Override
+    public String headerRow() {
+        return "RSS [MB]\tPeak RSS [MB]\tPaged Pool Usage [kB]\tPeak Paged Pool Usage [kB]\tNonpaged Pool Usage [kB]\tPeak Nonpaged Pool Usage [kB]\tPage File Usage [MB]\tPeak Page File Usage [MB]\tPage Faults";
+    }
+
+    @Override
+    public String dataRow() {
+        return Util.toMb(WorkingSetSize) + "\t" + Util.toMb(PeakWorkingSetSize)
+        + "\t" + Util.toKb(QuotaPagedPoolUsage) + "\t" + Util.toKb(QuotaPeakPagedPoolUsage)
+        + "\t" + Util.toKb(QuotaNonPagedPoolUsage) + "\t" + Util.toKb(QuotaPeakNonPagedPoolUsage)
+        + "\t" + Util.toMb(PagefileUsage) + "\t" + Util.toMb(PeakPagefileUsage)
+        + "\t" + PageFaultCount;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new ProcessMemoryCounters().toHumanReadableString());
+        System.out.println(new ProcessMemoryCounters().headerRow());
+        System.out.println(new ProcessMemoryCounters().dataRow());
+    }
+
 }
\ No newline at end of file