Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17316 cldr-apps-webdriver add Dashboard test, etc #40

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spotless.version>2.35.0</spotless.version>
<google-java-style.version>1.15.0</google-java-style.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -46,6 +48,27 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<!-- optional: limit format enforcement to just the files changed by this feature branch -->
<!-- You can explicitly disable ratchet functionality by providing the value 'NONE': -->
<ratchetFrom>NONE</ratchetFrom>
<!-- define a language-specific format -->
<java>
<!-- no need to specify files, inferred automatically, but you can if you want -->
<!-- apply a specific flavor of google-java-format and reflow long strings -->
<googleJavaFormat>
<!-- version of google-java-style -->
<version>${google-java-style.version}</version>
<style>AOSP</style>
<reflowLongStrings>false</reflowLongStrings>
</googleJavaFormat>
</java>
</configuration>
</plugin>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
Expand Down
130 changes: 130 additions & 0 deletions scripts/cldrHarStats.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { readFileSync } from "fs";

const URL_PREFIX = "http://localhost:9080/cldr-apps/";
const FILTER_REGEX = "api/voting/[a-zA-Z_]+/row";

/*
* Run with three args: the HAR file name, the start time, and the end time. For example:
* node scripts/cldrHarStats.mjs ../HAR/2024-01-12-a.har 2024-01-12T17:15:55Z 2024-01-12T17:18:55Z > ../HAR/2024-01-12-a.html
*
* Summary is written to stderr (console.warn); detailed HTML is written to stdout
*/
const harFileName = process.argv[2];
const startTimeStamp = process.argv[3];
const endTimeStamp = process.argv[4];
/*
* Read the input HAR file into an array and filter it to include only entries
* matching FILTER_REGEX and within the given start/end times
*/
const obj = JSON.parse(readFileSync(harFileName, "utf8"));
const allEntries = obj.log.entries;
const filteredEntries = allEntries.filter(function (entry) {
return (
entry.startedDateTime.localeCompare(startTimeStamp) >= 0 &&
entry.startedDateTime.localeCompare(endTimeStamp) < 0 &&
entry.request.url.match(FILTER_REGEX)
);
});
console.warn("allEntries.length = " + allEntries.length);
console.warn("filteredEntries.length = " + filteredEntries.length);

writeHtmlThruTableStart();
writeHtmlTableHeader();
writeHtmlTableBody(filteredEntries);
writeHtmlFromTableEnd();

/**
* Write the HTML up to and including the opening table tag
*/
function writeHtmlThruTableStart() {
write("<html>");
write("<head>");
write(
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
);
write("<style>");
write("table {border-collapse: collapse;}");
write("table, th, td {border: 1px solid black; padding: 4px;}");
write("td:nth-child(3){text-align: right;}"); // ms
write("td:nth-child(4){text-align: right;}"); // size
write("</style>");
write("</head>");
write("<body>");
write("<table>");
}

function writeHtmlFromTableEnd() {
write("</table>");
write("</body>");
write("</html>");
}

function writeHtmlTableHeader() {
const info = {
isHeader: true,
requestNumber: "request",
startedDateTime: "start",
time: "ms",
size: "size",
method: "method",
url: "URL",
postData: "POST data (if applicable)",
};
putEntryInfo(info);
}

function writeHtmlTableBody(entries) {
let postTime = 0,
getTime = 0,
postCount = 0,
getCount = 0;
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
let url = entry.request.url;
if (url.indexOf(URL_PREFIX) === 0) {
url = url.slice(URL_PREFIX.length);
}
if (entry.request.method === "POST") {
postCount++;
postTime += entry.time;
} else {
getCount++;
getTime += entry.time;
}
const postData =
entry.request.method === "POST" && entry.request?.postData?.text
? entry.request.postData.text
: "";
const info = {
isHeader: false,
requestNumber: i + 1,
startedDateTime: entry.startedDateTime,
time: Math.round(parseFloat(entry.time)),
size: Math.round(entry.response.content.size / 1000) + "k",
method: entry.request.method,
url: url,
postData: postData,
};
putEntryInfo(info);
}
console.warn("Average POST time = " + postTime / postCount);
console.warn("Average GET time = " + getTime / getCount);
}

function putEntryInfo(info) {
const cellStart = info.isHeader ? "<th>" : "<td>";
const cellEnd = info.isHeader ? "</th>" : "</td>";
write("<tr>");
write(cellStart + info.requestNumber + cellEnd);
write(cellStart + info.startedDateTime + cellEnd);
write(cellStart + info.time + cellEnd);
write(cellStart + info.size + cellEnd);
write(cellStart + info.method + cellEnd);
write(cellStart + info.url + cellEnd);
write(cellStart + info.postData + cellEnd);
write("</tr>");
}

function write(string) {
process.stdout.write(string + "\n");
}
Binary file added scripts/selenium-server-4.16.1.jar
Binary file not shown.
Loading
Loading