@@ -11,7 +11,13 @@ def makeAnalyzeParser(add_help: bool = True):
1111 Parallel solvers show events of the primary rank next to the secondary ranks spending the least and most time in advance of preCICE.
1212 """
1313 analyze = argparse .ArgumentParser (description = analyze_help , add_help = add_help )
14- analyze .add_argument ("participant" , type = str , help = "The participant to analyze" )
14+ analyze .add_argument (
15+ "participant" ,
16+ type = str ,
17+ nargs = "?" ,
18+ default = None ,
19+ help = "The participant to analyze. If omitted, all participants are analyzed." ,
20+ )
1521 addInputArgument (analyze )
1622 addUnitArgument (analyze )
1723 analyze .add_argument (
@@ -116,26 +122,10 @@ def runAnalyze(ns):
116122 )
117123
118124
119- def analyzeCommand (profilingfile , participant , event , outfile = None , unit = "us" ):
120- # Translate display name "total" back to internal name "_GLOBAL"
121- if event == "total" :
122- event = "_GLOBAL"
123-
124- run = Run (profilingfile )
125-
126- participants = run .participants ()
127- assert (
128- participant in participants
129- ), f"Given participant { participant } doesn't exist. Known: " + ", " .join (
130- participants
131- )
132-
125+ def computeAnalysis (run , participant , event , unit = "us" ):
126+ """Compute the analysis DataFrame for a single participant."""
133127 df = run .toDataFrame (participant = participant )
134128
135- print (f"Output timing are in { unit } ." )
136-
137- # Filter by participant
138- # Convert duration to requested unit
139129 dur_factor = 1000 * ns_to_unit_factor (unit )
140130 df = (
141131 df .filter (pl .col ("participant" ) == participant )
@@ -213,6 +203,39 @@ def analyzeCommand(profilingfile, participant, event, outfile=None, unit="us"):
213203 .collect ()
214204 )
215205
206+ return joined
207+
208+
209+ def analyzeCommand (profilingfile , participant , event , outfile = None , unit = "us" ):
210+ # Translate display name "total" back to internal name "_GLOBAL"
211+ if event == "total" :
212+ event = "_GLOBAL"
213+
214+ run = Run (profilingfile )
215+ all_participants = run .participants ()
216+
217+ assert (
218+ participant is None or participant in all_participants
219+ ), f"Given participant { participant } doesn't exist. Known: " + ", " .join (
220+ all_participants
221+ )
222+
223+ print (f"Output timings are in { unit } ." )
224+
225+ if participant is None :
226+ if outfile is not None :
227+ print (
228+ "Error: --output requires a specific participant. "
229+ "Use `analyze <participant> --output <file>`." ,
230+ file = sys .stderr ,
231+ )
232+ return 1
233+ for p in all_participants :
234+ print (f"\n === Participant: { p } ===" )
235+ printWide (computeAnalysis (run , p , event , unit ))
236+ return 0
237+
238+ joined = computeAnalysis (run , participant , event , unit )
216239 printWide (joined )
217240
218241 if outfile :
0 commit comments