Skip to content

Commit

Permalink
fix(best-analyzer): Allow multi-project comparison (#82)
Browse files Browse the repository at this point in the history
* Change projectNames to test
* Minor prettier change
* Allow multi project comparison
  • Loading branch information
diervo authored Feb 12, 2018
1 parent fb23e9a commit 3431292
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ build/
coverage/
__benchmark_results__/
public/

examples
CHANGELOG.md
2 changes: 1 addition & 1 deletion examples/simple_benchmark/best.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
projectName: 'perf-best-examples',
projectName: 'simple-benchmarks',
benchmarkOnClient: true,
useMacroTaskAfterBenchmark: false,
benchmarkRunner: '@best/runner-headless',
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_lwc_benchmark/best.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
projectName: 'perf-best-examples',
projectName: 'lwc-examples',
plugins: {
'rollup-plugin-lwc-compiler': {
rootDir: '<rootDir>/src/',
Expand Down
5 changes: 3 additions & 2 deletions packages/best-cli/src/run_compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function runCompare(globalConfig, configs, outputStream) {
return false;
}

const projectName = globalConfig.rootProjectName;
const projects = configs.map(cfg => cfg.projectName);
const projectNames = projects.length ? projects : [globalConfig.rootProjectName];
let storageProvider;
try {
storageProvider = require(externalStorage);
Expand All @@ -28,7 +29,7 @@ export async function runCompare(globalConfig, configs, outputStream) {
}

preRunMessager.print('\n Fetching benchmark results to compare... \n\n', outputStream);
const compareResults = await compareBenchmarkStats(baseCommit, compareCommit, projectName, storageProvider);
const compareResults = await compareBenchmarkStats(baseCommit, compareCommit, projectNames, storageProvider);

if (gitIntegration) {
await pushBenchmarkComparison(baseCommit, compareCommit, compareResults, globalConfig);
Expand Down
54 changes: 33 additions & 21 deletions packages/best-compare/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ function compareBenchmarks(baseBenchs, targetBenchs, comparison = []) {
return comparison;
}

export async function compareBenchmarkStats(baseCommit, targetCommit, projectName, storageProvider) {
const [baseBenchmarks, targetBenchmarks] = await Promise.all([
storageProvider.getAllBenchmarkStatsPerCommit(projectName, baseCommit),
storageProvider.getAllBenchmarkStatsPerCommit(projectName, targetCommit),
]);
export async function compareBenchmarkStats(baseCommit, targetCommit, projectNames, storageProvider) {
const stats = await Promise.all(
projectNames.reduce((reducer, projectName) => [
...reducer,
storageProvider.getAllBenchmarkStatsPerCommit(projectName, baseCommit),
storageProvider.getAllBenchmarkStatsPerCommit(projectName, targetCommit)
], [])
);

if (stats.length % 2) {
throw new Error('Recovered odd number of stats to compare');
}

preRunMessager.print('\n Running comparison... \n\n', process.stdout);

Expand All @@ -60,25 +67,30 @@ export async function compareBenchmarkStats(baseCommit, targetCommit, projectNam
comparison: [],
};

baseBenchmarks.forEach(baseBenchmarkBundle => {
const { benchmarkName } = baseBenchmarkBundle;
const targetBenchmarkBundle = targetBenchmarks.find(b => b.benchmarkName === benchmarkName);
if (!targetBenchmarkBundle) {
console.log(`Skipping benchmark ${benchmarkName} since we couldn't find it in commit ${targetCommit}`);
return;
}
const { version: baseVersion, environment: baseEnv, benchmarks: baseBenchs } = baseBenchmarkBundle;
const { version: targetVersion, environment: targetEnv, benchmarks: targetBenchs } = targetBenchmarkBundle;
while (stats.length) {
const baseBenchmarks = stats.shift();
const targetBenchmarks = stats.shift();

baseBenchmarks.forEach(baseBenchmarkBundle => {
const { benchmarkName } = baseBenchmarkBundle;
const targetBenchmarkBundle = targetBenchmarks.find(b => b.benchmarkName === benchmarkName);
if (!targetBenchmarkBundle) {
console.log(`Skipping benchmark ${benchmarkName} since we couldn't find it in commit ${targetCommit}`);
return;
}
const { version: baseVersion, environment: baseEnv, benchmarks: baseBenchs } = baseBenchmarkBundle;
const { version: targetVersion, environment: targetEnv, benchmarks: targetBenchs } = targetBenchmarkBundle;

if (baseVersion !== targetVersion) {
console.log(`Skipping comparing ${benchmarkName} since stat versions are different`);
}
if (baseVersion !== targetVersion) {
console.log(`Skipping comparing ${benchmarkName} since stat versions are different`);
}

compareEnvironment(baseEnv, targetEnv);
compareEnvironment(baseEnv, targetEnv);

const comparison = compareBenchmarks(baseBenchs, targetBenchs);
commitComparison.comparison.push({ benchmarkName, comparison });
});
const comparison = compareBenchmarks(baseBenchs, targetBenchs);
commitComparison.comparison.push({ benchmarkName, comparison });
});
}

return commitComparison;
}
4 changes: 3 additions & 1 deletion packages/best-frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const cacheSuccesses = cache('5 minutes', onlyStatus200);
// -- Middleware definition ------------------------
module.exports = function (options = {}) {
const config = Object.assign({}, defaultOptions, options);
const { apiVersion, store } = config;
const { apiVersion, store, title } = config;
const ApiV1 = require(`./server/api_${apiVersion}`);
const storeInstance = require(store);
const app = express();
Expand All @@ -31,6 +31,7 @@ module.exports = function (options = {}) {
parent.get(['/', '/home'], cacheSuccesses, async (req, res) => {
const projects = await storeInstance.getProjects();
res.send(template.generateHTML({
title,
projects,
action: { type: 'navigateHome', page: 'home' }
}));
Expand All @@ -48,6 +49,7 @@ module.exports = function (options = {}) {
// const stats = await statsFuture;

const data = {
title,
projects,
// stats,
selectedProject: projectName,
Expand Down
1 change: 1 addition & 0 deletions packages/best-frontend/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PORT = process.env.PORT || 3000;
const app = express();

const config = {
title: 'Best',
// store: "@best/store-aws",
storeConfig: {
// Config shall be passed as env parameters
Expand Down
2 changes: 1 addition & 1 deletion packages/best-frontend/src/modules/one/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ul>
</div>
<div class="bBottom">
<one-appnav nav-items={state.navItems} selected-item-id={state.selectedPage}></one-appnav>
<one-appnav app-name={state.title} nav-items={state.navItems} selected-item-id={state.selectedPage}></one-appnav>
</div>
</header>
</section>
Expand Down
3 changes: 2 additions & 1 deletion packages/best-frontend/src/modules/one/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export function normalizeStats(state, stats, project, branch) {
}

export function initializeState(state, serverState) {
const { action, stats, projects, branches, selectedProject, selectedBranch} = serverState;
const { action, stats, projects, branches, selectedProject, selectedBranch, title } = serverState;
const navItems = projects.map(p => buildNavItem(p));
state.title = title;
state.projects = projects;
// eslint-disable-next-line no-return-assign, no-sequences
state.branches = projects.reduce((r, p) => (r[p] = ['master'], r), {});
Expand Down

0 comments on commit 3431292

Please sign in to comment.