]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.nativemem/src/org/simantics/nativemem/internal/win/ProcessMemoryCounters.java
(refs #7250) Merged feature/modularCHR to master.
[simantics/platform.git] / bundles / org.simantics.nativemem / src / org / simantics / nativemem / internal / win / ProcessMemoryCounters.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 org.simantics.nativemem.ProcessMemoryInfo;
15 import org.simantics.nativemem.internal.Util;
16
17 /**
18  * Architecture-independent version of the Windows PsApi PROCESS_MEMORY_COUNTERS
19  * structure.
20  * 
21  * @author Tuukka Lehtonen
22  */
23 public class ProcessMemoryCounters implements ProcessMemoryInfo {
24     public int PageFaultCount;
25     public long PeakWorkingSetSize;
26     public long WorkingSetSize;
27     public long QuotaPeakPagedPoolUsage;
28     public long QuotaPagedPoolUsage;
29     public long QuotaPeakNonPagedPoolUsage;
30     public long QuotaNonPagedPoolUsage;
31     public long PagefileUsage;
32     public long PeakPagefileUsage;
33     public long PrivateUsage;
34
35     @Override
36     public String toString() {
37         return "ProcessMemoryCounters [PageFaultCount="
38                 + PageFaultCount + ", PeakWorkingSetSize=" + PeakWorkingSetSize
39                 + ", WorkingSetSize=" + WorkingSetSize
40                 + ", QuotaPeakPagedPoolUsage=" + QuotaPeakPagedPoolUsage
41                 + ", QuotaPagedPoolUsage=" + QuotaPagedPoolUsage
42                 + ", QuotaPeakNonPagedPoolUsage=" + QuotaPeakNonPagedPoolUsage
43                 + ", QuotaNonPagedPoolUsage=" + QuotaNonPagedPoolUsage
44                 + ", PagefileUsage=" + PagefileUsage + ", PeakPagefileUsage="
45                 + PeakPagefileUsage + ", PrivateUsage=" + PrivateUsage + "]";
46     }
47
48     @Override
49     public String toHumanReadableString() {
50         StringBuilder sb = new StringBuilder();
51         sb.append("RSS                 ").append(Util.toMb(WorkingSetSize))
52         .append("M / ").append(Util.toMb(PeakWorkingSetSize))
53         .append("M").append(Util.NL)
54         .append("Paged/Nonpaged Pool ").append(Util.toKb(QuotaPagedPoolUsage)).append("K / ")
55         .append(Util.toKb(QuotaPeakPagedPoolUsage)).append("K  /  ")
56         .append(Util.toKb(QuotaNonPagedPoolUsage)).append("K / ")
57         .append(Util.toKb(QuotaPeakNonPagedPoolUsage)).append("K").append(Util.NL)
58         .append("Page File           ").append(Util.toMb(PagefileUsage))
59         .append("M / ").append(Util.toMb(PeakPagefileUsage))
60         .append("M (").append(PageFaultCount).append(" faults)");
61         return sb.toString();
62     }
63
64     @Override
65     public String headerRow() {
66         return "RSS [MB]\tPeak RSS [MB]\tPaged Pool Usage [kB]\tPeak Paged Pool Usage [kB]\tNonpaged Pool Usage [kB]\tPeak Nonpaged Pool Usage [kB]\tPage File Usage [MB]\tPeak Page File Usage [MB]\tPage Faults";
67     }
68
69     @Override
70     public String dataRow() {
71         return Util.toMb(WorkingSetSize) + "\t" + Util.toMb(PeakWorkingSetSize)
72         + "\t" + Util.toKb(QuotaPagedPoolUsage) + "\t" + Util.toKb(QuotaPeakPagedPoolUsage)
73         + "\t" + Util.toKb(QuotaNonPagedPoolUsage) + "\t" + Util.toKb(QuotaPeakNonPagedPoolUsage)
74         + "\t" + Util.toMb(PagefileUsage) + "\t" + Util.toMb(PeakPagefileUsage)
75         + "\t" + PageFaultCount;
76     }
77
78     public static void main(String[] args) {
79         System.out.println(new ProcessMemoryCounters().toHumanReadableString());
80         System.out.println(new ProcessMemoryCounters().headerRow());
81         System.out.println(new ProcessMemoryCounters().dataRow());
82     }
83
84 }