Commit caa0f4c
authored
feat(aws-cdk-lib): emits performance counters if synthesis is slow (#37919)
(This is a re-roll of #37843, to account for the warning emitted by `fs-extra` if it detects monkey patching)
If the framework determines that synthesis is taking a long time (more than 10 seconds per stack, which is extremely unlikely high; we may adjust this threshold over time) it will emit a file with performance counters to the file indicated by the `$CDK_PERF_COUNTERS_FILE` environment variable.
The CLI is responsible for sending this report in as telemetry, or not if disabled.
The reporting can be disabled altogether by passing a property to `App`, or setting a context key in `cdk.json`:
```ts
new App({
performanceReporting: false,
});
```
```js
{
"context": {
"aws:cdk:performance-reporting": false,
},
}
```
Performance profiling works by making functions emit `measure` events to the Node [performance measurement APIs](https://nodejs.org/api/perf_hooks.html). The new `perf.ts` file provides a number of helper functions to decorate classes and functions to make them emit measurement information. A number of CDK APIs that we suspect of being slow are annotated by default, and some global NodeJS APIs that are typical sources of slowness (filesystem access, subprocess spawns) are annotated as well.
CDK users are free to use these functions as well and the `printPerfCounters()` function to do their own profiling.
At the end of synthesis, only those counters annotated with `{ telemetry: true }` are written to the telemetry file and sent to the server.
Here is an example of a set of perf counters (extracted from a test):
```js
{
'phase:Construction': 12154,
'phase:Construction(cnt)': 1,
'bundle:NodejsFunction': 12133,
'bundle:NodejsFunction(cnt)': 2,
'DockerImage.fromBuild': 10957,
'DockerImage.fromBuild(cnt)': 1,
'phase:Load': 3940,
'phase:Load(cnt)': 1,
'AssetBundlingBindMount.run': 1176,
'AssetBundlingBindMount.run(cnt)': 1,
'phase:Synthesis': 26,
'phase:Synthesis(cnt)': 1,
'Stack.resolve': 7,
'Stack.resolve(cnt)': 47,
'FileSystem.fingerprint': 1,
'FileSystem.fingerprint(cnt)': 1,
'FileSystem.isEmpty': 0,
'FileSystem.isEmpty(cnt)': 1
}
```
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
### Issue # (if applicable)
Closes #<issue number here>.
### Reason for this change
### Description of changes
### Describe any new or updated permissions being added
### Description of how you validated changes
### Checklist
- [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent dddc6e0 commit caa0f4c
19 files changed
Lines changed: 718 additions & 22 deletions
File tree
- packages
- @aws-cdk
- aws-lambda-go-alpha/lib
- aws-lambda-python-alpha/lib
- aws-cdk-lib
- aws-lambda-nodejs
- lib
- test/e2e
- core
- lib
- fs
- helpers-internal
- private
- test
- fs
- private
- cx-api/lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
145 | | - | |
146 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
147 | 159 | | |
148 | 160 | | |
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
152 | 164 | | |
153 | | - | |
154 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
155 | 170 | | |
156 | 171 | | |
157 | 172 | | |
| |||
177 | 192 | | |
178 | 193 | | |
179 | 194 | | |
| 195 | + | |
| 196 | + | |
180 | 197 | | |
181 | 198 | | |
182 | 199 | | |
| |||
Lines changed: 21 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
| 89 | + | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| |||
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | | - | |
187 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
188 | 200 | | |
189 | 201 | | |
190 | 202 | | |
| |||
193 | 205 | | |
194 | 206 | | |
195 | 207 | | |
196 | | - | |
197 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
198 | 213 | | |
199 | 214 | | |
200 | 215 | | |
| |||
455 | 470 | | |
456 | 471 | | |
457 | 472 | | |
| 473 | + | |
458 | 474 | | |
459 | 475 | | |
460 | 476 | | |
| |||
Lines changed: 58 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| |||
250 | 256 | | |
251 | 257 | | |
252 | 258 | | |
253 | | - | |
254 | 259 | | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
259 | 264 | | |
260 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
261 | 317 | | |
262 | 318 | | |
263 | 319 | | |
| |||
513 | 569 | | |
514 | 570 | | |
515 | 571 | | |
| 572 | + | |
516 | 573 | | |
517 | 574 | | |
518 | 575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
0 commit comments