Repository navigation
Expand file tree
/
Copy pathdiff_metrics.py
More file actions
executable file
·75 lines (64 loc) · 1.92 KB
/
Copy pathdiff_metrics.py
File metadata and controls
executable file
·75 lines (64 loc) · 1.92 KB
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
#!/usr/bin/python3
# Copyright (c) 2018-2022 Homa Developers
# SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+
"""
This program reads 2 Homa metrics files (/proc/net/homa_metrics)
and prints out all of the statistics that have changed, in the
same format as the original files.
Usage:
diff_metrics file1 file2
"""
from __future__ import annotations
from glob import glob
from optparse import OptionParser
import math
import os
import re
import string
import sys
# Contains values for all the metrics from the first file. Keys are
# metric names, values are metric values.
metrics = {}
def scan_first(name: str) -> None:
"""
Scan the metrics file given by 'name' and record its metrics.
"""
global metrics
f = open(name)
for line in f:
match = re.match('^([^ ]+) *([0-9]+) *(.*)', line)
if not match:
print("Didn't match: %s\n" % (line))
continue
metrics[match.group(1)] = int(match.group(2))
f.close()
def scan_second(name: str) -> None:
"""
Scan the metrics file given by 'name', compare its metrics to
those that have been recorded, and print an output line with
the difference, if there is any.
"""
global metrics
f = open(name)
for line in f:
match = re.match('^([^ ]+) *([0-9]+) *(.*)', line)
if not match:
print("Didn't match: %s\n" % (line))
continue
name = match.group(1)
value = int(match.group(2))
comment = match.group(3)
if not name in metrics:
print("No metric for %s\n" % (name))
continue
# print("%s: %d %d\n" % (name, metrics[name], value))
diff = value - metrics[name]
if diff == 0:
continue
print("%-22s %15lu %s" % (name, diff, comment))
f.close()
if len(sys.argv) != 3:
print("Usage: %s file file2\n" % sys.argv[0])
exit(1)
scan_first(sys.argv[1])
scan_second(sys.argv[2])