From 5f5bc08838234cd998e4d078e996a47a00964460 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Tue, 7 Jun 2022 08:02:19 -0700 Subject: [PATCH] fix: switch for using in javascript benchmark using in tests --- .eslintignore | 1 + system-test/busybench-js/package.json | 3 ++- system-test/busybench-js/src/busybench.js | 13 ++++--------- system-test/busybench/src/busybench.ts | 11 ++++------- system-test/test.sh | 16 ++++++---------- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/.eslintignore b/.eslintignore index e21434e3..8c85dfb5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,4 @@ build/ proto/ out/ +system-test/busybench-js/src/busybench.js diff --git a/system-test/busybench-js/package.json b/system-test/busybench-js/package.json index a4db0050..2cd1d365 100644 --- a/system-test/busybench-js/package.json +++ b/system-test/busybench-js/package.json @@ -9,5 +9,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC" + "license": "ISC", + "type": "module" } diff --git a/system-test/busybench-js/src/busybench.js b/system-test/busybench-js/src/busybench.js index 87bdf123..e904957d 100644 --- a/system-test/busybench-js/src/busybench.js +++ b/system-test/busybench-js/src/busybench.js @@ -14,13 +14,8 @@ * limitations under the License. */ -const fs = require('fs'); -// eslint-disable-next-line node/no-extraneous-require -const pify = require('pify'); -// eslint-disable-next-line node/no-missing-require -const pprof = require('pprof'); - -const writeFilePromise = pify(fs.writeFile); +import fs from 'fs'; +import pprof from 'pprof'; const startTime = Date.now(); const testArr = []; @@ -59,13 +54,13 @@ async function collectAndSaveTimeProfile( sourceMapper: sourceMapper, }); const buf = await pprof.encode(profile); - await writeFilePromise('time.pb.gz', buf); + await fs.promises.writeFile('time.pb.gz', buf); } async function collectAndSaveHeapProfile(sourceMapper) { const profile = pprof.heap.profile(undefined, sourceMapper); const buf = await pprof.encode(profile); - await writeFilePromise('heap.pb.gz', buf); + await fs.promises.writeFile('heap.pb.gz', buf); } async function collectAndSaveProfiles(collectLineNumberTimeProfile) { diff --git a/system-test/busybench/src/busybench.ts b/system-test/busybench/src/busybench.ts index 849f28cf..feb7c828 100644 --- a/system-test/busybench/src/busybench.ts +++ b/system-test/busybench/src/busybench.ts @@ -14,14 +14,11 @@ * limitations under the License. */ -import {writeFile} from 'fs'; -// eslint-disable-next-line node/no-extraneous-import -import * as pify from 'pify'; +// eslint-disable-next-line node/no-unsupported-features/node-builtins +import {promises} from 'fs'; // eslint-disable-next-line node/no-extraneous-import import {encode, heap, SourceMapper, time} from 'pprof'; -const writeFilePromise = pify(writeFile); - const startTime: number = Date.now(); const testArr: number[][] = []; @@ -57,7 +54,7 @@ async function collectAndSaveTimeProfile( sourceMapper, }); const buf = await encode(profile); - await writeFilePromise('time.pb.gz', buf); + await promises.writeFile('time.pb.gz', buf); } async function collectAndSaveHeapProfile( @@ -65,7 +62,7 @@ async function collectAndSaveHeapProfile( ): Promise { const profile = await heap.profile(undefined, sourceMapper); const buf = await encode(profile); - await writeFilePromise('heap.pb.gz', buf); + await promises.writeFile('heap.pb.gz', buf); } async function collectAndSaveProfiles(): Promise { diff --git a/system-test/test.sh b/system-test/test.sh index 8fcba377..9c632f32 100755 --- a/system-test/test.sh +++ b/system-test/test.sh @@ -45,7 +45,7 @@ TESTDIR=$(mktemp -d) cp -r "$BENCHDIR" "$TESTDIR/busybench" cd "$TESTDIR/busybench" -retry npm_install pify @types/pify typescript gts @types/node >/dev/null +retry npm_install typescript gts @types/node >/dev/null retry npm_install --nodedir="$NODEDIR" \ $([ -z "$BINARY_HOST" ] && echo "--build-from-source=pprof" \ || echo "--pprof_binary_host_mirror=$BINARY_HOST")\ @@ -59,18 +59,14 @@ node -v node --trace-warnings "$BENCHPATH" 10 $VERIFY_TIME_LINE_NUMBERS if [[ "$VERIFY_TIME_LINE_NUMBERS" == "true" ]]; then - pprof -lines -top -nodecount=2 time.pb.gz - pprof -lines -top -nodecount=2 time.pb.gz | \ - grep "busyLoop.*src/busybench.js:3[3-5]" - pprof -filefunctions -top -nodecount=2 heap.pb.gz - pprof -filefunctions -top -nodecount=2 heap.pb.gz | \ + pprof -lines -top -nodecount=2 time.pb.gz | tee $tty | \ + grep "busyLoop.*src/busybench.js:[2-3][08-9]" + pprof -filefunctions -top -nodecount=2 heap.pb.gz | tee $tty | \ grep "busyLoop.*src/busybench.js" else - pprof -filefunctions -top -nodecount=2 time.pb.gz - pprof -filefunctions -top -nodecount=2 time.pb.gz | \ + pprof -filefunctions -top -nodecount=2 time.pb.gz | tee $tty | \ grep "busyLoop.*src/busybench.ts" - pprof -filefunctions -top -nodecount=2 heap.pb.gz - pprof -filefunctions -top -nodecount=2 heap.pb.gz | \ + pprof -filefunctions -top -nodecount=2 heap.pb.gz | tee $tty | \ grep "busyLoop.*src/busybench.ts" fi