@@ -16,9 +16,11 @@ describe('profilers/native/wall', () => {
16
16
time : {
17
17
start : sinon . stub ( ) ,
18
18
stop : sinon . stub ( ) . returns ( 'profile' ) ,
19
+ setContext : sinon . stub ( ) ,
19
20
v8ProfilerStuckEventLoopDetected : sinon . stub ( ) . returns ( false ) ,
20
21
constants : {
21
- kSampleCount : 0
22
+ kSampleCount : 0 ,
23
+ NON_JS_THREADS_FUNCTION_NAME : 'Non JS threads activity'
22
24
}
23
25
}
24
26
}
@@ -174,4 +176,91 @@ describe('profilers/native/wall', () => {
174
176
collectCpuTime : false
175
177
} )
176
178
} )
179
+
180
+ it ( 'should generate appropriate sample labels' , ( ) => {
181
+ const profiler = new NativeWallProfiler ( { timelineEnabled : true } )
182
+ profiler . start ( )
183
+ profiler . stop ( )
184
+
185
+ function expectLabels ( context , expected ) {
186
+ const actual = profiler . _generateLabels ( { node : { } , context } )
187
+ expect ( actual ) . to . deep . equal ( expected )
188
+ }
189
+
190
+ expect ( profiler . _generateLabels ( { node : { name : 'Non JS threads activity' } } ) ) . to . deep . equal ( {
191
+ 'thread name' : 'Non-JS threads' ,
192
+ 'thread id' : 'NA' ,
193
+ 'os thread id' : 'NA'
194
+ } )
195
+
196
+ const shared = require ( '../../../src/profiling/profilers/shared' )
197
+ const nativeThreadId = shared . getThreadLabels ( ) [ 'os thread id' ]
198
+ const threadInfo = {
199
+ 'thread name' : 'Main Event Loop' ,
200
+ 'thread id' : '0' ,
201
+ 'os thread id' : nativeThreadId
202
+ }
203
+
204
+ expectLabels ( undefined , threadInfo )
205
+
206
+ const threadInfoWithTimestamp = {
207
+ ...threadInfo ,
208
+ end_timestamp_ns : 1234000n
209
+ }
210
+
211
+ expectLabels ( { timestamp : 1234n } , threadInfoWithTimestamp )
212
+
213
+ expectLabels ( { timestamp : 1234n , asyncId : - 1 } , threadInfoWithTimestamp )
214
+
215
+ expectLabels ( { timestamp : 1234n , asyncId : 1 } , {
216
+ ...threadInfoWithTimestamp ,
217
+ 'async id' : 1
218
+ } )
219
+
220
+ expectLabels ( { timestamp : 1234n , context : { } } , threadInfoWithTimestamp )
221
+
222
+ expectLabels ( { timestamp : 1234n , context : { ref : { } } } , threadInfoWithTimestamp )
223
+
224
+ expectLabels ( { timestamp : 1234n , context : { ref : { spanId : 'foo' } } } , {
225
+ ...threadInfoWithTimestamp ,
226
+ 'span id' : 'foo'
227
+ } )
228
+
229
+ expectLabels ( { timestamp : 1234n , context : { ref : { rootSpanId : 'foo' } } } , {
230
+ ...threadInfoWithTimestamp ,
231
+ 'local root span id' : 'foo'
232
+ } )
233
+
234
+ expectLabels ( {
235
+ timestamp : 1234n ,
236
+ context : { ref : { webTags : { 'http.method' : 'GET' , 'http.route' : '/foo/bar' } } }
237
+ } , {
238
+ ...threadInfoWithTimestamp ,
239
+ 'trace endpoint' : 'GET /foo/bar'
240
+ } )
241
+
242
+ expectLabels ( { timestamp : 1234n , context : { ref : { endpoint : 'GET /foo/bar/2' } } } , {
243
+ ...threadInfoWithTimestamp ,
244
+ 'trace endpoint' : 'GET /foo/bar/2'
245
+ } )
246
+
247
+ // All at once
248
+ expectLabels ( {
249
+ timestamp : 1234n ,
250
+ asyncId : 2 ,
251
+ context : {
252
+ ref : {
253
+ spanId : '1234567890' ,
254
+ rootSpanId : '0987654321' ,
255
+ webTags : { 'http.method' : 'GET' , 'http.route' : '/foo/bar' }
256
+ }
257
+ }
258
+ } , {
259
+ ...threadInfoWithTimestamp ,
260
+ 'async id' : 2 ,
261
+ 'span id' : '1234567890' ,
262
+ 'local root span id' : '0987654321' ,
263
+ 'trace endpoint' : 'GET /foo/bar'
264
+ } )
265
+ } )
177
266
} )
0 commit comments