Skip to content

Commit

Permalink
Use full path from apps directory to define benchmark name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Mar 7, 2024
1 parent 43cad41 commit e0347c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
7 changes: 6 additions & 1 deletion cli/bin/preact-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ async function analyzeAction(requestedBench) {
return;
}

const benchmarkNames = await readdir(baseTraceLogDir());
const benchmarkNames = [];
for (let dirName of await readdir(baseTraceLogDir())) {
for (let benchmarkName of await readdir(baseTraceLogDir(dirName))) {
benchmarkNames.push(`${dirName}/${benchmarkName}`);
}
}

/** @type {string} */
let selectedBench;
Expand Down
30 changes: 16 additions & 14 deletions cli/src/tach.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from "node:path";
import { deleteAsync } from "del";
import { main } from "tachometer";
import {
appFilePath,
baseTraceLogDir,
configDir,
getBenchmarkBaseName,
Expand All @@ -20,7 +21,7 @@ const TACH_SCHEMA =
function getMeasurements(benchName) {
/** @type {TachBenchmarkConfig["measurement"]} */
let measurement;
if (benchName == "replace1k") {
if (benchName == "table-app/replace1k") {
// MUST BE KEPT IN SYNC WITH WARMUP COUNT IN 02_replace1k.html
const WARMUP_COUNT = 5;

Expand Down Expand Up @@ -75,13 +76,15 @@ function getMeasurements(benchName) {
/**
* @param {string} benchmarkFile
* @param {BenchmarkConfig} benchConfig
* @returns {Promise<{ name: string; configPath: string; config: TachConfig; }>}
* @returns {Promise<{ basePath: string; configPath: string; config: TachConfig; }>}
*/
async function generateTachConfig(benchmarkFile, benchConfig) {
const baseName = getBenchmarkBaseName(benchmarkFile);
const basePath = path
.relative(appFilePath(), benchmarkFile)
.replace(/\.html$/, "");

if (benchConfig.browser.name == "chrome" && benchConfig.trace) {
const traceLogDir = baseTraceLogDir(baseName);
const traceLogDir = baseTraceLogDir(basePath);
await deleteAsync("**/*", { cwd: traceLogDir });
await mkdir(traceLogDir, { recursive: true });

Expand All @@ -90,13 +93,14 @@ async function generateTachConfig(benchmarkFile, benchConfig) {
};
}

const measurement = getMeasurements(baseName);
const measurement = getMeasurements(basePath);
const baseBenchConfig = { measurement, browser: benchConfig.browser };

const baseUrl = new URL("http://localhost:" + benchConfig.port);

/** @type {TachBenchmarkConfig["expand"]} */
const expand = [];
const baseName = getBenchmarkBaseName(benchmarkFile);
for (let impl of benchConfig.implementations) {
for (let depGroup of benchConfig.depGroups) {
expand.push({
Expand All @@ -121,20 +125,23 @@ async function generateTachConfig(benchmarkFile, benchConfig) {
],
};

const tachConfigPath = configDir(baseName + ".config.json");
const tachConfigPath = configDir(basePath + ".config.json");
await mkdir(path.dirname(tachConfigPath), { recursive: true });
await writeFile(tachConfigPath, JSON.stringify(tachConfig, null, 2), "utf8");

return { name: baseName, configPath: tachConfigPath, config: tachConfig };
return { basePath, configPath: tachConfigPath, config: tachConfig };
}

/** @type {(benchmarkFile: string, benchConfig: BenchmarkConfig) => Promise<TachResult[]>} */
export async function runTach(benchmarkFile, benchConfig) {
const { name, configPath } = await generateTachConfig(
const { basePath, configPath } = await generateTachConfig(
benchmarkFile,
benchConfig,
);

const jsonFilePath = resultsPath(basePath + ".json");
await mkdir(path.dirname(jsonFilePath), { recursive: true });

/** @type {TachResult[] | undefined} */
let results;

Expand All @@ -143,12 +150,7 @@ export async function runTach(benchmarkFile, benchConfig) {
const realLog = console.log;
try {
console.log = () => {};
results = await main([
"--config",
configPath,
"--json-file",
resultsPath(name + ".json"),
]);
results = await main(["--config", configPath, "--json-file", jsonFilePath]);
} finally {
console.log = realLog;
}
Expand Down

0 comments on commit e0347c1

Please sign in to comment.