Skip to content

Commit

Permalink
test: add debug flag for suppressing extra console messages in ssb (#…
Browse files Browse the repository at this point in the history
…2146)

* test: add debug flag for suppressing extra console messages in ssb

* remove unneeded third argument
  • Loading branch information
ddelgrosso1 authored Feb 23, 2023
1 parent 7054e43 commit 4006dfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
24 changes: 15 additions & 9 deletions internal-tooling/performanceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
convertToCSVFormat,
convertToCloudMonitoringFormat,
TestResult,
log,
} from './performanceUtils';
import {existsSync} from 'fs';
import {writeFile} from 'fs/promises';
Expand Down Expand Up @@ -72,6 +73,10 @@ const argv = yargs(process.argv.slice(2))
filename: {
type: 'string',
},
debug: {
type: 'boolean',
default: false,
},
})
.parseSync();

Expand All @@ -86,8 +91,9 @@ let iterationsRemaining = argv.iterations;
function main() {
let numThreads = argv.numthreads;
if (numThreads > iterationsRemaining) {
console.log(
`${numThreads} is greater than number of iterations (${iterationsRemaining}). Using ${iterationsRemaining} threads instead.`
log(
`${numThreads} is greater than number of iterations (${iterationsRemaining}). Using ${iterationsRemaining} threads instead.`,
argv.debug
);
numThreads = iterationsRemaining;
}
Expand All @@ -105,8 +111,9 @@ function main() {
*/
function createWorker() {
iterationsRemaining--;
console.log(
`Starting new iteration. Current iterations remaining: ${iterationsRemaining}`
log(
`Starting new iteration. Current iterations remaining: ${iterationsRemaining}`,
argv.debug
);
let testPath = '';
if (argv.testtype === TRANSFER_MANAGER_TEST_TYPES.WRITE_ONE_READ_THREE) {
Expand Down Expand Up @@ -136,15 +143,14 @@ function createWorker() {
});

w.on('message', data => {
console.log('Successfully completed iteration.');
log('Successfully completed iteration.', argv.debug);
recordResult(data);
if (iterationsRemaining > 0) {
createWorker();
}
});
w.on('error', e => {
console.log('An error occurred.');
console.log(e);
log(e, true, true);
});
}

Expand Down Expand Up @@ -172,15 +178,15 @@ async function recordResult(results: TestResult[] | TestResult) {
argv.filename,
`${convertToCSVFormat(resultsToAppend)}\n`
)
: console.log(convertToCSVFormat(resultsToAppend));
: log(convertToCSVFormat(resultsToAppend), true);
} else if (argv.format === OUTPUT_FORMATS.CLOUD_MONITORING) {
for await (const outputString of convertToCloudMonitoringFormat(
resultsToAppend,
argv.bucket
)) {
argv.filename
? await appendFile(argv.filename, `${outputString}\n`)
: console.log(outputString);
: log(outputString, true);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions internal-tooling/performanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,20 @@ export function convertToCSVFormat(results: TestResult[]): string {
const csv = results.map(result => Object.values(result));
return csv.join('\n');
}

/**
* Logs the provided message if debugging is enabled.
*
* @param {string | error} messageOrError the message or error object to be printed utilizing console.debug.
* @param {boolean} shouldLog flag indicating whether or not the message should be logged to stdout or stderr.
* @param {boolean} isError if set to true and shouldLog is true, write the output to stderr instead of stdout.
*/
export function log(
messageOrError: string | Error,
shouldLog: boolean,
isError = false
): void {
if (shouldLog) {
isError ? console.error(messageOrError) : console.log(messageOrError);
}
}

0 comments on commit 4006dfe

Please sign in to comment.