Skip to content

Commit

Permalink
perf-test support: added unstructured dump of SQL queries from listener
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed May 19, 2021
1 parent 8abcf32 commit f852353
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
Expand Up @@ -61,7 +61,8 @@ private static String checkVersionProgressInternal(String prevVersion, String ne
* Returns report callback adding query section to the performance test report.
* Note that the section is NOT added if the count of queries is 0.
*/
public static TestMonitor.ReportCallback createReportCallback(TestQueryListener testQueryListener) {
public static TestMonitor.ReportCallback reportCallbackQuerySummary(
TestQueryListener testQueryListener) {
return testMonitor -> {
if (testQueryListener.hasNoEntries()) {
return;
Expand All @@ -73,4 +74,21 @@ public static TestMonitor.ReportCallback createReportCallback(TestQueryListener
section.addRow("execution-count", testQueryListener.getExecutionCount());
};
}

/**
* Returns report callback adding detailed query dump section to the performance test report.
* Note that the section is NOT added if the count of queries is 0.
* This section is more for visual comparison/interpretation than for graphing.
*/
public static TestMonitor.ReportCallback reportCallbackQueryList(
TestQueryListener testQueryListener) {
return testMonitor -> {
if (testQueryListener.hasNoEntries()) {
return;
}

TestReportSection section = testMonitor.addRawReportSection("query-list");
testQueryListener.getEntries().forEach(e -> section.addRow(e.query));
};
}
}
Expand Up @@ -174,7 +174,8 @@ public TestMonitor createTestMonitor() {
queryListener.clear();
return super.createTestMonitor()
.addReportCallback(TestReportUtil::reportGlobalPerfData)
.addReportCallback(SqlRepoTestUtil.createReportCallback(queryListener));
.addReportCallback(SqlRepoTestUtil.reportCallbackQuerySummary(queryListener))
.addReportCallback(SqlRepoTestUtil.reportCallbackQueryList(queryListener));
}

protected boolean isUsingH2() {
Expand Down
Expand Up @@ -316,7 +316,8 @@ public TestMonitor createTestMonitor() {

return super.createTestMonitor()
.addReportCallback(TestReportUtil::reportGlobalPerfData)
.addReportCallback(SqlRepoTestUtil.createReportCallback(queryListener));
.addReportCallback(SqlRepoTestUtil.reportCallbackQuerySummary(queryListener))
.addReportCallback(SqlRepoTestUtil.reportCallbackQueryList(queryListener));
}

protected TracingProfileType getTestMethodTracingProfile() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -113,6 +113,12 @@ public TestReportSection addReportSection(String sectionName) {
return reportSection;
}

public TestReportSection addRawReportSection(String sectionName) {
TestReportSection reportSection = new TestReportSection(sectionName, true);
reportSections.add(reportSection);
return reportSection;
}

public void dumpReport(String testName) {
ReportMetadata reportMetadata = new ReportMetadata(testName);
String perfReportPrefix = System.getProperty(PERF_REPORT_PREFIX_PROPERTY_NAME);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -19,12 +19,18 @@ public class TestReportSection {
public static final char ESCAPE_CHAR = '\\';

private final String sectionName;
private final boolean rawSection; // no CSV header, no test name column
private final List<Object[]> rows = new ArrayList<>();

private String[] columnNames;

public TestReportSection(String sectionName) {
this(sectionName, false);
}

public TestReportSection(String sectionName, boolean rawSection) {
this.sectionName = sectionName;
this.rawSection = rawSection;
}

/**
Expand All @@ -43,19 +49,36 @@ public void addRow(Object... row) {
* Dumps the output as CSV including section header preceded by an empty line.
*
* @param testName common test name used as a first column value (named "test")
* unless {@link #rawSection} is `true` in which case it is skipped
*/
public void dump(String testName, PrintStream out) {
out.print("\n[" + sectionName + "]\ntest");
for (String columnName : columnNames) {
out.print(SEPARATOR + format(columnName));
}
if (rawSection) {
out.print("\n[" + sectionName + "]");
for (Object[] row : rows) {
StringBuilder sb = new StringBuilder();
for (Object value : row) {
if (sb.length() > 0) {
sb.append(SEPARATOR);
}
sb.append(format(value));
}
out.print('\n' + sb.toString());
}
} else {
// normal CSV output
out.print("\n[" + sectionName + "]\ntest");
for (String columnName : columnNames) {
out.print(SEPARATOR + format(columnName));
}

for (Object[] row : rows) {
out.print('\n' + format(testName));
for (Object value : row) {
out.print(SEPARATOR + format(value));
for (Object[] row : rows) {
out.print('\n' + format(testName));
for (Object value : row) {
out.print(SEPARATOR + format(value));
}
}
}

out.println();
}

Expand Down

0 comments on commit f852353

Please sign in to comment.