Skip to content

Commit edd3766

Browse files
author
wangqing
committed
btrfs_stats.py: Precompiled regular expressions improve performance
Signed-off-by: wangqing <[email protected]>
1 parent ef8c077 commit edd3766

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

btrfs_stats.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from prometheus_client import CollectorRegistry, Gauge, generate_latest
1313

1414

15+
DEVICE_PATTERN = re.compile(r"^\[([^\]]+)\]\.(\S+)\s+(\d+)$", re.MULTILINE)
16+
1517
def get_btrfs_mount_points():
1618
"""List all btrfs mount points.
1719
@@ -47,7 +49,7 @@ def get_btrfs_errors(mountpoint):
4749
continue
4850
# Sample line:
4951
# [/dev/vdb1].flush_io_errs 0
50-
m = re.search(r"^\[([^\]]+)\]\.(\S+)\s+(\d+)$", line.decode("utf-8"))
52+
m = DEVICE_PATTERN.match(line.decode("utf-8"))
5153
if not m:
5254
raise RuntimeError("unexpected output from btrfs: '%s'" % line)
5355
yield m.group(1), m.group(2), int(m.group(3))

0 commit comments

Comments
 (0)