ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r576173 - in /ant/core/trunk: WHATSNEW docs/manual/listeners.html src/main/org/apache/tools/ant/listener/ProfileLogger.java
Date Sun, 16 Sep 2007 20:54:18 GMT
Author: jkf
Date: Sun Sep 16 13:54:17 2007
New Revision: 576173

URL: http://svn.apache.org/viewvc?rev=576173&view=rev
Log:
Added a basic profiling logger.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/listener/ProfileLogger.java
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/listeners.html

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=576173&r1=576172&r2=576173&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sun Sep 16 13:54:17 2007
@@ -173,6 +173,8 @@
 
 Other changes:
 --------------
+* Profiling logger has been added with basic profiling capabilities.
+
 * <script> now has basic support for JavaFX scripts
 
 * SSH task can now take a command parameter containing the commands to execute.

Modified: ant/core/trunk/docs/manual/listeners.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/listeners.html?rev=576173&r1=576172&r2=576173&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/listeners.html (original)
+++ ant/core/trunk/docs/manual/listeners.html Sun Sep 16 13:54:17 2007
@@ -111,8 +111,14 @@
     <td width="34%">BuildLogger</td>
   </tr>
   <tr>
-    <td width="33%"><code><a href="#BigProjectLogger">org.apache.tools.ant.BigProjectLogger</a></code></td>
+    <td width="33%"><code><a href="#BigProjectLogger">org.apache.tools.ant.listener.BigProjectLogger</a></code></td>
     <td width="33%">Prints the project name every target</td>
+    <td width="34%">BuildLogger</td>
+  </tr>
+  <tr>
+    <td width="33%"><code><a href="#ProfileLogger">org.apache.tools.ant.listener.ProfileLogger</a></code></td>
+    <td width="33%">The default logger, with start times, end times and
+    durations added for each task and target.</td>
     <td width="34%">BuildLogger</td>
   </tr>
 </table>

Added: ant/core/trunk/src/main/org/apache/tools/ant/listener/ProfileLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/listener/ProfileLogger.java?rev=576173&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/listener/ProfileLogger.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/listener/ProfileLogger.java Sun Sep 16 13:54:17
2007
@@ -0,0 +1,112 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 org.apache.tools.ant.listener;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.util.StringUtils;
+
+/**
+ * This is a special logger that is designed to profile builds.
+ *
+ * @since Ant1.8
+ */
+public class ProfileLogger extends DefaultLogger {
+
+    private Map profileData = new HashMap(); // <Object, Date>
+
+    /**
+     * Logs a message to say that the target has started.
+     * 
+     * @param event
+     *            An event with any relevant extra information. Must not be
+     *            <code>null</code>.
+     */
+    public void targetStarted(BuildEvent event) {
+        Date now = new Date();
+        String name = "Target " + event.getTarget().getName();
+        logStart(event, now, name);
+        profileData.put(event.getTarget(), now);
+    }
+
+    /**
+     * Logs a message to say that the target has finished.
+     * 
+     * @param event
+     *            An event with any relevant extra information. Must not be
+     *            <code>null</code>.
+     */
+    public void targetFinished(BuildEvent event) {
+        Date start = (Date) profileData.remove(event.getTarget());
+        String name = "Target " + event.getTarget().getName();
+        logFinish(event, start, name);
+    }
+
+    /**
+     * Logs a message to say that the task has started.
+     * 
+     * @param event
+     *            An event with any relevant extra information. Must not be
+     *            <code>null</code>.
+     */
+    public void taskStarted(BuildEvent event) {
+        String name = event.getTask().getTaskName();
+        Date now = new Date();
+        logStart(event, now, name);
+        profileData.put(event.getTask(), now);
+    }
+
+    /**
+     * Logs a message to say that the task has finished.
+     * 
+     * @param event
+     *            An event with any relevant extra information. Must not be
+     *            <code>null</code>.
+     */
+    public void taskFinished(BuildEvent event) {
+        Date start = (Date) profileData.remove(event.getTask());
+        String name = event.getTask().getTaskName();
+        logFinish(event, start, name);
+    }
+
+    private void logFinish(BuildEvent event, Date start, String name) {
+        Date now = new Date();
+        String msg = null;
+        if (start != null) {
+            long diff = now.getTime() - start.getTime();
+            msg = StringUtils.LINE_SEP + name + ": finished" + now + " ("
+                    + diff + "ms)";
+        } else {
+            msg = StringUtils.LINE_SEP + name + ": finished" + now
+                    + " (unknown duration, start not detected)";
+        }
+        printMessage(msg, out, event.getPriority());
+        log(msg);
+    }
+
+    private void logStart(BuildEvent event, Date start, String name) {
+        String msg = StringUtils.LINE_SEP + name + ": started " + start;
+        printMessage(msg, out, event.getPriority());
+        log(msg);
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message