Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #37 from github/use-full-memory
Use the full amount of memory  when running queries.
Chris Gavin authored and GitHub committed May 18, 2020

Unverified

No user is associated with the committer email.
2 parents 6507fba + 97ef912 commit 5c5f422
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions analyze/action.yml
@@ -12,6 +12,9 @@ inputs:
description: Upload the SARIF file
required: false
default: true
ram:
description: Override the amount of memory in MB to be used by CodeQL. By default, almost all the memory of the machine is used.
required: false
token:
default: ${{ github.token }}
matrix:
19 changes: 19 additions & 0 deletions lib/finalize-db.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/finalize-db.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/finalize-db.ts
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

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

function getMemoryFlag(): string {
let memoryToUseMegaBytes: number;
const memoryToUseString = core.getInput("ram");
if (memoryToUseString) {
memoryToUseMegaBytes = Number(memoryToUseString);
if (Number.isNaN(memoryToUseMegaBytes) || memoryToUseMegaBytes <= 0) {
throw new Error("Invalid RAM setting \"" + memoryToUseString + "\", specified.");
}
} else {
const totalMemoryBytes = os.totalmem();
const totalMemoryMegaBytes = totalMemoryBytes / (1024 * 1024);
const systemReservedMemoryMegaBytes = 256;
memoryToUseMegaBytes = totalMemoryMegaBytes - systemReservedMemoryMegaBytes;
}
return "--ram=" + Math.floor(memoryToUseMegaBytes);
}

async function createdDBForScannedLanguages(codeqlCmd: string, databaseFolder: string) {
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
if (scannedLanguages) {
@@ -113,6 +131,7 @@ async function runQueries(codeqlCmd: string, databaseFolder: string, sarifFolder
await exec.exec(codeqlCmd, [
'database',
'analyze',
getMemoryFlag(),
path.join(databaseFolder, database),
'--format=sarif-latest',
'--output=' + sarifFile,

0 comments on commit 5c5f422

Please sign in to comment.