Author: ruschein
Date: 2011-03-11 15:44:09 -0800 (Fri, 11 Mar 2011)
New Revision: 24415

Modified:
   
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
Log:
Work in progress.

Modified: 
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
===================================================================
--- 
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
        2011-03-11 23:42:43 UTC (rev 24414)
+++ 
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
        2011-03-11 23:44:09 UTC (rev 24415)
@@ -618,32 +618,55 @@
         * @component
         */
        private ToolchainManager toolchainManager;
-       
+
        /**
+        * @parameter groupId
+        * @required
+        */
+       private String groupId;
+
+       /**
+        * @parameter artifactId
+        * @required
+        */
+       private String artifactId;
+
+       /**
+        * @parameter currentVersion
+        * @required
+        */
+       private String currentVersion;
+
+       /**
         * @parameter baselineVersion
         * @required
         */
        private String baselineVersion;
 
+       /**
+        * @parameter default-value="10.0"
+        */
+       private double maxPerformanceDecreasePercentage;
+
        /** @component */
        private ArtifactResolver resolver;
 
        public void execute() throws MojoExecutionException, 
MojoFailureException {
-System.err.println("+++++++++++++++++++++++++++ Entering execute()");
                if (verifyParameters()) {
-System.err.println("+++++++++++++++++++++++++++ parameters are Ok");
                        if (hasExecutedBefore())
                                return;
 
                        logReportsDirectory();
 
-System.err.println("+++++++++++++++++++++++++++ about to call run()");
+                       setClassesDirectory(getCurrentArtifact());
                        run();
                        final Set<ClassAndMethodNameAndExecutionTime> 
currentNamesAndTimes = getTestTimes();
-System.err.println("+++++++++++++++++++++++++++ after first run: " + 
currentNamesAndTimes);
+
+                       setClassesDirectory(getBaselineArtifact());
                        run();
                        final Set<ClassAndMethodNameAndExecutionTime> 
baselineNamesAndTimes = getTestTimes();
-System.err.println("+++++++++++++++++++++++++++ after baseline run: " + 
baselineNamesAndTimes);
+
+                       compareRuntimes(currentNamesAndTimes, 
baselineNamesAndTimes);
                }
        }
 
@@ -656,7 +679,6 @@
                        ProviderInfo provider = (ProviderInfo) iter.next();
                        forkConfiguration = getForkConfiguration();
                        final Classpath bootClasspath = 
forkConfiguration.getBootClasspath();
-System.err.println("+++++++++++++++++++++++++++ class path is " + 
bootClasspath.getClassPath());
                        ClassLoaderConfiguration classLoaderConfiguration =
                                getClassLoaderConfiguration(forkConfiguration);
                        ForkStarter forkStarter =
@@ -682,6 +704,49 @@
                SurefireHelper.reportExecution(this, result, getLog());
        }
 
+       private void compareRuntimes(final 
Set<ClassAndMethodNameAndExecutionTime> currentNamesAndTimes,
+                                    final 
Set<ClassAndMethodNameAndExecutionTime> baselineNamesAndTimes)
+               throws MojoFailureException
+       {
+               boolean failed = false;
+               for (final ClassAndMethodNameAndExecutionTime 
currentNameAndTime : currentNamesAndTimes) {
+                       final ClassAndMethodNameAndExecutionTime 
baselineNameAndTime =
+                               
find(currentNameAndTime.getClassAndMethodName(), baselineNamesAndTimes);
+                       if (baselineNameAndTime == null) {
+                               getLog().warn("Missing test in baseline 
version: "
+                                             + 
currentNameAndTime.getClassAndMethodName());
+                               continue;
+                       }
+
+                       final double percentageDifference = 100.0 * (
+                               baselineNameAndTime.getExecutionTime() == 0.0
+                               ? currentNameAndTime.getExecutionTime()
+                               : (currentNameAndTime.getExecutionTime() - 
baselineNameAndTime.getExecutionTime())
+                                 / baselineNameAndTime.getExecutionTime());
+                       if (percentageDifference > 
maxPerformanceDecreasePercentage) {
+                               
getLog().error("currentNameAndTime.getClassAndMethodName() is " + 
percentageDifference
+                                              + "% slower than the baseline 
version!");
+                               failed = true;
+                       } else if (percentageDifference > 0.0)
+                               
getLog().info("currentNameAndTime.getClassAndMethodName() is " + 
percentageDifference
+                                              + "% slower than the baseline 
version.");
+               }
+
+               if (failed)
+                       throw new MojoFailureException("One or more tests took 
too long relative to the baseline version!");
+       }
+
+       private ClassAndMethodNameAndExecutionTime find(final String 
classAndMethodName,
+                                                       final 
Set<ClassAndMethodNameAndExecutionTime> namesAndTimes)
+       {
+               for (final ClassAndMethodNameAndExecutionTime nameAndTime : 
namesAndTimes) {
+                       if 
(nameAndTime.getClassAndMethodName().equals(classAndMethodName))
+                               return nameAndTime;
+               }
+
+               return null;
+       }
+
        private Set<ClassAndMethodNameAndExecutionTime> getTestTimes() throws 
MojoExecutionException {
                final XMLInputFactory inputFactory = 
XMLInputFactory.newInstance();
 
@@ -693,7 +758,7 @@
                for (final String fileName : fileNames) {
                        if (!fileName.startsWith("TEST-") || ! 
fileName.endsWith(".xml"))
                                continue;
-                       
+
                        final InputStream input;
                        try {
                                input = new FileInputStream(new File(targetDir 
+ "/" + fileName));
@@ -736,7 +801,27 @@
                return result;
        }
 
-       /*      
+       private File getCurrentArtifact() throws MojoExecutionException {
+               final Artifact artifact = project.getArtifact();
+               final Artifact baselineArtifact = 
artifactFactory.createArtifactWithClassifier(groupId, artifactId,
+                                                                               
               currentVersion,
+                                                                               
               artifact.getType(),
+                                                                               
               artifact.getClassifier());
+               resolveDependencies(baselineArtifact);
+               return baselineArtifact.getFile();
+       }
+
+       private File getBaselineArtifact() throws MojoExecutionException {
+               final Artifact artifact = project.getArtifact();
+               final Artifact baselineArtifact = 
artifactFactory.createArtifactWithClassifier(groupId, artifactId,
+                                                                               
               baselineVersion,
+                                                                               
               artifact.getType(),
+                                                                               
               artifact.getClassifier());
+               resolveDependencies(baselineArtifact);
+               return baselineArtifact.getFile();
+       }
+
+       /*
        public void execute() throws MojoExecutionException {
                getLog().info("+++ ProfilerMojo: base line version is " + 
baselineVersion + ", group ID: "
                              + project.getGroupId() + ", artifact ID: " + 
project.getArtifactId());

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to