Skip to content

Commit 052f919

Browse files
Rss ladder warn (#127)
* Added(rss-ladder): warning about using few queues on same cpu. #113 * Added(rss-ladder): colorized output #117 * Added(rss-ladder): automatic socket detection #123 * Fixed(autorps): explicit passing --socket 0 didn't work and called socket_detection logic. * Fixed: reorder tests by time they take because they should fail as soon as possible. * Added(rss-ladder): docstrings everywhere * Changes(pylint): disabled C0111. * Fixed: pylint violations.
1 parent 545eb57 commit 052f919

File tree

17 files changed

+115
-59
lines changed

17 files changed

+115
-59
lines changed

.pylintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[FORMAT]
2+
# why: because checks should be consistent with default pycharm settings
23
max-line-length=120
4+
5+
[MESSAGES CONTROL]
6+
# why: because I think module/class docstrings are generally useless, naming should be the documentation
7+
disable=C0111

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
test:
2+
pytest netutils_linux_*/
3+
./tests/utils_runnable
24
./tests/rss-ladder-test
35
./tests/server-info-show
46
./tests/link_rate_units.sh
5-
./tests/utils_runnable
6-
pytest netutils_linux_*/
77

88
env:
99
rm -rf env

netutils_linux_hardware/assessor_math.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import math
66

77

8-
def round_(x, d=0):
9-
p = 10 ** d
10-
return float(math.floor((x * p) + math.copysign(0.5, x))) / p
8+
def round_(value, precision=0):
9+
"""
10+
:param value: float value
11+
:param precision: how much digits after ',' we need
12+
:return: rounded float value
13+
"""
14+
precision = 10 ** precision
15+
return float(math.floor((value * precision) + math.copysign(0.5, value))) / precision
1116

1217

1318
def extract(dictionary, key_sequence):
@@ -25,9 +30,9 @@ def any2int(value):
2530
elif value is None:
2631
return 0
2732
elif isinstance(value, str):
28-
v = re.sub(r'[^0-9]', '', value)
29-
if v.isdigit():
30-
return int(v)
33+
value = re.sub(r'[^0-9]', '', value)
34+
if value.isdigit():
35+
return int(value)
3136
elif isinstance(value, float):
3237
return int(value)
3338
return 0

netutils_linux_hardware/grade_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def test_grade_str(self):
3333
"Dlink": 1,
3434
"Realtek": 1,
3535
}
36-
for k, v in iteritems(expected):
37-
self.assertEqual(Grade.str(k, good, bad), v)
36+
for k, value in iteritems(expected):
37+
self.assertEqual(Grade.str(k, good, bad), value)
3838

3939
def test_grade_fact(self):
4040
self.assertEqual(Grade.fact(None, True), 1)
41-
self.assertEqual(Grade.fact(None, False), 10)
41+
self.assertEqual(Grade.fact(None), 10)
4242
self.assertEqual(Grade.fact("Anything", True), 10)
43-
self.assertEqual(Grade.fact("Anything", False), 1)
43+
self.assertEqual(Grade.fact("Anything"), 1)
4444
self.assertEqual(Grade.fact(15, True), 10)
45-
self.assertEqual(Grade.fact(15, False), 1)
45+
self.assertEqual(Grade.fact(15), 1)
4646
self.assertEqual(Grade.fact({'x': 'y'}, True), 10)
4747
self.assertEqual(Grade.fact({}, True), 10)
4848

netutils_linux_monitoring/layout.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88

99
def make_table(header, align_map=None, rows=None):
1010
""" Wrapper for pretty table """
11-
t = PrettyTable()
12-
t.horizontal_char = t.vertical_char = t.junction_char = ' '
13-
t.field_names = header
11+
table = PrettyTable()
12+
table.horizontal_char = table.vertical_char = table.junction_char = ' '
13+
table.field_names = header
1414
if align_map:
1515
for field, align in zip(header, align_map):
16-
t.align[field] = align
16+
table.align[field] = align
1717
if rows:
1818
for row in rows:
19-
if len(row) < len(t.field_names):
19+
if len(row) < len(table.field_names):
2020
continue
2121
try:
22-
t.add_row(row)
22+
table.add_row(row)
2323
except Exception as err:
24-
print_('fields:', t.field_names)
24+
print_('fields:', table.field_names)
2525
print_('row:', row)
2626
print_('rows:', rows)
2727
raise err
28-
return t
28+
return table

netutils_linux_monitoring/link_rate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def devices_list(self):
135135
devices = self.options.devices.split(',')
136136
else:
137137
devices = self.devices_list_regex()
138-
return list(filter(self.devices_list_validate, devices))
138+
return [dev for dev in devices if self.devices_list_validate(dev)]
139139

140140
def post_optparse(self):
141141
""" Asserting and applying parsing options """

netutils_linux_monitoring/numa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def dev_node(self, dev, fake=False):
5858
filename = '/sys/class/net/{0}/device/numa_node'.format(dev)
5959
if not os.path.isfile(filename):
6060
return -1
61-
with open(filename) as fd:
62-
return int(fd.read().strip())
61+
with open(filename) as dev_file:
62+
return int(dev_file.read().strip())
6363

6464
def detect_layouts_fallback(self):
6565
"""
@@ -96,7 +96,7 @@ def detect_layouts(self, lscpu_output=None):
9696
""" Determine NUMA and sockets layout """
9797
stdout = self.detect_layout_lscpu(lscpu_output)
9898
rows = [row for row in stdout.strip().split('\n') if not row.startswith('#')]
99-
layouts = [list(map(any2int, row.split(',')[2:4])) for row in rows]
99+
layouts = [[any2int(value) for value in row.split(',')][2:4] for row in rows]
100100
numa_layout, socket_layout = zip(*layouts)
101101
self.numa_layout = dict(enumerate(numa_layout))
102102
self.socket_layout = dict(enumerate(socket_layout))

netutils_linux_monitoring/softirqs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ def post_optparse(self):
3030
self.numa = Numa(fake=self.options.random)
3131

3232
def parse(self):
33-
with open(self.options.softirqs_file) as fd:
34-
metrics = [line.strip().split(':')
35-
for line in fd.readlines() if ':' in line]
36-
return dict((k, list(map(int, v.strip().split()))) for k, v in metrics)
33+
with open(self.options.softirqs_file) as softirq_file:
34+
metrics = [line.strip().split(':') for line in softirq_file.readlines() if ':' in line]
35+
return dict((k, [int(d) for d in v.strip().split()]) for k, v in metrics)
3736

3837
@staticmethod
3938
def __active_cpu_count__(data):

netutils_linux_monitoring/softnet_stat.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def make_rows(self):
9393
colorize(stat.time_squeeze, self.time_squeeze_warning, self.time_squeeze_error),
9494
colorize(stat.cpu_collision, self.cpu_collision_warning, self.cpu_collision_error),
9595
stat.received_rps
96-
]
97-
for stat in self.repr_source()
98-
]
96+
] for stat in self.repr_source()]
9997

10098
def __repr__(self):
10199
table = make_table(self.make_header(), self.align, list(self.make_rows()))

netutils_linux_tuning/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from netutils_linux_tuning.rx_buffers import RxBuffersIncreaser
2+
from netutils_linux_tuning.rss_ladder import RSSLadder
3+
from netutils_linux_tuning.autorps import AutoRPS
24

3-
__all__ = ['RxBuffersIncreaser']
5+
__all__ = ['RxBuffersIncreaser', 'AutoRPS', 'RSSLadder']

0 commit comments

Comments
 (0)