Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* (c) Copyright 2010 by Volker Bergmann. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted under the terms of the
* GNU General Public License (GPL).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
* REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
* HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.databene.dbsanity.report;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.databene.commons.comparator.IntComparator;
import org.databene.commons.file.FilePrintStream;
import org.databene.dbsanity.model.SanityCheck;
import org.databene.dbsanity.model.SanityCheckSuite;
import org.databene.dbsanity.model.SanityCheckVerdict;
import org.databene.html.HTMLUtil;
/**
* New module that lists the slow checks.
* Created: 11.11.2010 20:08:32
* @since 1.0
* @author Volker Bergmann
*/
public class ExecutionTimeModule extends AbstractReportModule {
List checks;
public ExecutionTimeModule() {
}
@Override
public int getDashboardColSpan(ReportScope scope) {
return (scope == ReportScope.ROOT ? 2 : 0);
}
@Override
public void renderDashboardView(ReportScope scope, SanityCheckSuite suite,
FilePrintStream out) {
div(5, out);
}
@Override
public void summary(SanityCheckSuite rootSuite) {
checks = checkSuite(rootSuite);
createDetailsPage(checks, rootSuite);
}
private List checkSuite(SanityCheckSuite suite) {
List checks = ReportUtil.agregateChecks(suite, true);
Collections.sort(checks, new Comparator() {
public int compare(SanityCheck c1, SanityCheck c2) {
return IntComparator.compare(c2.getExecutionTime(), c1.getExecutionTime());
}
});
return checks;
}
private void createDetailsPage(List checks, SanityCheckSuite rootSuite) {
String title = "Execution Times";
FilePrintStream out = null;
File file = new File(rootSuite.getReportFolder(), "execution_times.html");
try {
out = openNewFile(file, title);
out.println(context.navBar(rootSuite.getReportFolder()));
div(-1, out);
} catch (FileNotFoundException e) {
throw new RuntimeException("Error writing execution times file: " + file, e);
} finally {
super.closeFile(out);
}
}
private void div(int limit, FilePrintStream out) {
// order defect type counts in descending order
if (!checks.isEmpty()) {
long maxCount = checks.get(0).getExecutionTime();
// render HTML
startModule(out);
modHeader("Slowest Checks", out);
startModBody(out);
out.println("
");
out.println("
");
out.println("
Verdict
");
out.println("
Check name
");
out.println("
Execution Time
");
out.println("
");
for (int i = 0; (i < limit || limit < 0) && i < checks.size(); i++) {
SanityCheck check = checks.get(i);
if (check.getVerdict() == SanityCheckVerdict.SKIPPED)
continue;
String percentage = (maxCount > 0 ? (String.valueOf(check.getExecutionTime() * 100 / maxCount) + "%") : "");
out.println("