1 /*******************************************************************************
2 * Copyright (c) 2016, 2017 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.nativemem.internal.win;
14 import java.util.Arrays;
15 import java.util.List;
17 import com.sun.jna.Native;
18 import com.sun.jna.Structure;
19 import com.sun.jna.platform.win32.WinNT.HANDLE;
20 import com.sun.jna.win32.StdCallLibrary;
22 public interface Psapi64 extends StdCallLibrary {
24 Psapi64 INSTANCE = (Psapi64) Native.loadLibrary("Psapi", Psapi64.class);
27 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms684874%28v=vs.85%29.aspx
29 public static class PROCESS_MEMORY_COUNTERS_EX extends Structure {
31 public int PageFaultCount;
32 public long PeakWorkingSetSize;
33 public long WorkingSetSize;
34 public long QuotaPeakPagedPoolUsage;
35 public long QuotaPagedPoolUsage;
36 public long QuotaPeakNonPagedPoolUsage;
37 public long QuotaNonPagedPoolUsage;
38 public long PagefileUsage;
39 public long PeakPagefileUsage;
40 public long PrivateUsage;
43 protected List<String> getFieldOrder() {
44 return PROCESS_MEMORY_COUNTERS_EX_FIELDS;
47 private static final List<String> PROCESS_MEMORY_COUNTERS_EX_FIELDS = Arrays.asList(new String[] {
48 "cb", "PageFaultCount",
49 "PeakWorkingSetSize", "WorkingSetSize",
50 "QuotaPeakPagedPoolUsage", "QuotaPagedPoolUsage",
51 "QuotaPeakNonPagedPoolUsage", "QuotaNonPagedPoolUsage",
52 "PagefileUsage", "PeakPagefileUsage", "PrivateUsage"
55 public void writeTo(ProcessMemoryCounters to) {
56 to.PageFaultCount = PageFaultCount;
57 to.PeakWorkingSetSize = PeakWorkingSetSize;
58 to.WorkingSetSize = WorkingSetSize;
59 to.QuotaPeakPagedPoolUsage = QuotaPeakPagedPoolUsage;
60 to.QuotaPagedPoolUsage = QuotaPagedPoolUsage;
61 to.QuotaPeakNonPagedPoolUsage = QuotaPeakNonPagedPoolUsage;
62 to.QuotaNonPagedPoolUsage = QuotaNonPagedPoolUsage;
63 to.PagefileUsage = PagefileUsage;
64 to.PeakPagefileUsage = PeakPagefileUsage;
65 to.PrivateUsage = PrivateUsage;
70 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms683219%28v=vs.85%29.aspx
72 boolean GetProcessMemoryInfo(HANDLE Process, PROCESS_MEMORY_COUNTERS_EX ppsmemCounters, int cb);