| 410 | } |
| 411 | |
| 412 | private asyncEvent( |
| 413 | ph: 'b' | 'e', |
| 414 | kind: SpanKind, |
| 415 | fileId: number, |
| 416 | args?: Record<string, unknown>, |
| 417 | ): void { |
| 418 | const now = nowMicros(); |
| 419 | const key = fileId * SPAN_KINDS + kind; |
| 420 | if (ph === 'b') { |
| 421 | this.asyncOpen.set(key, now); |
| 422 | } else { |
| 423 | const start = this.asyncOpen.get(key); |
| 424 | if (start === undefined) { |
| 425 | return; |
| 426 | } |
| 427 | this.asyncOpen.delete(key); |
| 428 | this.asyncCount[kind]++; |
| 429 | this.asyncWallUs[kind] += Math.max(0, now - start); |
| 430 | } |
| 431 | const event: TraceEvent = { |
| 432 | name: SPAN_NAMES[kind], |
| 433 | cat: 'ngp.file', |
| 434 | ph, |
| 435 | pid: this.pid, |
| 436 | tid: 1, |
| 437 | ts: now, |
| 438 | id2: {local: fileId}, |
| 439 | }; |
| 440 | if (args !== undefined) { |
| 441 | event.args = args; |
| 442 | } |
| 443 | this.events.push(event); |
| 444 | } |
| 445 | |
| 446 | count(counter: Counter, n = 1): void { |
| 447 | this.counters[counter] += n; |