[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <238cbe14607880e99d7e6cbaa3f046dfaf96dcd2.1738020236.git.mchehab+huawei@kernel.org>
Date: Tue, 28 Jan 2025 01:06:05 +0100
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Linux Doc Mailing List <linux-doc@...r.kernel.org>,
Jonathan Corbet <corbet@....net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
"Mauro Carvalho Chehab" <mchehab+huawei@...nel.org>,
linux-kernel@...r.kernel.org
Subject: [RFC v2 16/38] scripts/get_abi.py: optimize parse_abi() function
Instead of using glob, use a recursive function to parse all files.
Such change reduces the total excecution time by 15% with my SSD disks.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
---
scripts/get_abi.py | 57 ++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 19 deletions(-)
diff --git a/scripts/get_abi.py b/scripts/get_abi.py
index 93a23cf30ea1..73613fb29c1c 100755
--- a/scripts/get_abi.py
+++ b/scripts/get_abi.py
@@ -13,7 +13,6 @@ import os
import re
import sys
-from glob import glob
from pprint import pformat
from random import randrange, seed
@@ -59,7 +58,11 @@ class AbiParser:
self.file_refs = {}
self.what_refs = {}
+ # Ignore files that contain such suffixes
+ self.ignore_suffixes = (".rej", ".org", ".orig", ".bak", "~")
+
# Regular expressions used on parser
+ self.re_abi_dir = re.compile(r"(.*)" + ABI_DIR)
self.re_tag = re.compile(r"(\S+)(:\s*)(.*)", re.I)
self.re_valid = re.compile(self.TAGS)
self.re_start_spc = re.compile(r"(\s*)(\S.*)")
@@ -335,26 +338,42 @@ class AbiParser:
for w in fdata.what:
self.add_symbol(what=w, fname=fname, xref=fdata.key)
- def parse_abi(self):
+ def _parse_abi(self, root=None):
+ """Internal function to parse documentation ABI recursively"""
+
+ if not root:
+ root = self.directory
+
+ with os.scandir(root) as obj:
+ for entry in obj:
+ name = os.path.join(root, entry.name)
+
+ if entry.is_dir():
+ self.parse_abi(name)
+ continue
+
+ if not entry.is_file():
+ continue
+
+ basename = os.path.basename(name)
+
+ if basename == "README":
+ continue
+
+ if basename.startswith("."):
+ continue
+
+ if basename.endswith(self.ignore_suffixes):
+ continue
+
+ path = self.re_abi_dir.sub("", os.path.dirname(name))
+
+ self.parse_file(name, path, basename)
+
+ def parse_abi(self, root=None):
"""Parse documentation ABI"""
- ignore_suffixes = ("rej", "org", "orig", "bak", "~")
- re_abi = re.compile(r".*" + ABI_DIR)
-
- for fname in glob(os.path.join(self.directory, "**"), recursive=True):
- if os.path.isdir(fname):
- continue
-
- basename = os.path.basename(fname)
-
- if basename == "README":
- continue
- if basename.startswith(".") or basename.endswith(ignore_suffixes):
- continue
-
- path = re_abi.sub("", os.path.dirname(fname))
-
- self.parse_file(fname, path, basename)
+ self._parse_abi(root)
if self.debug & DEBUG_DUMP_ABI_STRUCTS:
self.log.debug(pformat(self.data))
--
2.48.1
Powered by blists - more mailing lists