in _damon_result.py [0:0]
def perf_script_to_damon_result(file_path, f, max_secs):
result = None
nr_read_regions = 0
parse_start_time = None
if not f:
f = open(file_path, 'r')
for line in f:
line = line.strip()
'''
example line is as below:
kdamond.0 4452 [000] 82877.315633: damon:damon_aggregated: \
target_id=18446623435582458880 nr_regions=17 \
140731667070976-140731668037632: 0 3
Note that the last field is not in the mainline but a patch[1] for it
is posted.
[1] https://lore.kernel.org/linux-mm/df8d52f1fb2f353a62ff34dc09fe99e32ca1f63f.1636610337.git.xhao@linux.alibaba.com/
'''
fields = line.strip().split()
if not len(fields) in [9, 10]:
continue
if fields[4] != 'damon:damon_aggregated:':
continue
end_time = int(float(fields[3][:-1]) * 1000000000)
if not result:
result = DAMONResult()
if parse_start_time == None:
parse_start_time = end_time
elif max_secs != None and (
end_time - parse_start_time > max_secs * 1000000000):
# reverse seek of text file is not supported, we simply remove
# over-read line.
break
target_id = int(fields[5].split('=')[1])
if not target_id in result.target_snapshots:
result.target_snapshots[target_id] = []
target_snapshots = result.target_snapshots[target_id]
if len(target_snapshots) == 0:
start_time = None
else:
start_time = target_snapshots[-1].end_time
nr_regions = int(fields[6].split('=')[1])
addrs = [int(x) for x in fields[7][:-1].split('-')]
nr_accesses = int(fields[8])
if nr_read_regions == 0:
snapshot = DAMONSnapshot(start_time, end_time, target_id)
target_snapshots.append(snapshot)
snapshot = target_snapshots[-1]
snapshot.regions.append(DAMONRegion(addrs[0], addrs[1], nr_accesses))
nr_read_regions += 1
if nr_read_regions == nr_regions:
nr_read_regions = 0
if max_secs == None:
f.close()
return result, f