@@ -48,6 +48,13 @@ def _extract_bootstrap(html):
4848 return json .loads (html [start :end ])
4949
5050
51+ def _extract_named_bootstrap (html , script_id ):
52+ marker = f'<script id="{ script_id } " type="application/json">'
53+ start = html .index (marker ) + len (marker )
54+ end = html .index ("</script>" , start )
55+ return json .loads (html [start :end ])
56+
57+
5158class TestExtractFrames :
5259 def test_filters_unwind_frames (self ):
5360 frames = [
@@ -281,6 +288,65 @@ def test_uses_fixed_layout_instead_of_splitter(self, snapshot):
281288 assert "window.addEventListener('resize', applyPaneLayout);" in html
282289 assert 'id="splitter"' not in html
283290
291+ def test_uses_requested_devices_per_side (self ):
292+ snapshot_left = {
293+ "device_traces" : [
294+ [_make_event ("alloc" , 0x1000 , 128 , time_us = 1 , filename = "left.py" , name = "left" )]
295+ ],
296+ "segments" : [
297+ {
298+ "device" : 0 ,
299+ "stream" : 0 ,
300+ "address" : 0x1000 ,
301+ "blocks" : [
302+ {
303+ "state" : "active_allocated" ,
304+ "size" : 64 ,
305+ "addr" : 0x1000 ,
306+ "frames" : [{"filename" : "left.py" , "name" : "seed" , "line" : 1 }],
307+ }
308+ ],
309+ }
310+ ],
311+ "allocator_settings" : {},
312+ }
313+ snapshot_right = {
314+ "device_traces" : [
315+ [],
316+ [_make_event ("alloc" , 0x2000 , 256 , time_us = 2 , filename = "right.py" , name = "right" )],
317+ ],
318+ "segments" : [
319+ {
320+ "device" : 1 ,
321+ "stream" : 0 ,
322+ "address" : 0x2000 ,
323+ "blocks" : [
324+ {
325+ "state" : "active_allocated" ,
326+ "size" : 128 ,
327+ "addr" : 0x2000 ,
328+ "frames" : [{"filename" : "right.py" , "name" : "seed" , "line" : 1 }],
329+ }
330+ ],
331+ }
332+ ],
333+ "allocator_settings" : {},
334+ }
335+ html = generate_memory_comparison_html (
336+ snapshot_left ,
337+ snapshot_right ,
338+ device_left = 0 ,
339+ device_right = 1 ,
340+ title_left = "Rank 0" ,
341+ title_right = "Rank 1" ,
342+ )
343+ bootstrap_left = _extract_named_bootstrap (html , "bootstrap-left" )
344+ bootstrap_right = _extract_named_bootstrap (html , "bootstrap-right" )
345+ assert bootstrap_left ["meta" ]["device" ] == 0
346+ assert bootstrap_right ["meta" ]["device" ] == 1
347+ assert bootstrap_left ["meta" ]["num_allocs" ] == 2
348+ assert bootstrap_right ["meta" ]["num_allocs" ] == 2
349+
284350
285351class TestNeverFreedAllocations :
286352 def test_never_freed_end_at_max_ts (self ):
0 commit comments