Skip to content

Fix cpu profiling #12411

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

Merged
merged 5 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ if (process.env['CODE_COVERAGE'] || process.argv.indexOf('--code-coverage') !==
let profiler = null;
if (process.env['DEVKIT_PROFILING']) {
try {
profiler = require('v8-profiler');
profiler = require('v8-profiler-node8');
} catch (err) {
throw new Error(`Could not require 'v8-profiler'. You must install it separetely with` +
`'npm install v8-profiler --no-save.\n\nOriginal error:\n\n${err}`);
throw new Error(`Could not require 'v8-profiler-node8'. You must install it separetely with` +
`'npm install v8-profiler-node8 --no-save.\n\nOriginal error:\n\n${err}`);
}

profiler.startProfiling();
Expand Down
22 changes: 22 additions & 0 deletions packages/angular/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,28 @@ Then you can add breakpoints in `dist/@angular` files.

For more informations about Node.js debugging in VS Code, see the related [VS Code Documentation](https://code.visualstudio.com/docs/nodejs/nodejs-debugging).

### CPU Profiling

In order to investigate performance issues, CPU profiling is often usefull.

To capture a CPU profiling, you can:
1. install the v8-profiler-node8 dependency: `npm install v8-profiler-node8 --no-save`
1. set the NG_CLI_PROFILING Environment variable to the file name you want:
* on Unix systems (Linux & Mac OS X): ̀`export NG_CLI_PROFILING=my-profile`
* on Windows: ̀̀`setx NG_CLI_PROFILING my-profile`

Then, just run the ng command on which you want to capture a CPU profile.
You will then obtain a `my-profile.cpuprofile` file in the folder from wich you ran the ng command.

You can use the Chrome Devtools to process it. To do so:
1. open `chrome://inspect/#devices` in Chrome
1. click on "Open dedicated DevTools for Node"
1. go to the "profiler" tab
1. click on the "Load" button and select the generated .cpuprofile file
1. on the left panel, select the associated file

In addition to this one, another, more elaborated way to capture a CPU profile using the Chrome Devtools is detailed in https://github.com/angular/angular-cli/issues/8259#issue-269908550.

## Documentation

The documentation for the Angular CLI is located in this repo's [wiki](https://github.com/angular/angular-cli/wiki).
Expand Down
13 changes: 12 additions & 1 deletion packages/angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ function _fromPackageJson(cwd?: string) {

// Check if we need to profile this CLI run.
if (process.env['NG_CLI_PROFILING']) {
const profiler = require('v8-profiler'); // tslint:disable-line:no-implicit-dependencies
let profiler: {
startProfiling: (name?: string, recsamples?: boolean) => void;
stopProfiling: (name?: string) => any; // tslint:disable-line:no-any
};
try {
profiler = require('v8-profiler-node8'); // tslint:disable-line:no-implicit-dependencies
} catch (err) {
throw new Error(`Could not require 'v8-profiler-node8'. You must install it separetely with` +
`'npm install v8-profiler-node8 --no-save.\n\nOriginal error:\n\n${err}`);
}

profiler.startProfiling();

const exitHandler = (options: { cleanup?: boolean, exit?: boolean }) => {
if (options.cleanup) {
const cpuProfile = profiler.stopProfiling();
Expand Down