| 345 | } |
| 346 | |
| 347 | private finish( |
| 348 | kind: SpanKind, |
| 349 | start: number, |
| 350 | now: number, |
| 351 | fileId: number | undefined, |
| 352 | childUs: number, |
| 353 | ): void { |
| 354 | const dur = Math.max(0, now - start); |
| 355 | this.spanCount[kind]++; |
| 356 | this.spanInclusiveUs[kind] += dur; |
| 357 | this.spanSelfUs[kind] += Math.max(0, dur - childUs); |
| 358 | const depth = this.openChildUs.length; |
| 359 | if (depth > 0) { |
| 360 | this.openChildUs[depth - 1] += dur; |
| 361 | } |
| 362 | if (!AWAITING_KINDS[kind] && --this.openNonAwaiting === 0) { |
| 363 | this.busyUs += dur; |
| 364 | } |
| 365 | const event: TraceEvent = { |
| 366 | name: SPAN_NAMES[kind], |
| 367 | cat: 'ngp', |
| 368 | ph: 'X', |
| 369 | pid: this.pid, |
| 370 | tid: 1, |
| 371 | ts: start, |
| 372 | dur, |
| 373 | }; |
| 374 | if (fileId) { |
| 375 | event.args = {f: fileId}; |
| 376 | } |
| 377 | this.events.push(event); |
| 378 | } |
| 379 | |
| 380 | slice<T>(kind: SpanKind, fn: () => T, fileId?: number): T { |
| 381 | const token = this.begin(kind, fileId); |