@@ -150,8 +150,8 @@ class NetworkEventProcessor extends TimelineEventProcessor {
150
150
}
151
151
}
152
152
153
- async function gatherNetworkTimelineEvents ( cwd , scriptFilePath , eventType , args ) {
154
- return gatherTimelineEvents ( cwd , scriptFilePath , eventType , args , NetworkEventProcessor )
153
+ async function gatherNetworkTimelineEvents ( cwd , scriptFilePath , agentPort , eventType , args ) {
154
+ return gatherTimelineEvents ( cwd , scriptFilePath , agentPort , eventType , args , NetworkEventProcessor )
155
155
}
156
156
157
157
class FilesystemEventProcessor extends TimelineEventProcessor {
@@ -201,18 +201,19 @@ class FilesystemEventProcessor extends TimelineEventProcessor {
201
201
}
202
202
}
203
203
204
- async function gatherFilesystemTimelineEvents ( cwd , scriptFilePath ) {
205
- return gatherTimelineEvents ( cwd , scriptFilePath , 'fs' , [ ] , FilesystemEventProcessor )
204
+ async function gatherFilesystemTimelineEvents ( cwd , scriptFilePath , agentPort ) {
205
+ return gatherTimelineEvents ( cwd , scriptFilePath , agentPort , 'fs' , [ ] , FilesystemEventProcessor )
206
206
}
207
207
208
- async function gatherTimelineEvents ( cwd , scriptFilePath , eventType , args , Processor ) {
208
+ async function gatherTimelineEvents ( cwd , scriptFilePath , agentPort , eventType , args , Processor ) {
209
209
const procStart = BigInt ( Date . now ( ) * 1000000 )
210
210
const proc = fork ( path . join ( cwd , scriptFilePath ) , args , {
211
211
cwd,
212
212
env : {
213
213
DD_PROFILING_EXPORTERS : 'file' ,
214
214
DD_PROFILING_ENABLED : 1 ,
215
- DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED : 0 // capture all events
215
+ DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED : 0 , // capture all events
216
+ DD_TRACE_AGENT_PORT : agentPort
216
217
}
217
218
} )
218
219
@@ -312,6 +313,14 @@ describe('profiler', () => {
312
313
await sandbox . remove ( )
313
314
} )
314
315
316
+ beforeEach ( async ( ) => {
317
+ agent = await new FakeAgent ( ) . start ( )
318
+ } )
319
+
320
+ afterEach ( async ( ) => {
321
+ await agent . stop ( )
322
+ } )
323
+
315
324
if ( process . platform !== 'win32' ) {
316
325
it ( 'code hotspots and endpoint tracing works' , async function ( ) {
317
326
// see comment on busyCycleTimeNs recomputation below. Ideally a single retry should be enough
@@ -323,7 +332,8 @@ describe('profiler', () => {
323
332
env : {
324
333
DD_PROFILING_EXPORTERS : 'file' ,
325
334
DD_PROFILING_ENABLED : 1 ,
326
- BUSY_CYCLE_TIME : ( busyCycleTimeNs | 0 ) . toString ( )
335
+ BUSY_CYCLE_TIME : ( busyCycleTimeNs | 0 ) . toString ( ) ,
336
+ DD_TRACE_AGENT_PORT : agent . port
327
337
}
328
338
} )
329
339
@@ -440,7 +450,7 @@ describe('profiler', () => {
440
450
} )
441
451
442
452
it ( 'fs timeline events work' , async ( ) => {
443
- const fsEvents = await gatherFilesystemTimelineEvents ( cwd , 'profiler/fstest.js' )
453
+ const fsEvents = await gatherFilesystemTimelineEvents ( cwd , 'profiler/fstest.js' , agent . port )
444
454
assert . equal ( fsEvents . length , 6 )
445
455
const path = fsEvents [ 0 ] . path
446
456
const fd = fsEvents [ 1 ] . fd
@@ -456,7 +466,7 @@ describe('profiler', () => {
456
466
} )
457
467
458
468
it ( 'dns timeline events work' , async ( ) => {
459
- const dnsEvents = await gatherNetworkTimelineEvents ( cwd , 'profiler/dnstest.js' , 'dns' )
469
+ const dnsEvents = await gatherNetworkTimelineEvents ( cwd , 'profiler/dnstest.js' , agent . port , 'dns' )
460
470
assert . sameDeepMembers ( dnsEvents , [
461
471
{ operation : 'lookup' , host : 'example.org' } ,
462
472
{ operation : 'lookup' , host : 'example.com' } ,
@@ -494,7 +504,7 @@ describe('profiler', () => {
494
504
const args = [ String ( port1 ) , String ( port2 ) , msg ]
495
505
// Invoke the profiled program, passing it the ports of the servers and
496
506
// the expected message.
497
- const events = await gatherNetworkTimelineEvents ( cwd , 'profiler/nettest.js' , 'net' , args )
507
+ const events = await gatherNetworkTimelineEvents ( cwd , 'profiler/nettest.js' , agent . port , 'net' , args )
498
508
// The profiled program should have two TCP connection events to the two
499
509
// servers.
500
510
assert . sameDeepMembers ( events , [
@@ -511,8 +521,7 @@ describe('profiler', () => {
511
521
}
512
522
513
523
context ( 'shutdown' , ( ) => {
514
- beforeEach ( async ( ) => {
515
- agent = await new FakeAgent ( ) . start ( )
524
+ beforeEach ( ( ) => {
516
525
oomEnv = {
517
526
DD_TRACE_AGENT_PORT : agent . port ,
518
527
DD_PROFILING_ENABLED : 1 ,
@@ -521,9 +530,8 @@ describe('profiler', () => {
521
530
}
522
531
} )
523
532
524
- afterEach ( async ( ) => {
533
+ afterEach ( ( ) => {
525
534
proc . kill ( )
526
- await agent . stop ( )
527
535
} )
528
536
529
537
it ( 'records profile on process exit' , ( ) => {
@@ -641,13 +649,8 @@ describe('profiler', () => {
641
649
} )
642
650
643
651
context ( 'SSI heuristics' , ( ) => {
644
- beforeEach ( async ( ) => {
645
- agent = await new FakeAgent ( ) . start ( )
646
- } )
647
-
648
- afterEach ( async ( ) => {
652
+ afterEach ( ( ) => {
649
653
proc . kill ( )
650
- await agent . stop ( )
651
654
} )
652
655
653
656
describe ( 'does not trigger for' , ( ) => {
0 commit comments