001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/evolve/ 022 */ 023 024 package EVolve; 025 026 import java.util.*; 027 import EVolve.data.DataSource; 028 import EVolve.visualization.DefaultPredictorFactory; 029 import EVolve.visualization.VizFactory.*; 030 031 public class Main { 032 private static VisualizationFactory[] factory; 033 private static ArrayList dsList; 034 public static ArrayList availableDataSource; 035 036 public static void main(String[] args) { 037 // initialize XML driver 038 System.setProperty("org.xml.sax.driver", "org.apache.crimson.parser.XMLReaderImpl"); 039 040 dsList = new ArrayList(); 041 availableDataSource = new ArrayList(); 042 043 availableDataSource.add("EVolve.DemoSource"); 044 availableDataSource.add("EVolve.PMCPentiumSource"); 045 parseArgs(args); 046 047 /* This code has been moved to 'addVizLibrary' */ 048 /* 049 VisualizationFactory[] factory = new VisualizationFactory[10]; 050 factory[0] = new TableVizFactory(); 051 factory[1] = new BarChartVizFactory(); 052 factory[2] = new ThreadHotspotVizFactory(); 053 factory[3] = new HotspotVizFactory(); 054 factory[4] = new StackHotspotVizFactory(); 055 factory[5] = new PredictionVizFactory(); 056 factory[6] = new CorrelationVizFactory(); 057 factory[7] = new StackVizFactory(); 058 factory[8] = new DotPlotVizFactory(); 059 factory[9] = new MissPredictionMetricVizFactory(); 060 //factory[9] = new EscObjectVizFactory(); 061 ((PredictionVizFactory)(factory[5])).addPredictorFactory(new DefaultPredictorFactory()); 062 ((MissPredictionMetricVizFactory)(factory[9])).addPredictorFactory(new DefaultPredictorFactory()); 063 */ 064 065 //Scene.start(dataSource, factory); 066 Scene.start(dsList, factory); 067 } 068 069 public static void parseArgs(String[] args) { 070 factory = null; 071 072 HashMap vizFactories = new HashMap(); 073 074 addVizLibrary(vizFactories); 075 076 try { 077 for (int i = 0; i < args.length; i++) { 078 if (args[i].equals("-d") || args[i].equals("--datasource")) { 079 StringTokenizer token = new StringTokenizer(args[++i],","); 080 while (token.hasMoreTokens()) { 081 String name = token.nextToken(); 082 Object dsource = instanciateDataSource(name); 083 084 if (dsource == null) { 085 System.err.println("EVolve> Failed to instanciate class: \"" + name + "\""); 086 System.exit(1); 087 } else if (dsource instanceof DataSource) { 088 dsList.add(dsource); 089 } else { 090 System.err.println("EVolve> \"" + args[i] + "\" is not a DataSource"); 091 System.exit(2); 092 } 093 } 094 } else if (args[i].equals("+v") || args[i].equals("--addviz")) { 095 Object viz = instanciateFromName(args[++i]); 096 if (viz == null) { 097 System.err.println("EVolve> Failed to instanciate class: \"" + args[i] + "\""); 098 System.exit(1); 099 } else if (viz instanceof VisualizationFactory) { 100 vizFactories.put(args[i], viz); 101 } else { 102 System.err.println("EVolve> \"" + args[i] + "\" is not a VisualizationFactory"); 103 System.exit(2); 104 } 105 } else if (args[i].equals("-v") || args[i].equals("--removeviz")) { 106 if (vizFactories.containsKey(args[++i])) { 107 vizFactories.remove(args[i]); 108 } else { 109 System.err.println("EVolve> Unknown visualization factory: \"" + args[i] + "\""); 110 System.exit(1); 111 } 112 } else if (args[i].equals("-h") || args[i].equals("--help")) { 113 System.out.println("Usage: java evolve.Main [options]"); 114 System.out.println(" where options can be:"); 115 System.out.println(" -h | --help"); 116 System.out.println(" Prints this help message"); 117 System.out.println(" -d | --datasource <data_source_1,data_source_2,...>"); 118 System.out.println(" Specifies the class name of the data source to be used"); 119 System.out.println(" +v | --addviz <viz factory>"); 120 System.out.println(" Specifies the name of a visualization factory to be registered with EVolve"); 121 System.out.println(" -v | --removeviz <viz factory>"); 122 System.out.println(" Specifies the name of a visualization factory to be unregistered with EVolve"); 123 System.out.println(""); 124 System.out.println("Visit the EVolve page at http://www.sable.mcgill.ca/evolve"); 125 System.exit(0); 126 } else { 127 System.err.println("EVolve> Unrecognized option: \"" + args[i] + "\""); 128 System.exit(1); 129 } 130 } 131 } catch (ArrayIndexOutOfBoundsException e) { 132 System.err.println("EVolve> Missing argument!!"); 133 System.exit(3); 134 } 135 136 if (dsList.size() == 0) { 137 dsList.add(new DemoSource()); // provide a default data source 138 } 139 140 Collection factories = vizFactories.values(); 141 factory = new VisualizationFactory[factories.size()]; 142 int j = 0; 143 Iterator it = factories.iterator(); 144 while (it.hasNext()) { 145 factory[j++] = (VisualizationFactory) it.next(); 146 } 147 } 148 149 private static void addVizLibrary(HashMap vizFactories) { 150 vizFactories.put("TableVizFactory", new TableVizFactory()); 151 vizFactories.put("BarChartVizFactory", new BarChartVizFactory()); 152 vizFactories.put("ThreadHotspotVizFactory", new ThreadHotspotVizFactory()); 153 vizFactories.put("HotspotVizFactory", new HotspotVizFactory()); 154 vizFactories.put("StackHotspotVizFactory", new StackHotspotVizFactory()); 155 PredictionVizFactory predViz = new PredictionVizFactory(); 156 predViz.addPredictorFactory(new DefaultPredictorFactory()); 157 vizFactories.put("PredictionVizFactory", predViz); 158 vizFactories.put("CorrelationVizFactory", new CorrelationVizFactory()); 159 vizFactories.put("StackVizFactory", new StackVizFactory()); 160 vizFactories.put("DotPlotVizFactory", new DotPlotVizFactory()); 161 MissPredictionMetricVizFactory missPredViz = new MissPredictionMetricVizFactory(); 162 missPredViz.addPredictorFactory(new DefaultPredictorFactory()); 163 vizFactories.put("MissPredictionMetricVizFactory", missPredViz); 164 EventVizFactory eventViz = new EventVizFactory(); 165 eventViz.addPredictorFactory(new DefaultPredictorFactory()); 166 vizFactories.put("EventVizFactory", eventViz); 167 vizFactories.put("RelationshipVizFactory", new RelationshipVizFactory()); 168 vizFactories.put("HardwareCounterVizFactory", new HardwareCounterVizFactory()); 169 } 170 171 private static Object instanciateFromName(String className) { 172 /* Get a Class object corresponding to the given 173 class name using Java's Reflection API */ 174 try { 175 Class klass = null; 176 try { 177 klass = Class.forName(className); 178 } catch (ClassNotFoundException e) { 179 System.err.println("EVolve> Class not found: \"" + className + "\""); 180 return null; 181 } 182 183 return klass.newInstance(); 184 } catch (InstantiationException e) { 185 } catch (IllegalAccessException e) { 186 } 187 188 return null; 189 } 190 191 public static Object instanciateDataSource(String className) { 192 Object retObj = instanciateFromName(className); 193 if ((retObj != null)&&(!availableDataSource.contains(className))) { 194 if (retObj instanceof DataSource) { 195 availableDataSource.add(className); 196 } 197 } 198 199 return retObj; 200 } 201 } 202