Skip to content
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

Add cpu profiling #2536

Closed
wants to merge 4 commits into from
Closed

Conversation

Lakitna
Copy link
Contributor

@Lakitna Lakitna commented Oct 7, 2020

As discussed in #2417 (comment)

Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

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

Thanks. Could you give me a small introduction about what --cpu-prof does? 😅

@@ -27,6 +27,7 @@ const BROKEN_PIPE_ERROR_CODE = 'EPIPE';
const IPC_CHANNEL_CLOSED_ERROR_CODE = 'ERR_IPC_CHANNEL_CLOSED';
const TIMEOUT_FOR_DISPOSE = 2000;

let n = 0;
Copy link
Member

Choose a reason for hiding this comment

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

What is this doing here? n is never updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

n is updated on 56 and used on 55. Basically, I use it to enumerate the child process output files to check how many of them are missing. Another naming scheme is fine with me.

Copy link
Member

Choose a reason for hiding this comment

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

Should we not reuse this n? For example, with --concurrency 4, we might want to use 1, 2, 3, and 4, but never 5. Whenever a child process crashes, it can reuse the number.

Copy link
Contributor Author

@Lakitna Lakitna Oct 14, 2020

Choose a reason for hiding this comment

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

No, that'll result in overwritten .cpuprofile files.

n here is not a good solution by any means, but it is a human-readable approach to unique file names. Doing it sequenced like this allows a human to see how many processes crashed, as crashed processes have no .cpuprofile file.

For example:

image

We can see that 1, 3, 6-10, 12-14, and 17 are missing here. These processes must have crashed for some reason.

This insight is the only reason why we need n.

Edit: The last file of the run is child-process-278.cpuprofile. I have a feeling that there are many more processes than you're expecting.

@@ -48,7 +49,14 @@ export default class ChildProcessProxy<T> implements Disposable {
additionalInjectableValues: unknown,
workingDirectory: string
) {
this.worker = fork(require.resolve('./ChildProcessProxyWorker'), [autoStart], { silent: true, execArgv: [] });
const execArgv = [];
if (process.env.STRYKER_PROFILE) {
Copy link
Member

Choose a reason for hiding this comment

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

I think adding environment variables should be a "last resort". (I literally have nightmares about the vue-cli and the zoo of env variables there 😪).

Can we simply check if the current process has the --cpu-prof argument and, if so, forward that to the child process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can, I initially had it set up with a flag. The downside here is that we will have to add the flag to the StrykerCli.ts, so the option would be exposed to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See commit, I've changed things over to the --cpu-prof flag on stryker run.

@Lakitna
Copy link
Contributor Author

Lakitna commented Oct 10, 2020

In simple terms, --cpu-prof calls the V8 profiler where --prof uses a Node-specific profiler. The upside of using the V8 one is tooling support.

Running a script with --cpu-prof will output a .cpuprofile file. This file can be read by Chromes profiler (chrome://inspect -> Open dedicated DevTools for Node -> Profile tab -> load).

image

In the profiler tooling, you can see at what point of the scripts life cycle it was doing what. For example, in the image above you can see that the first part of the script is all requires, and then it starts running mutants. In fact, a simple ctrl+f tells me this particular child worker only executed tests for 3 mutants.

@nicojs
Copy link
Member

nicojs commented Oct 29, 2020

I was thinking, maybe it might be a better idea to add --workerNodeArgs support. It would be a really low level and simple way to support both --cpu-prof, --prof and any other arguments, like --inspect-brk.

It would be a simple (dumb) sollution, so users should combine this with --concurrency.

It would allow for low maintenance and maximum flexibility.

@Lakitna , what do you think?

@nicojs nicojs mentioned this pull request Nov 4, 2020
4 tasks
@nicojs
Copy link
Member

nicojs commented Nov 6, 2020

This use case will be supported with #2609

@nicojs nicojs closed this Nov 6, 2020
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.

None yet

2 participants