Skip to content

Commit 5e29f02

Browse files
committed
[process-stats-dir] Support --merge-timers to sum across modules.
1 parent 779166d commit 5e29f02

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

utils/jobstats/jobstats.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,56 @@ def to_lnt_test_obj(self, args):
170170
}
171171

172172

173+
AUXPATSTR = (r"(?P<module>[^-]+)-(?P<input>[^-]+)-(?P<triple>[^-]+)" +
174+
r"-(?P<out>[^-]*)-(?P<opt>[^-]+)")
175+
AUXPAT = re.compile(AUXPATSTR)
176+
177+
TIMERPATSTR = (r"time\.swift-(?P<jobkind>\w+)\." + AUXPATSTR +
178+
"\.(?P<timerkind>\w+)$")
179+
TIMERPAT = re.compile(TIMERPATSTR)
180+
181+
FILEPATSTR = (r"^stats-(?P<start>\d+)-swift-(?P<kind>\w+)-" +
182+
AUXPATSTR +
183+
r"-(?P<pid>\d+)(-.*)?.json$")
184+
FILEPAT = re.compile(FILEPATSTR)
185+
186+
187+
def match_auxpat(s):
188+
m = AUXPAT.match(s)
189+
if m is not None:
190+
return m.groupdict()
191+
else:
192+
return None
193+
194+
195+
def match_timerpat(s):
196+
m = TIMERPAT.match(s)
197+
if m is not None:
198+
return m.groupdict()
199+
else:
200+
return None
201+
202+
203+
def match_filepat(s):
204+
m = FILEPAT.match(s)
205+
if m is not None:
206+
return m.groupdict()
207+
else:
208+
return None
209+
210+
173211
def load_stats_dir(path, select_module=[], select_stat=[],
174-
exclude_timers=False, **kwargs):
212+
exclude_timers=False, merge_timers=False, **kwargs):
175213
"""Loads all stats-files found in path into a list of JobStats objects"""
176214
jobstats = []
177-
auxpat = (r"(?P<module>[^-]+)-(?P<input>[^-]+)-(?P<triple>[^-]+)" +
178-
r"-(?P<out>[^-]*)-(?P<opt>[^-]+)")
179-
fpat = (r"^stats-(?P<start>\d+)-swift-(?P<kind>\w+)-" +
180-
auxpat +
181-
r"-(?P<pid>\d+)(-.*)?.json$")
182-
fre = re.compile(fpat)
183215
sre = re.compile('.*' if len(select_stat) == 0 else
184216
'|'.join(select_stat))
185217
for root, dirs, files in os.walk(path):
186218
for f in files:
187-
m = fre.match(f)
188-
if not m:
219+
mg = match_filepat(f)
220+
if not mg:
189221
continue
190222
# NB: "pid" in fpat is a random number, not unix pid.
191-
mg = m.groupdict()
192223
jobkind = mg['kind']
193224
jobid = int(mg['pid'])
194225
start_usec = int(mg['start'])
@@ -200,21 +231,22 @@ def load_stats_dir(path, select_module=[], select_stat=[],
200231
with open(os.path.join(root, f)) as fp:
201232
j = json.load(fp)
202233
dur_usec = 1
203-
patstr = (r"time\.swift-" + jobkind + r"\." + auxpat +
204-
r"\.wall$")
205-
pat = re.compile(patstr)
206234
stats = dict()
207235
for (k, v) in j.items():
208236
if sre.search(k) is None:
209237
continue
210-
if k.startswith("time."):
238+
if k.startswith('time.') and exclude_timers:
239+
continue
240+
tm = match_timerpat(k)
241+
if tm:
211242
v = int(1000000.0 * float(v))
212-
if exclude_timers:
213-
continue
243+
if tm['jobkind'] == jobkind and \
244+
tm['timerkind'] == 'wall':
245+
dur_usec = v
246+
if merge_timers:
247+
k = "time.swift-%s.%s" % (tm['jobkind'],
248+
tm['timerkind'])
214249
stats[k] = v
215-
tm = re.match(pat, k)
216-
if tm:
217-
dur_usec = v
218250

219251
e = JobStats(jobkind=jobkind, jobid=jobid,
220252
module=module, start_usec=start_usec,

utils/process-stats-dir.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ def main():
528528
default="sum",
529529
type=str,
530530
help="Merge identical metrics by (sum|min|max)")
531+
parser.add_argument("--merge-timers",
532+
default=False,
533+
action="store_true",
534+
help="Merge timers across modules/targets/etc.")
531535
parser.add_argument("--markdown",
532536
default=False,
533537
action="store_true",

0 commit comments

Comments
 (0)