Add RAM and threads options to init action

This commit is contained in:
Chuan-kai Lin 2021-10-28 15:09:59 -07:00
parent 2905689d8a
commit 70b730eb7d
25 changed files with 631 additions and 58 deletions

View file

@ -85,13 +85,13 @@ function getSystemReservedMemoryMegaBytes(): number {
}
/**
* Get the codeql `--ram` flag as configured by the `ram` input. If no value was
* specified, the total available memory will be used minus a threshold
* reserved for the OS.
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
* If no value was specified, the total available memory will be used minus a
* threshold reserved for the OS.
*
* @returns string
* @returns {number} the amount of RAM to use, in megabytes
*/
export function getMemoryFlag(userInput: string | undefined): string {
export function getMemoryFlagValue(userInput: string | undefined): number {
let memoryToUseMegaBytes: number;
if (userInput) {
memoryToUseMegaBytes = Number(userInput);
@ -104,7 +104,18 @@ export function getMemoryFlag(userInput: string | undefined): string {
const reservedMemoryMegaBytes = getSystemReservedMemoryMegaBytes();
memoryToUseMegaBytes = totalMemoryMegaBytes - reservedMemoryMegaBytes;
}
return `--ram=${Math.floor(memoryToUseMegaBytes)}`;
return Math.floor(memoryToUseMegaBytes);
}
/**
* Get the codeql `--ram` flag as configured by the `ram` input. If no value was
* specified, the total available memory will be used minus a threshold
* reserved for the OS.
*
* @returns string
*/
export function getMemoryFlag(userInput: string | undefined): string {
return `--ram=${getMemoryFlagValue(userInput)}`;
}
/**
@ -123,17 +134,17 @@ export function getAddSnippetsFlag(
}
/**
* Get the codeql `--threads` value specified for the `threads` input.
* If no value was specified, all available threads will be used.
* Get the value of the codeql `--threads` flag specified for the `threads`
* input. If no value was specified, all available threads will be used.
*
* The value will be capped to the number of available CPUs.
*
* @returns string
* @returns {number}
*/
export function getThreadsFlag(
export function getThreadsFlagValue(
userInput: string | undefined,
logger: Logger
): string {
): number {
let numThreads: number;
const maxThreads = os.cpus().length;
if (userInput) {
@ -158,7 +169,22 @@ export function getThreadsFlag(
// Default to using all threads
numThreads = maxThreads;
}
return `--threads=${numThreads}`;
return numThreads;
}
/**
* Get the codeql `--threads` flag specified for the `threads` input.
* If no value was specified, all available threads will be used.
*
* The value will be capped to the number of available CPUs.
*
* @returns string
*/
export function getThreadsFlag(
userInput: string | undefined,
logger: Logger
): string {
return `--threads=${getThreadsFlagValue(userInput, logger)}`;
}
/**