Skip to content

Commit 5c5f422

Browse files
authored
Merge pull request #37 from github/use-full-memory
Use the full amount of memory when running queries.
2 parents 6507fba + 97ef912 commit 5c5f422

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

analyze/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
description: Upload the SARIF file
1313
required: false
1414
default: true
15+
ram:
16+
description: Override the amount of memory in MB to be used by CodeQL. By default, almost all the memory of the machine is used.
17+
required: false
1518
token:
1619
default: ${{ github.token }}
1720
matrix:

lib/finalize-db.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/finalize-db.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/finalize-db.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import * as io from '@actions/io';
44
import * as fs from 'fs';
5+
import * as os from 'os';
56
import * as path from 'path';
67

78
import * as configUtils from './config-utils';
@@ -10,6 +11,23 @@ import * as sharedEnv from './shared-environment';
1011
import * as upload_lib from './upload-lib';
1112
import * as util from './util';
1213

14+
function getMemoryFlag(): string {
15+
let memoryToUseMegaBytes: number;
16+
const memoryToUseString = core.getInput("ram");
17+
if (memoryToUseString) {
18+
memoryToUseMegaBytes = Number(memoryToUseString);
19+
if (Number.isNaN(memoryToUseMegaBytes) || memoryToUseMegaBytes <= 0) {
20+
throw new Error("Invalid RAM setting \"" + memoryToUseString + "\", specified.");
21+
}
22+
} else {
23+
const totalMemoryBytes = os.totalmem();
24+
const totalMemoryMegaBytes = totalMemoryBytes / (1024 * 1024);
25+
const systemReservedMemoryMegaBytes = 256;
26+
memoryToUseMegaBytes = totalMemoryMegaBytes - systemReservedMemoryMegaBytes;
27+
}
28+
return "--ram=" + Math.floor(memoryToUseMegaBytes);
29+
}
30+
1331
async function createdDBForScannedLanguages(codeqlCmd: string, databaseFolder: string) {
1432
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
1533
if (scannedLanguages) {
@@ -113,6 +131,7 @@ async function runQueries(codeqlCmd: string, databaseFolder: string, sarifFolder
113131
await exec.exec(codeqlCmd, [
114132
'database',
115133
'analyze',
134+
getMemoryFlag(),
116135
path.join(databaseFolder, database),
117136
'--format=sarif-latest',
118137
'--output=' + sarifFile,

0 commit comments

Comments
 (0)