1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
import json
import os
import subprocess
import _damon_sysfs
def dump_damon_status_dict(pid):
file_dir = os.path.dirname(os.path.abspath(__file__))
dump_script = os.path.join(file_dir, 'drgn_dump_damon_status.py')
rc = subprocess.call(['drgn', dump_script, pid, 'damon_dump_output'],
stderr=subprocess.DEVNULL)
if rc != 0:
return None, 'drgn fail'
try:
with open('damon_dump_output', 'r') as f:
return json.load(f), None
except Exception as e:
return None, 'json.load fail (%s)' % e
def fail(expectation, status):
print('unexpected %s' % expectation)
print(json.dumps(status, indent=4))
exit(1)
def main():
kdamonds = _damon_sysfs.Kdamonds(
[_damon_sysfs.Kdamond(
contexts=[_damon_sysfs.DamonCtx(
targets=[_damon_sysfs.DamonTarget(pid=-1)],
schemes=[_damon_sysfs.Damos()],
)])])
err = kdamonds.start()
if err is not None:
print('kdamond start failed: %s' % err)
exit(1)
status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid)
if err is not None:
print(err)
exit(1)
if len(status['contexts']) != 1:
fail('number of contexts', status)
ctx = status['contexts'][0]
attrs = ctx['attrs']
if attrs['sample_interval'] != 5000:
fail('sample interval', status)
if attrs['aggr_interval'] != 100000:
fail('aggr interval', status)
if attrs['ops_update_interval'] != 1000000:
fail('ops updte interval', status)
if attrs['intervals_goal'] != {
'access_bp': 0, 'aggrs': 0,
'min_sample_us': 0, 'max_sample_us': 0}:
fail('intervals goal')
if attrs['min_nr_regions'] != 10:
fail('min_nr_regions')
if attrs['max_nr_regions'] != 1000:
fail('max_nr_regions')
if ctx['adaptive_targets'] != [
{ 'pid': 0, 'nr_regions': 0, 'regions_list': []}]:
fail('adaptive targets', status)
if len(ctx['schemes']) != 1:
fail('number of schemes', status)
scheme = ctx['schemes'][0]
if scheme['pattern'] != {
'min_sz_region': 0,
'max_sz_region': 2**64 - 1,
'min_nr_accesses': 0,
'max_nr_accesses': 2**32 - 1,
'min_age_region': 0,
'max_age_region': 2**32 - 1,
}:
fail('damos pattern', status)
if scheme['action'] != 9: # stat
fail('damos action', status)
if scheme['apply_interval_us'] != 0:
fail('damos apply interval', status)
if scheme['target_nid'] != -1:
fail('damos target nid', status)
if scheme['quota'] != {
'reset_interval': 0,
'ms': 0,
'sz': 0,
'goals': [],
'esz': 0,
'weight_sz': 0,
'weight_nr_accesses': 0,
'weight_age': 0,
}:
fail('damos quota', status)
if scheme['wmarks'] != {
'metric': 0,
'interval': 0,
'high': 0,
'mid': 0,
'low': 0,
}:
fail('damos wmarks', status)
kdamonds.stop()
if __name__ == '__main__':
main()
|