1 /*
2  * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package vm.share.monitoring.data;
24 
25 import java.io.Serializable;
26 import java.lang.management.MemoryUsage;
27 import nsk.share.log.Log;
28 
29 public class MemoryUsageData implements Serializable {
30         private long init;
31         private long used;
32         private long committed;
33         private long max;
34 
MemoryUsageData(long init, long used, long committed, long max)35         public MemoryUsageData(long init, long used, long committed, long max) {
36                 this.init = init;
37                 this.used = used;
38                 this.committed = committed;
39                 this.max = max;
40         }
41 
MemoryUsageData(MemoryUsage usage)42         public MemoryUsageData(MemoryUsage usage) {
43                 this.init = usage.getInit();
44                 this.used = usage.getUsed();
45                 this.committed = usage.getCommitted();
46                 this.max = usage.getMax();
47         }
48 
MemoryUsageData(MemoryUsageData usage, MemoryUsageData usage1)49         public MemoryUsageData(MemoryUsageData usage, MemoryUsageData usage1) {
50                 this.init = usage.getInit() + usage1.getInit();
51                 this.used = usage.getUsed() + usage1.getUsed();
52                 this.committed = usage.getCommitted() + usage1.getCommitted();
53                 this.max = usage.getMax() + usage1.getMax();
54         }
55 
getInit()56         public long getInit() {
57                 return init;
58         }
59 
getUsed()60         public long getUsed() {
61                 return used;
62         }
63 
getMax()64         public long getMax() {
65                 return max;
66         }
67 
getFree()68         public long getFree() {
69                 return committed - used;
70         }
71 
getCommitted()72         public long getCommitted() {
73                 return committed;
74         }
75 
log(Log log)76         public void log(Log log) {
77                 log.info("    Init: " + init);
78                 log.info("    Used: " + used);
79                 log.info("    Committed: " + committed);
80                 log.info("    Max: " + max);
81         }
82 }
83