Skip to content

Commit

Permalink
Merge pull request #122 from input-output-hk/rvl/adp-1173/rtsopts
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 26, 2021
2 parents e77702f + 086deea commit 7cc09bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/cardanoNode.ts
Expand Up @@ -11,7 +11,7 @@ import path from 'path';
import getPort from 'get-port';

import { StartService, ShutdownMethod, cleanShutdownFD } from './service';
import { FilePath, DirPath } from './common';
import { FilePath, DirPath, makeRtsArgs } from './common';

/**
* Definition of a `cardano-node` network.
Expand Down Expand Up @@ -104,6 +104,9 @@ export interface CardanoNodeArgs {
/** Validate all on-disk database files. */
validateDb?: boolean;

/** GHC runtime system options. */
rtsOpts?: string[];

/**
* Extra arguments to add to the `cardano-node` command line.
*/
Expand Down Expand Up @@ -148,6 +151,13 @@ export interface CardanoNodeConfig {
* node. Optional -- will be set automatically if not provided.
*/
socketFile?: FilePath;

/**
* GHC runtime system options for cardano-node.
* Can be used for debugging, tuning performance, etc.
* See: https://downloads.haskell.org/ghc/8.10.7/docs/html/users_guide/runtime_control.html#setting-rts-options-on-the-command-line
*/
rtsOpts?: string[];
}

let pipeCounter = 0;
Expand Down Expand Up @@ -227,6 +237,7 @@ function makeArgs(
signingKey: config.signingKey,
kesKey: config.kesKey,
vrfKey: config.vrfKey,
rtsOpts: config.rtsOpts,
};
}

Expand Down Expand Up @@ -287,6 +298,7 @@ export async function startCardanoNode(
? ['--shelley-operational-certificate', args.operationalCertificate]
: []
)
.concat(makeRtsArgs(args.rtsOpts))
.concat(args.extra || []),
shutdownMethod: ShutdownMethod.CloseFD,
// set working directory to stateDir -- config file may have relative paths for logs.
Expand Down
11 changes: 11 additions & 0 deletions src/common.ts
Expand Up @@ -34,3 +34,14 @@ export function passthroughErrorLogger(err: Error): void {
* eslint warning from appearing.
*/
export function ignorePromiseRejection(_: Error): void {} // eslint-disable-line

/**
* Format GHC RTS options for the command line.
*
* See: https://downloads.haskell.org/ghc/8.10.7/docs/html/users_guide/runtime_control.html#setting-rts-options-on-the-command-line
*/
export function makeRtsArgs(rtsOpts?: string[]): string[] {
return Array.isArray(rtsOpts) && rtsOpts.length
? ['+RTS'].concat(rtsOpts as string[]).concat(['-RTS'])
: [];
}
27 changes: 26 additions & 1 deletion test/integration.test.ts
Expand Up @@ -8,7 +8,7 @@ import * as https from 'https';
import * as tmp from 'tmp-promise';
import * as path from 'path';
import * as fs from 'fs';
import { stat } from 'fs-extra';
import { stat, pathExists } from 'fs-extra';

import * as cardanoNode from '../src/cardanoNode';
import { ExitStatus } from '../src/cardanoLauncher';
Expand Down Expand Up @@ -262,6 +262,31 @@ describe('Starting cardano-wallet (and its node)', () => {
},
veryLongTestTimeoutMs
);

it(
'applies RTS options to cardano-node',
async () => {
let hp = 'cardano-node.hp';
const launcher = await setupTestLauncher(stateDir => {
hp = path.join(stateDir, hp);
return {
stateDir,
networkName: 'testnet',
nodeConfig: {
kind: 'shelley',
configurationDir: getShelleyConfigDir('testnet'),
network: cardanoNode.networks.testnet,
rtsOpts: ['-h'], // generates a basic heap profile
},
};
});

await launcher.start();
expect(await pathExists(hp)).toBe(true);
await launcher.stop(defaultStopTimeout);
},
veryLongTestTimeoutMs
);
});

async function setupTestLauncher(
Expand Down

0 comments on commit 7cc09bb

Please sign in to comment.