X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.nativemem%2Fsrc%2Forg%2Fsimantics%2Fnativemem%2FNativeMem.java;h=c902214ac9bcee3711f747bbb31451100719a2f8;hp=cfccc215447af083bbf6e5d032464309185400da;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.nativemem/src/org/simantics/nativemem/NativeMem.java b/bundles/org.simantics.nativemem/src/org/simantics/nativemem/NativeMem.java index cfccc2154..c902214ac 100644 --- a/bundles/org.simantics.nativemem/src/org/simantics/nativemem/NativeMem.java +++ b/bundles/org.simantics.nativemem/src/org/simantics/nativemem/NativeMem.java @@ -1,56 +1,56 @@ -package org.simantics.nativemem; - -import org.simantics.nativemem.internal.Arch; -import org.simantics.nativemem.internal.OS; -import org.simantics.nativemem.internal.Psapi32; -import org.simantics.nativemem.internal.Psapi64; - -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.WinNT.HANDLE; - - -public class NativeMem { - - /** - * @param out - * the structure to write the result into or null to - * create a new structure - * @return the result structure - */ - public static ProcessMemoryCounters getMemoryCounters(ProcessMemoryCounters out) { - if (out == null) - out = new ProcessMemoryCounters(); - - OS os = OS.calculate(); - Arch arch = Arch.calculate(); - switch (os) { - case WINDOWS: { - HANDLE proc = Kernel32.INSTANCE.GetCurrentProcess(); - switch (arch) { - case X86: { - Psapi32.PROCESS_MEMORY_COUNTERS_EX pmem = new Psapi32.PROCESS_MEMORY_COUNTERS_EX(); - boolean ok = Psapi32.INSTANCE.GetProcessMemoryInfo(proc, pmem, pmem.size()); - if (ok) - pmem.writeTo(out); - return out; - } - - case X86_64: { - Psapi64.PROCESS_MEMORY_COUNTERS_EX pmem = new Psapi64.PROCESS_MEMORY_COUNTERS_EX(); - boolean ok = Psapi64.INSTANCE.GetProcessMemoryInfo(proc, pmem, pmem.size()); - if (ok) - pmem.writeTo(out); - return out; - } - - default: - throw new UnsupportedOperationException("Architecture " + arch + " not supported on operating system " + os); - } - } - - default: - throw new UnsupportedOperationException("Operating system " + os + " not supported"); - } - } - +package org.simantics.nativemem; + +import org.simantics.nativemem.internal.Arch; +import org.simantics.nativemem.internal.OS; +import org.simantics.nativemem.internal.Psapi32; +import org.simantics.nativemem.internal.Psapi64; + +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.WinNT.HANDLE; + + +public class NativeMem { + + /** + * @param out + * the structure to write the result into or null to + * create a new structure + * @return the result structure + */ + public static ProcessMemoryCounters getMemoryCounters(ProcessMemoryCounters out) { + if (out == null) + out = new ProcessMemoryCounters(); + + OS os = OS.calculate(); + Arch arch = Arch.calculate(); + switch (os) { + case WINDOWS: { + HANDLE proc = Kernel32.INSTANCE.GetCurrentProcess(); + switch (arch) { + case X86: { + Psapi32.PROCESS_MEMORY_COUNTERS_EX pmem = new Psapi32.PROCESS_MEMORY_COUNTERS_EX(); + boolean ok = Psapi32.INSTANCE.GetProcessMemoryInfo(proc, pmem, pmem.size()); + if (ok) + pmem.writeTo(out); + return out; + } + + case X86_64: { + Psapi64.PROCESS_MEMORY_COUNTERS_EX pmem = new Psapi64.PROCESS_MEMORY_COUNTERS_EX(); + boolean ok = Psapi64.INSTANCE.GetProcessMemoryInfo(proc, pmem, pmem.size()); + if (ok) + pmem.writeTo(out); + return out; + } + + default: + throw new UnsupportedOperationException("Architecture " + arch + " not supported on operating system " + os); + } + } + + default: + throw new UnsupportedOperationException("Operating system " + os + " not supported"); + } + } + } \ No newline at end of file