@@ -309,45 +309,21 @@ class GeckoCollector(StackTraceCollector):
309
309
310
310
def __init__ (self , * args , ** kwargs ):
311
311
super ().__init__ (* args , ** kwargs )
312
- self .samples = []
313
- self .start_time = None
314
312
self ._string_table = StringTable ()
315
- self ._func_intern = {}
313
+ self ._builder = GeckoBuilder ( self . _string_table , time . time ())
316
314
317
315
def process_frames (self , frames , thread_id ):
318
316
current_time = time .time ()
319
- if self .start_time is None :
320
- self .start_time = current_time
321
-
322
- # Intern frames to avoid storing duplicates
323
- interned_frames = [
324
- self ._func_intern .setdefault (frame , frame ) for frame in frames
325
- ]
326
-
327
- self .samples .append ({
328
- 'timestamp' : current_time ,
329
- 'thread_id' : thread_id ,
330
- 'frames' : interned_frames
331
- })
317
+ self ._builder .add_sample (frames , current_time , thread_id )
332
318
333
319
def export (self , filename ):
334
- if not self .samples :
320
+ if not self ._builder . threads_data :
335
321
print ("No samples to export" )
336
322
return
337
323
338
- builder = GeckoBuilder (self ._string_table , self .start_time )
339
-
340
- for sample in self .samples :
341
- builder .add_sample (
342
- sample ['frames' ],
343
- sample ['timestamp' ],
344
- sample ['thread_id' ]
345
- )
346
-
347
- profile = builder .build_profile ()
324
+ profile = self ._builder .build_profile ()
348
325
349
326
with open (filename , 'w' , encoding = 'utf-8' ) as file :
350
327
json .dump (profile , file , indent = 2 )
351
328
352
- thread_count = len (set (sample ['thread_id' ] for sample in self .samples ))
353
- print (f"Gecko profile exported: { filename } ({ thread_count } threads, { len (self .samples )} samples)" )
329
+ print (f"Gecko profile exported: { filename } " )
0 commit comments