source: src/main/java/weka/core/SystemInfo.java @ 10

Last change on this file since 10 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.2 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    SystemInfo.java
19 *    Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22package weka.core;
23
24import weka.gui.LookAndFeel;
25
26import java.util.Collections;
27import java.util.Enumeration;
28import java.util.Hashtable;
29import java.util.Properties;
30import java.util.Vector;
31
32/**
33 * This class prints some information about the system setup, like Java
34 * version, JVM settings etc. Useful for Bug-Reports.
35 *
36 * @author FracPete (fracpete at waikato dot ac dot nz)
37 * @version $Revision: 5953 $
38 */
39public class SystemInfo
40  implements RevisionHandler {
41 
42  /** for storing the information */
43  private Hashtable<String,String> m_Info = null;
44 
45  /**
46   * initializes the object and reads the system information
47   */
48  public SystemInfo() {
49    m_Info = new Hashtable<String,String>();
50    readProperties();
51  }
52
53  /**
54   * reads all the properties and stores them in the hashtable
55   */
56  private void readProperties() {
57    Properties          props;
58    Enumeration         enm;
59    String              name;
60    String[]            laf;
61    String              tmpStr;
62    int                 i;
63    Memory              mem;
64   
65    m_Info.clear();
66
67    // System information
68    props = System.getProperties();
69    enm   = props.propertyNames();
70    while (enm.hasMoreElements()) {
71      name = (String)enm.nextElement();
72      m_Info.put(name, (String)props.get(name));
73    }
74
75    // additional WEKA info
76    m_Info.put("weka.version", Version.VERSION);
77
78    // look and feel info
79    laf    = LookAndFeel.getInstalledLookAndFeels();
80    tmpStr = "";
81    for (i = 0; i < laf.length; i++) {
82      if (i > 0)
83        tmpStr += ",";
84      tmpStr += laf[i];
85    }
86    m_Info.put("ui.installedLookAndFeels", tmpStr);
87    m_Info.put("ui.currentLookAndFeel", LookAndFeel.getSystemLookAndFeel());
88
89    // memory info
90    mem = new Memory();
91    m_Info.put(
92        "memory.initial", 
93        "" + Utils.doubleToString(Memory.toMegaByte(mem.getInitial()), 1) + "MB" 
94        + " (" + mem.getInitial() + ")");
95    m_Info.put(
96        "memory.max", 
97        "" + Utils.doubleToString(Memory.toMegaByte(mem.getMax()), 1) + "MB"
98        + " (" + mem.getMax() + ")");
99  }
100
101  /**
102   * returns a copy of the system info. the key is the name of the property
103   * and the associated object is the value of the property (a string).
104   */
105  public Hashtable getSystemInfo() {
106    return (Hashtable) m_Info.clone();
107  }
108
109  /**
110   * returns a string representation of all the system properties
111   */
112  public String toString() {
113    Enumeration<String>     enm;
114    String          result;
115    String          key;
116    Vector<String>          keys;
117    int             i;
118    String          value;
119
120    result = "";
121    keys   = new Vector<String>();
122   
123    // get names and sort them
124    enm = m_Info.keys();
125    while (enm.hasMoreElements())
126      keys.add(enm.nextElement());
127    Collections.sort(keys);
128   
129    // generate result
130    for (i = 0; i < keys.size(); i++) {
131      key   = keys.get(i).toString();
132      value = m_Info.get(key).toString();
133      if (key.equals("line.separator"))
134        value = Utils.backQuoteChars(value);
135      result += key + ": " + value + "\n";
136    }
137
138    return result;
139  }
140 
141  /**
142   * Returns the revision string.
143   *
144   * @return            the revision
145   */
146  public String getRevision() {
147    return RevisionUtils.extract("$Revision: 5953 $");
148  }
149
150  /**
151   * for printing the system info to stdout.
152   */
153  public static void main(String[] args) {
154    System.out.println(new SystemInfo());
155  }
156}
Note: See TracBrowser for help on using the repository browser.