]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/win/Psapi64.java
(refs #7250) Merged feature/modularCHR to master.
[simantics/platform.git] / bundles / org.simantics.nativemem / src / org / simantics / nativemem / internal / win / Psapi64.java
1 /*******************************************************************************
2  * Copyright (c) 2016, 2017 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.nativemem.internal.win;
13
14 import java.util.Arrays;
15 import java.util.List;
16
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;
21
22 public interface Psapi64 extends StdCallLibrary {
23
24     Psapi64 INSTANCE = (Psapi64) Native.loadLibrary("Psapi", Psapi64.class);
25
26     /*
27      * https://msdn.microsoft.com/en-us/library/windows/desktop/ms684874%28v=vs.85%29.aspx
28      */
29     public static class PROCESS_MEMORY_COUNTERS_EX extends Structure {
30         public int cb;
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;
41
42         @Override
43         protected List<String> getFieldOrder() {
44             return PROCESS_MEMORY_COUNTERS_EX_FIELDS;
45         }
46
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"
53         });
54
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;
66         }
67     }
68
69     /*
70      * https://msdn.microsoft.com/en-us/library/windows/desktop/ms683219%28v=vs.85%29.aspx
71      */
72     boolean GetProcessMemoryInfo(HANDLE Process, PROCESS_MEMORY_COUNTERS_EX ppsmemCounters, int cb);
73
74 }