1#!/usr/bin/env python3 2# SPDX-License-Identifier: GPL-2.0 3 4import subprocess 5import time 6 7import _damon_sysfs 8 9def main(): 10 # access two 10 MiB memory regions, 2 second per each 11 sz_region = 10 * 1024 * 1024 12 proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000']) 13 kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( 14 contexts=[_damon_sysfs.DamonCtx( 15 ops='vaddr', 16 targets=[_damon_sysfs.DamonTarget(pid=proc.pid)], 17 schemes=[_damon_sysfs.Damos( 18 access_pattern=_damon_sysfs.DamosAccessPattern( 19 # >= 25% access rate, >= 200ms age 20 nr_accesses=[5, 20], age=[2, 2**64 - 1]))] # schemes 21 )] # contexts 22 )]) # kdamonds 23 24 err = kdamonds.start() 25 if err != None: 26 print('kdamond start failed: %s' % err) 27 exit(1) 28 29 wss_collected = [] 30 while proc.poll() == None: 31 time.sleep(0.1) 32 err = kdamonds.kdamonds[0].update_schemes_tried_bytes() 33 if err != None: 34 print('tried bytes update failed: %s' % err) 35 exit(1) 36 37 wss_collected.append( 38 kdamonds.kdamonds[0].contexts[0].schemes[0].tried_bytes) 39 40 wss_collected.sort() 41 acceptable_error_rate = 0.2 42 for percentile in [50, 75]: 43 sample = wss_collected[int(len(wss_collected) * percentile / 100)] 44 error_rate = abs(sample - sz_region) / sz_region 45 print('%d-th percentile (%d) error %f' % 46 (percentile, sample, error_rate)) 47 if error_rate > acceptable_error_rate: 48 print('the error rate is not acceptable (> %f)' % 49 acceptable_error_rate) 50 print('samples are as below') 51 print('\n'.join(['%d' % wss for wss in wss_collected])) 52 exit(1) 53 54if __name__ == '__main__': 55 main() 56