1313import subprocess
1414import sys
1515import time
16- from dataclasses import dataclass
16+ from dataclasses import dataclass , replace
1717from typing import Callable
1818
1919
@@ -122,16 +122,10 @@ def parse_args() -> argparse.Namespace:
122122 default = None ,
123123 help = "Optional directory placeholder used to label one rsloop Tracy run per workload before measured runs" ,
124124 )
125- parser .add_argument (
126- "--profile-frequency" ,
127- type = int ,
128- default = 999 ,
129- help = "Compatibility option retained from the old pprof profiler; ignored by Tracy" ,
130- )
131125 parser .add_argument ("--child" , action = "store_true" , help = argparse .SUPPRESS )
132126 parser .add_argument ("--loop" , choices = LOOP_CHOICES , help = argparse .SUPPRESS )
133127 parser .add_argument ("--workload" , choices = WORKLOAD_CHOICES , help = argparse .SUPPRESS )
134- parser .add_argument ("--profile-output " , help = argparse .SUPPRESS )
128+ parser .add_argument ("--profile-label " , help = argparse .SUPPRESS )
135129 return parser .parse_args ()
136130
137131
@@ -160,8 +154,6 @@ def validate_args(args: argparse.Namespace) -> None:
160154 raise SystemExit ("--tcp-roundtrips must be > 0" )
161155 if args .payload_size <= 0 :
162156 raise SystemExit ("--payload-size must be > 0" )
163- if args .profile_frequency <= 0 :
164- raise SystemExit ("--profile-frequency must be > 0" )
165157
166158
167159def env_flag (name : str ) -> bool :
@@ -421,12 +413,12 @@ def child_main(args: argparse.Namespace) -> int:
421413 else : # pragma: no cover - parser guards this
422414 raise AssertionError (f"unsupported workload: { args .workload } " )
423415
424- profile_requested = args .profile_output is not None or (
416+ profile_requested = args .profile_label is not None or (
425417 args .loop == "rsloop" and env_flag (RSLOOP_PROFILE_ENV )
426418 )
427419 loop_factory_for (args .loop )
428420 baseline_rss_bytes = get_current_rss_bytes ()
429- if profile_requested and not args .profile_output :
421+ if profile_requested and not args .profile_label :
430422 print (
431423 f"[profile] Tracy enabled via { RSLOOP_PROFILE_ENV } =1 for { args .loop } /{ args .workload } " ,
432424 flush = True ,
@@ -435,29 +427,23 @@ def child_main(args: argparse.Namespace) -> int:
435427 if args .loop != "rsloop" :
436428 raise RuntimeError ("profiling is only supported for rsloop" )
437429 rsloop = importlib .import_module ("rsloop" )
438- with rsloop .profile (args .profile_output , frequency = args .profile_frequency ):
430+ if args .profile_label :
431+ print (f"[profile] Tracy session label: { args .profile_label } " , flush = True )
432+ with rsloop .profile ():
439433 result = run_with_loop (args .loop , coro )
440434 else :
441435 result = run_with_loop (args .loop , coro )
442436 finally :
443437 gc .enable ()
444438
445- result = ChildResult (
446- loop = result .loop ,
447- workload = result .workload ,
448- seconds = result .seconds ,
449- operations = result .operations ,
439+ result = replace (
440+ result ,
450441 baseline_rss_bytes = baseline_rss_bytes ,
451442 peak_rss_bytes = get_peak_rss_bytes (),
452443 peak_rss_delta_bytes = 0 ,
453444 )
454- result = ChildResult (
455- loop = result .loop ,
456- workload = result .workload ,
457- seconds = result .seconds ,
458- operations = result .operations ,
459- baseline_rss_bytes = result .baseline_rss_bytes ,
460- peak_rss_bytes = result .peak_rss_bytes ,
445+ result = replace (
446+ result ,
461447 peak_rss_delta_bytes = max (0 , result .peak_rss_bytes - result .baseline_rss_bytes ),
462448 )
463449
@@ -484,7 +470,7 @@ def run_child(
484470 workload : str ,
485471 args : argparse .Namespace ,
486472 * ,
487- profile_output : str | None = None ,
473+ profile_label : str | None = None ,
488474) -> ChildResult :
489475 cmd = [
490476 sys .executable ,
@@ -504,11 +490,9 @@ def run_child(
504490 str (args .tcp_roundtrips ),
505491 "--payload-size" ,
506492 str (args .payload_size ),
507- "--profile-frequency" ,
508- str (args .profile_frequency ),
509493 ]
510- if profile_output is not None :
511- cmd .extend (["--profile-output " , profile_output ])
494+ if profile_label is not None :
495+ cmd .extend (["--profile-label " , profile_label ])
512496 env = os .environ .copy ()
513497 if loop_name == "rsloop" :
514498 env ["RSLOOP_USE_FAST_STREAMS" ] = "1" if args .rsloop_fast_streams else "0"
@@ -662,16 +646,14 @@ def parent_main(args: argparse.Namespace) -> int:
662646 print (f"Running { workload } on { loop_name } ..." )
663647 if profile_rsloop_dir and loop_name == "rsloop" :
664648 os .makedirs (profile_rsloop_dir , exist_ok = True )
665- profile_output = os .path .join (
666- profile_rsloop_dir , f"rsloop-{ workload } .svg"
667- )
668- print (f" starting Tracy session labeled { profile_output } " )
649+ profile_label = os .path .join (profile_rsloop_dir , f"rsloop-{ workload } " )
650+ print (f" starting Tracy session labeled { profile_label } " )
669651 run_child (
670652 script_path ,
671653 loop_name ,
672654 workload ,
673655 args ,
674- profile_output = profile_output ,
656+ profile_label = profile_label ,
675657 )
676658 for _ in range (args .warmups ):
677659 run_child (script_path , loop_name , workload , args )
0 commit comments