Skip to content

feat(swingset-runner): Add cpu/heap profiling support #11400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

usmanmani1122
Copy link
Contributor

Description

This PR adds support for generating cpu and/or heap profiles in the swingset runner using the engine's native inspector
Also fixed some typing errors (not all of them)

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

Added help messages for the added flags

Testing Considerations

Tested by generating profiles

Upgrade Considerations

None

@usmanmani1122 usmanmani1122 self-assigned this May 22, 2025
@usmanmani1122 usmanmani1122 requested a review from a team as a code owner May 22, 2025 07:42
Copy link

cloudflare-workers-and-pages bot commented May 22, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: a9a16ed
Status: ✅  Deploy successful!
Preview URL: https://317675e4.agoric-sdk.pages.dev
Branch Preview URL: https://usman-swingset-runner-profil.agoric-sdk.pages.dev

View logs

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, modulo some tweaks to argument processing. Thanks for the type annotations. Do you think you could also add a simple README.md?

@@ -368,6 +377,56 @@ export async function main() {
case '--sbench':
swingsetBenchmarkDriverPath = argv.shift();
break;
case '--cpu-profile-output':
cpuProfileFilePath = path.resolve(String(argv.shift()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cpuProfileFilePath = path.resolve(String(argv.shift()));
cpuProfileFilePath = path.resolve(argv.shift());

case '--cpu-profile-output':
cpuProfileFilePath = path.resolve(String(argv.shift()));
await new Promise(resolve => {
const parentDirectory = path.dirname(String(cpuProfileFilePath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const parentDirectory = path.dirname(String(cpuProfileFilePath));
const parentDirectory = path.dirname(cpuProfileFilePath);

const parentDirectory = path.dirname(String(cpuProfileFilePath));
fs.access(parentDirectory, fs.constants.F_OK, err => {
if (err) {
console.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw rather than warn. Also, wouldn't the whole thing be easier with fs/promises?

        try {
          const parentDirectory = path.dirname(cpuProfileFilePath);
          const dir = await fsp.opendir(parentDirectory);
          dir.closeSync();
          if (!inspectorSession) {
            await initializeInspectorSession();
          }
        } catch (cause) {
          throw Error(`Can't record CPU profile at ${cpuProfileFilePath}`, { cause });
        }

case '--heap-sampling-interval':
samplingInterval = Number(argv.shift());
if (Number.isNaN(samplingInterval) || samplingInterval < 1)
console.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw instead.

config.devices.bridge = {
sourceSpec: bridge.srcPath,
};
config.devices.bridge = { sourceSpec: bridge.srcPath };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, I'd love to see this reimplemented on the cosmic-swingset test kit too!

@toliaqat toliaqat removed their request for review May 22, 2025 16:12
@usmanmani1122
Copy link
Contributor Author

This seems reasonable, modulo some tweaks to argument processing. Thanks for the type annotations. Do you think you could also add a simple README.md?

I have added the usage message in the README for now

@usmanmani1122 usmanmani1122 requested a review from gibson042 May 23, 2025 12:44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not render well; the line breaks are all collapsed.

@@ -303,7 +303,8 @@ export async function main() {
logStats = true;
break;
case '--logtag':
logTag = argv.shift();
nextArg = argv.shift();
nextArg && (logTag = nextArg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --logtag '', is invalid, it should be rejected with an error rather than silently ignored.

@@ -333,11 +334,13 @@ export async function main() {
doDumps = true;
break;
case '--dumpdir':
dumpDir = argv.shift();
nextArg = argv.shift();
nextArg && (dumpDir = nextArg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here.

doDumps = true;
break;
case '--dumptag':
dumpTag = argv.shift();
nextArg = argv.shift();
nextArg && (dumpTag = nextArg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants