Adding time and size metric collection to samples. Includes a new Timer
task for ant, to emit the needed time metric.
Patch by: fabbott
Review by: scottb
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2739 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/Timer.java b/build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/Timer.java
new file mode 100644
index 0000000..5f2c514
--- /dev/null
+++ b/build-tools/ant-gwt/src/com/google/gwt/ant/taskdefs/Timer.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.ant.taskdefs;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.TaskContainer;
+
+import java.util.Vector;
+
+/**
+ * A timer task for ant, which reports the total time to execute the contained
+ * tasks. It reports both a millisecond total and hour:minute:second.fraction
+ * formats.
+ */
+public class Timer extends Task implements TaskContainer {
+
+ private static final int MS_IN_HOUR = 60 * 60 * 1000;
+ private static final int MS_IN_MINUTE = 60 * 1000;
+ private static final double MS_IN_SECOND_FLOAT = 1000.0;
+
+ private Vector<Task> nested;
+ private String name;
+
+ public Timer() {
+ super();
+ nested = new Vector<Task>();
+ name = "";
+ }
+
+ public void addTask(Task newtask) {
+ nested.addElement(newtask);
+ }
+
+ public void execute() throws BuildException {
+ long start = System.currentTimeMillis();
+ for (Task task : nested) {
+ task.perform();
+ }
+ long duration = (System.currentTimeMillis() - start);
+ long hrs = duration / MS_IN_HOUR;
+ long min = (duration - (hrs * MS_IN_HOUR)) / MS_IN_MINUTE;
+ double sec = (duration - (hrs * MS_IN_HOUR) - (min * MS_IN_MINUTE))
+ / MS_IN_SECOND_FLOAT;
+
+ log("timer " + name + " timed " + duration + " ms. ("
+ + hrs + ":" + (min < 10 ? "0" : "") + min + ":" + sec + ")");
+ }
+
+ public void setName(String newname) {
+ name = newname;
+ }
+}
diff --git a/common.ant.xml b/common.ant.xml
index 4335c97..b2e2522 100755
--- a/common.ant.xml
+++ b/common.ant.xml
@@ -195,6 +195,19 @@
</sequential>
</macrodef>
+ <macrodef name="gwt.timer">
+ <attribute name="name"/>
+ <element name="timer.elements" implicit="true" optional="false"/>
+ <sequential>
+ <taskdef name="timer"
+ classname="com.google.gwt.ant.taskdefs.Timer"
+ classpath="${gwt.build.lib}/ant-gwt.jar" />
+ <timer name="@{name}">
+ <timer.elements/>
+ </timer>
+ </sequential>
+ </macrodef>
+
<macrodef name="gwt.checkstyle">
<element name="sourcepath" implicit="yes" optional="true" />
<sequential>
diff --git a/samples/build.xml b/samples/build.xml
index ccf4ff4..bd74c3c 100644
--- a/samples/build.xml
+++ b/samples/build.xml
@@ -45,9 +45,17 @@
</target>
<target name="build" description="Builds GWT">
- <antcall target="-do">
- <param name="target" value="build" />
- </antcall>
+ <gwt.timer name="all">
+ <antcall target="-do">
+ <param name="target" value="build" />
+ </antcall>
+ </gwt.timer>
+ <length property="gwt.sample.length">
+ <fileset dir="${gwt.build.out}/samples">
+ <include name="**/www/com*/**"/>
+ </fileset>
+ </length>
+ <echo message="compiled size of all samples is ${gwt.sample.length} bytes."/>
</target>
<target name="checkstyle" description="Static analysis of GWT source">
diff --git a/samples/common.ant.xml b/samples/common.ant.xml
index 249fa10..76bca28 100755
--- a/samples/common.ant.xml
+++ b/samples/common.ant.xml
@@ -43,12 +43,14 @@
<targetfiles path="${sample.build}/www/com.google.gwt.sample.${sample.package}.${sample.module}/com.google.gwt.sample.${sample.package}.${sample.module}.nocache.js" />
<sequential>
<mkdir dir="${sample.build}/www" />
- <java dir="${sample.build}" classname="com.google.gwt.dev.GWTCompiler" classpath="src:${sample.build}/bin:${gwt.user.jar}:${gwt.dev.jar}" fork="yes" failonerror="true">
- <jvmarg value="-Xmx256M"/>
- <arg value="-out" />
- <arg file="${sample.build}/www" />
- <arg value="com.google.gwt.sample.${sample.package}.${sample.module}" />
- </java>
+ <gwt.timer name="${sample.main}">
+ <java dir="${sample.build}" classname="com.google.gwt.dev.GWTCompiler" classpath="src:${sample.build}/bin:${gwt.user.jar}:${gwt.dev.jar}" fork="yes" failonerror="true">
+ <jvmarg value="-Xmx256M"/>
+ <arg value="-out" />
+ <arg file="${sample.build}/www" />
+ <arg value="com.google.gwt.sample.${sample.package}.${sample.module}" />
+ </java>
+ </gwt.timer>
</sequential>
</outofdate>
</target>