2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.reports;
21 import peersim.core.*;
24 * This observer reports memory utilization (max, total and
25 * free, as defined by <code>java.lang.Runtime</code>).
27 * @author Alberto Montresor
28 * @version $Revision: 1.1 $
30 public class MemoryObserver implements Control
33 /** The runtime object to obtain memory info */
34 private final static Runtime r = Runtime.getRuntime();
36 /** The prefix to be printed */
37 private final String prefix;
40 * Constructor to be instantiated in PeerSim.
43 public MemoryObserver(String prefix)
48 public boolean execute()
50 System.out.println(prefix + ": max=" + r.maxMemory() + ", total=" +
51 r.totalMemory() + ", free=" + r.freeMemory());