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 Psapi32 extends StdCallLibrary {
24 Psapi32 INSTANCE = (Psapi32) Native.loadLibrary("Psapi", Psapi32.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 int PeakWorkingSetSize;
33 public int WorkingSetSize;
34 public int QuotaPeakPagedPoolUsage;
35 public int QuotaPagedPoolUsage;
36 public int QuotaPeakNonPagedPoolUsage;
37 public int QuotaNonPagedPoolUsage;
38 public int PagefileUsage;
39 public int PeakPagefileUsage;
40 public int PrivateUsage;
43 protected List<String> getFieldOrder() {
44 return PROCESS_MEMORY_COUNTERS_EX_FIELDS;
47 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);