001/* Run a model over and over again. 002 003 Copyright (c) 2004-2016 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.actor.gui.test; 029 030import ptolemy.moml.MoMLSimpleApplication; 031 032/////////////////////////////////////////////////////////////////// 033//// Rerun 034 035/** 036 Run a MoML model over and over again. 037 This class reads in a MoML file and executes it over and over again. 038 The time and memory usage stats are printed on stdout. 039 040 For example to run a model 100 times: 041 <pre> 042 cd $PTII/ptolemy/actor/gui/test 043 java -classpath $PTII ptolemy.actor.gui.test.Rerun ../../lib/test/auto/Sinewave.xml 044 </pre> 045 046 To run the model 10 times: 047 <pre> 048 java -classpath $PTII ptolemy.actor.gui.test.Rerun 10 ../../lib/test/auto/Sinewave.xml 049 </pre> 050 051 To create a ptplot file of the times and memory: 052 <pre> 053 awk '{ t[NR] = $1; 054 m[NR] = substr($4, 0, length($4) - 1); 055 f[NR] = substr($6, 0, length($6) - 1); 056 } 057 END { print "dataset: time (ms)"; 058 for (i=1;i<=NR;i++) {print i, t[i]}; 059 print "dataset: memory (K)"; 060 for (i=1;i<=NR;i++) {print i, m[i]}; 061 print "dataset: free (K)"; 062 for (i=1;i>=NR;i++) {print i, f[i]}; 063 }' /tmp/t > /tmp/t.plt 064 065 </pre> 066 067 @author Christopher Hylands Brooks 068 @version $Id$ 069 @since Ptolemy II 4.1 070 @Pt.ProposedRating Red (eal) 071 @Pt.AcceptedRating Red (cxh) 072 */ 073public class Rerun extends MoMLSimpleApplication { 074 /** Parse the xml file and run it. 075 * @param xmlFileName A string that refers to an MoML file that 076 * contains a Ptolemy II model. The string should be 077 * a relative pathname. 078 * @exception Throwable If there was a problem parsing 079 * or running the model. 080 */ 081 public Rerun(String xmlFileName) throws Throwable { 082 super(xmlFileName); 083 } 084 085 /////////////////////////////////////////////////////////////////// 086 //// public methods //// 087 088 /** Create an instance of a single model and run it. 089 * @param args The command-line arguments naming the .xml file to run 090 */ 091 public static void main(String[] args) { 092 try { 093 // Constructing the Rerun object runs the model once, 094 // so we run it 100-1 more times. 095 int runs = 99; 096 String xmlFileName = null; 097 098 if (args.length == 2) { 099 try { 100 runs = Integer.parseInt(args[0]) - 1; 101 } catch (Exception ex) { 102 System.err.println("Failed to parse '" + args[0] 103 + "', using " + runs + " instead."); 104 ex.printStackTrace(); 105 } 106 107 xmlFileName = args[1]; 108 } else { 109 if (args.length == 1) { 110 xmlFileName = args[0]; 111 } else { 112 throw new IllegalArgumentException( 113 "Usage: java -classpath $PTII ptolemy.actor.gui.test.Rerun [reRuns] model.xml\n" 114 + " Where reRuns is an integer, " 115 + "defaults to 100"); 116 } 117 } 118 119 Rerun reRun = new Rerun(xmlFileName); 120 121 for (int i = 0; i < runs; i++) { 122 reRun.rerun(); 123 } 124 } catch (Throwable ex) { 125 System.err.println("Command failed: " + ex); 126 ex.printStackTrace(); 127 } 128 } 129}