Merge pull request #149 from github/max_threads
Use all available threads for analysis
This commit is contained in:
commit
c5e07ebfcc
4 changed files with 24 additions and 10 deletions
|
|
@ -19,7 +19,6 @@ inputs:
|
||||||
threads:
|
threads:
|
||||||
description: The number of threads to be used by CodeQL.
|
description: The number of threads to be used by CodeQL.
|
||||||
required: false
|
required: false
|
||||||
default: "1"
|
|
||||||
checkout_path:
|
checkout_path:
|
||||||
description: "The path at which the analyzed repository was checked out. Used to relativeize any absolute paths in the uploaded SARIF file."
|
description: "The path at which the analyzed repository was checked out. Used to relativeize any absolute paths in the uploaded SARIF file."
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
16
lib/util.js
generated
16
lib/util.js
generated
|
|
@ -319,28 +319,36 @@ function getMemoryFlag() {
|
||||||
}
|
}
|
||||||
exports.getMemoryFlag = getMemoryFlag;
|
exports.getMemoryFlag = getMemoryFlag;
|
||||||
/**
|
/**
|
||||||
* Get the codeql `--threads` value specified for the `threads` input. The value
|
* Get the codeql `--threads` value specified for the `threads` input.
|
||||||
* defaults to 1. The value will be capped to the number of available CPUs.
|
* If not value was specified, all available threads will be used.
|
||||||
|
*
|
||||||
|
* The value will be capped to the number of available CPUs.
|
||||||
*
|
*
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
function getThreadsFlag() {
|
function getThreadsFlag() {
|
||||||
let numThreads = 1;
|
let numThreads;
|
||||||
const numThreadsString = core.getInput("threads");
|
const numThreadsString = core.getInput("threads");
|
||||||
|
const maxThreads = os.cpus().length;
|
||||||
if (numThreadsString) {
|
if (numThreadsString) {
|
||||||
numThreads = Number(numThreadsString);
|
numThreads = Number(numThreadsString);
|
||||||
if (Number.isNaN(numThreads)) {
|
if (Number.isNaN(numThreads)) {
|
||||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||||
}
|
}
|
||||||
const maxThreads = os.cpus().length;
|
|
||||||
if (numThreads > maxThreads) {
|
if (numThreads > maxThreads) {
|
||||||
|
core.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
|
||||||
numThreads = maxThreads;
|
numThreads = maxThreads;
|
||||||
}
|
}
|
||||||
const minThreads = -maxThreads;
|
const minThreads = -maxThreads;
|
||||||
if (numThreads < minThreads) {
|
if (numThreads < minThreads) {
|
||||||
|
core.info(`Clamping desired number of free threads (${numThreads}) to max available (${minThreads}).`);
|
||||||
numThreads = minThreads;
|
numThreads = minThreads;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Default to using all threads
|
||||||
|
numThreads = maxThreads;
|
||||||
|
}
|
||||||
return `--threads=${numThreads}`;
|
return `--threads=${numThreads}`;
|
||||||
}
|
}
|
||||||
exports.getThreadsFlag = getThreadsFlag;
|
exports.getThreadsFlag = getThreadsFlag;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
15
src/util.ts
15
src/util.ts
|
|
@ -375,27 +375,34 @@ export function getMemoryFlag(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the codeql `--threads` value specified for the `threads` input. The value
|
* Get the codeql `--threads` value specified for the `threads` input.
|
||||||
* defaults to 1. The value will be capped to the number of available CPUs.
|
* If not value was specified, all available threads will be used.
|
||||||
|
*
|
||||||
|
* The value will be capped to the number of available CPUs.
|
||||||
*
|
*
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
export function getThreadsFlag(): string {
|
export function getThreadsFlag(): string {
|
||||||
let numThreads = 1;
|
let numThreads: number;
|
||||||
const numThreadsString = core.getInput("threads");
|
const numThreadsString = core.getInput("threads");
|
||||||
|
const maxThreads = os.cpus().length;
|
||||||
if (numThreadsString) {
|
if (numThreadsString) {
|
||||||
numThreads = Number(numThreadsString);
|
numThreads = Number(numThreadsString);
|
||||||
if (Number.isNaN(numThreads)) {
|
if (Number.isNaN(numThreads)) {
|
||||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||||
}
|
}
|
||||||
const maxThreads = os.cpus().length;
|
|
||||||
if (numThreads > maxThreads) {
|
if (numThreads > maxThreads) {
|
||||||
|
core.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
|
||||||
numThreads = maxThreads;
|
numThreads = maxThreads;
|
||||||
}
|
}
|
||||||
const minThreads = -maxThreads;
|
const minThreads = -maxThreads;
|
||||||
if (numThreads < minThreads) {
|
if (numThreads < minThreads) {
|
||||||
|
core.info(`Clamping desired number of free threads (${numThreads}) to max available (${minThreads}).`);
|
||||||
numThreads = minThreads;
|
numThreads = minThreads;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Default to using all threads
|
||||||
|
numThreads = maxThreads;
|
||||||
}
|
}
|
||||||
return `--threads=${numThreads}`;
|
return `--threads=${numThreads}`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue