[jboss-cvs] JBoss Profiler SVN: r455 - branches/JBossProfiler2/src/main/org/jboss/profiler/ant.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 19 16:16:49 EDT 2008


Author: jesper.pedersen
Date: 2008-05-19 16:16:49 -0400 (Mon, 19 May 2008)
New Revision: 455

Added:
   branches/JBossProfiler2/src/main/org/jboss/profiler/ant/RegressionTask.java
Log:
Initial version of the regression task

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ant/RegressionTask.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ant/RegressionTask.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ant/RegressionTask.java	2008-05-19 20:16:49 UTC (rev 455)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007-2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profiler.ant;
+
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.SnapshotHelper;
+import org.jboss.profiler.shared.ThreadInfo;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * The regression Ant task
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class RegressionTask extends Task {
+
+  /** Old snapshot */
+  private File oldSnapshot;
+
+  /** New snapshpt */
+  private File newSnapshot;
+
+  /** Difference */
+  private int difference;
+
+  /**
+   * Constructor
+   */
+  public RegressionTask() {
+    super();
+  }
+
+  /**
+   * Get the old snapshot
+   * @return The old snapshot
+   */
+  public File getOldsnapshot() {
+    return oldSnapshot;
+  }
+
+  /**
+   * Set the old snapshot
+   * @param s The old snapshot
+   */
+  public void setOldsnapshot(File s) {
+    oldSnapshot = s;
+  }
+
+  /**
+   * Get the new snapshot
+   * @return The new snapshot
+   */
+  public File getNewsnapshot() {
+    return newSnapshot;
+  }
+
+  /**
+   * Set the new snapshot
+   * @param s The new snapshot
+   */
+  public void setNewsnapshot(File s) {
+    newSnapshot = s;
+  }
+
+  /**
+   * Get the difference
+   * @return The difference
+   */
+  public int getDifference() {
+    return difference;
+  }
+
+  /**
+   * Set the difference
+   * @param d The difference
+   */
+  public void setDifference(int d) {
+    difference = d;
+  }
+
+  /**
+   * Execute Ant task
+   * @exception BuildException If an error occurs
+   */
+  public void execute() throws BuildException {
+    if (oldSnapshot != null && oldSnapshot.exists() && newSnapshot != null && newSnapshot.exists()) {
+      try {
+        Snapshot os = SnapshotHelper.load(oldSnapshot);
+        Snapshot ns = SnapshotHelper.load(newSnapshot);
+
+        double ott = 0;
+        for (ThreadInfo ti: os.getThreads()) {
+          ott += ti.getTotalTime();
+        }
+      
+        double ntt = 0;
+        for (ThreadInfo ti: ns.getThreads()) {
+          ntt += ti.getTotalTime();
+        }
+
+        int regression = (int)(((ntt - ott) / ott) * 100.0);
+
+        if (regression >= difference) {
+          throw new BuildException("Regression between " + oldSnapshot + " and " +
+                                   newSnapshot + " at " + regression + "%");
+        }
+      } catch (IOException ioe) {
+        throw new BuildException(ioe.getMessage(), ioe);
+      }
+    }
+  }
+}




More information about the jboss-cvs-commits mailing list