()
| 475 | } |
| 476 | |
| 477 | take(): {events: TraceEvent[]; summary: PerfSummary} { |
| 478 | const now = nowMicros(); |
| 479 | const summary = emptySummary(Math.round(now - this.startUs)); |
| 480 | const node = summary.node; |
| 481 | for (let kind = 0; kind < SPAN_KINDS; kind++) { |
| 482 | if (this.spanCount[kind] > 0) { |
| 483 | node.spans[SpanKind[kind]] = { |
| 484 | count: this.spanCount[kind], |
| 485 | selfUs: Math.round(this.spanSelfUs[kind]), |
| 486 | inclusiveUs: Math.round(this.spanInclusiveUs[kind]), |
| 487 | }; |
| 488 | } |
| 489 | if (this.asyncCount[kind] > 0) { |
| 490 | node.async[SpanKind[kind]] = { |
| 491 | count: this.asyncCount[kind], |
| 492 | wallUs: Math.round(this.asyncWallUs[kind]), |
| 493 | }; |
| 494 | } |
| 495 | } |
| 496 | node.mainThreadBusyUs = Math.round(this.busyUs); |
| 497 | for (let counter = 0; counter < COUNTERS; counter++) { |
| 498 | node.counters[Counter[counter]] = this.counters[counter]; |
| 499 | } |
| 500 | if (this.gcObserver !== undefined) { |
| 501 | // Entries are delivered a tick after the GC, so ones from the last tick may be missed. |
| 502 | // `takeRecords` is missing from some @types/node versions. |
| 503 | const observer = this.gcObserver as unknown as {takeRecords?(): PerformanceEntry[]}; |
| 504 | this.addGcEntries(observer.takeRecords?.() ?? []); |
| 505 | this.gcObserver.disconnect(); |
| 506 | this.gcObserver = undefined; |
| 507 | } |
| 508 | node.gc = {count: this.gcCount, totalUs: Math.round(this.gcUs)}; |
| 509 | const {spans, async, ...nodeTotals} = node; |
| 510 | if (this.rust !== undefined) { |
| 511 | summary.rust = this.rust; |
| 512 | } |
| 513 | |
| 514 | const pid = this.pid; |
| 515 | const events: TraceEvent[] = [ |
| 516 | metadata('process_name', pid, 0, 'ngp'), |
| 517 | metadata('thread_name', pid, 1, 'main'), |
| 518 | metadata('thread_name', pid, GC_TID, 'gc'), |
| 519 | ...this.events, |
| 520 | {name: 'ngp.Counters', cat: 'ngp', ph: 'C', pid, tid: 1, ts: now, args: {...node.counters}}, |
| 521 | // Spans are left out; the timeline has them. |
| 522 | {name: 'ngp.Summary', cat: 'ngp', ph: 'i', s: 'p', pid, tid: 1, ts: now, args: nodeTotals}, |
| 523 | ]; |
| 524 | |
| 525 | // A section still open (a `sliceAsync` whose promise hasn't settled) is dropped. |
| 526 | this.openKind.length = 0; |
| 527 | this.openStart.length = 0; |
| 528 | this.openFile.length = 0; |
| 529 | this.openChildUs.length = 0; |
| 530 | this.openNonAwaiting = 0; |
| 531 | this.events = []; |
| 532 | this.spanCount.fill(0); |
| 533 | this.spanInclusiveUs.fill(0); |
| 534 | this.spanSelfUs.fill(0); |
nothing calls this directly
no test coverage detected