Skip to content

Commit

Permalink
chore/ci: move profiling to benchmark.js (#4525)
Browse files Browse the repository at this point in the history
* chore(benchmark): support profiling
* ci: use benchmark.js to profiling
* ci(travis): only run profiling
* refactor(benchmark): rewrite argv detection
  • Loading branch information
SukkaW committed Sep 10, 2020
1 parent 9947d86 commit e09c56a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -32,4 +32,4 @@ jobs:
- name: Install dependencies
run: npm install --silent
- name: Running benchmark
run: node test/benchmark.js
run: node test/benchmark.js --benchmark
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -10,11 +10,8 @@ node_js:
- "12"
- "14"

before_script:
- chmod +x ./test/profiling.sh

script:
- ./test/profiling.sh
- node ./test/benchmark.js --profiling

deploy:
provider: surge
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"warehouse": "^4.0.0"
},
"devDependencies": {
"0x": "^4.9.1",
"@easyops/git-exec-and-restage": "^1.0.4",
"chai": "^4.1.2",
"cheerio": "0.22.0",
Expand Down
57 changes: 49 additions & 8 deletions test/benchmark.js
Expand Up @@ -4,7 +4,7 @@ const { performance, PerformanceObserver } = require('perf_hooks');
const { spawn } = require('child_process');
const { spawn: spawnAsync } = require('hexo-util');
const { rmdir, exists } = require('hexo-fs');
const { resolve } = require('path');
const { join, resolve } = require('path');
const log = require('hexo-log')();
const { red } = require('chalk');
const hooks = [
Expand All @@ -21,17 +21,37 @@ const isWin32 = require('os').platform() === 'win32';
const npmScript = isWin32 ? 'npm.cmd' : 'npm';

const testDir = resolve('.tmp-hexo-theme-unit-test');
const zeroEksDir = process.env.TRAVIS_BUILD_DIR
? join(process.env.TRAVIS_BUILD_DIR, '0x')
: resolve(testDir, '0x');
const hexoBin = resolve(testDir, 'node_modules/.bin/hexo');

const zeroEks = require('0x');

let isProfiling = process.argv.join(' ').includes('--profiling');
let isBenchmark = process.argv.join(' ').includes('--benchmark');

if (!isProfiling && !isBenchmark) {
isProfiling = true;
isBenchmark = true;
}

(async () => {
await init();
log.info('Running benchmark');
await cleanUp();
await run_benchmark('Cold processing');
await run_benchmark('Hot processing');
await cleanUp();
await run_benchmark('Another Cold processing');
await cleanUp();

if (isBenchmark) {
log.info('Running benchmark');
await cleanUp();
await run_benchmark('Cold processing');
await run_benchmark('Hot processing');
await cleanUp();
await run_benchmark('Another Cold processing');
}

if (isProfiling) {
await cleanUp();
await profiling();
}
})();

async function run_benchmark(name) {
Expand Down Expand Up @@ -129,3 +149,24 @@ async function init() {
]);
}
}

async function profiling() {
// Clean up 0x dir before profiling
if (await exists(zeroEksDir)) await rmdir(zeroEksDir);

const zeroEksOpts = {
argv: [hexoBin, 'g', '--cwd', testDir],
workingDir: '.', // A workaround for https://github.com/davidmarkclements/0x/issues/228
outputDir: zeroEksDir,
title: 'Hexo Flamegraph'
};

log.info('Profiling');

const file = await zeroEks(zeroEksOpts);

// A small hack that workaround 0x's broken stdout handling
console.log('');

log.info(file);
}
38 changes: 0 additions & 38 deletions test/profiling.sh

This file was deleted.

0 comments on commit e09c56a

Please sign in to comment.