Browse Source

Added a basic profiling logger.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@576173 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 17 years ago
parent
commit
9cd9731a62
3 changed files with 121 additions and 1 deletions
  1. +2
    -0
      WHATSNEW
  2. +7
    -1
      docs/manual/listeners.html
  3. +112
    -0
      src/main/org/apache/tools/ant/listener/ProfileLogger.java

+ 2
- 0
WHATSNEW View File

@@ -173,6 +173,8 @@ Fixed bugs:

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.


+ 7
- 1
docs/manual/listeners.html View File

@@ -111,10 +111,16 @@ listeners and loggers.</p>
<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>
<h3><a name="DefaultLogger">DefaultLogger</a></h3>



+ 112
- 0
src/main/org/apache/tools/ant/listener/ProfileLogger.java View File

@@ -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);
}
}

Loading…
Cancel
Save