All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.databene.dbsanity.report.ExecutionTimeModule Maven / Gradle / Ivy

Go to download

DB Sanity is a tool for verifying a database's sanity and data integrity.

There is a newer version: 0.9.4
Show newest version
/*
 * (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(" "); out.println(" "); out.println(" "); 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(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); } if (limit >= 0 && limit < checks.size()) { out.println(" "); out.println(" "); out.println(" "); out.println(" "); } out.println("
VerdictCheck nameExecution Time
" + context.verdictImage(check.getVerdict(), out.getFile()) + "" + ReportUtil.docOrDefectFileLink(check, out.getFile()) + ""); ReportUtil.durationBar(check.getExecutionTime(), percentage, "#006688", context, out); out.println("
" + HTMLUtil.a("execution_times.html", "[more...]") + "
"); endModBody(out); modFooter("execution_times.html", out); endModule(out); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy