]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/win/Psapi32.java
(refs #7250) Merged feature/modularCHR to master.
[simantics/platform.git] / bundles / org.simantics.nativemem / src / org / simantics / nativemem / internal / win / Psapi32.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 Psapi32 extends StdCallLibrary {
23
24     Psapi32 INSTANCE = (Psapi32) Native.loadLibrary("Psapi", Psapi32.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 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;
41
42         @Override
43         protected List<String> getFieldOrder() {
44             return PROCESS_MEMORY_COUNTERS_EX_FIELDS;
45         }
46
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"
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
75 }