[llvm] 9a6ae91 - [lit] Avoid calling realpath() for every printed message

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 08:22:16 PDT 2020


Author: Alex Richardson
Date: 2020-10-19T16:21:34+01:00
New Revision: 9a6ae91128fa53b427f2da9765f042faed5533a6

URL: https://github.com/llvm/llvm-project/commit/9a6ae91128fa53b427f2da9765f042faed5533a6
DIFF: https://github.com/llvm/llvm-project/commit/9a6ae91128fa53b427f2da9765f042faed5533a6.diff

LOG: [lit] Avoid calling realpath() for every printed message

I did some profiling of lit while trying to optimize the libc++ test
startup for remote hosts and it turns out that there is a realpath() call
for every message printed and this shows up in the profile.
The inspect.getframeinfo() function calls realpath() internally and
moreover we don't need most of the other information returned from it.
This patch uses inspect.getsourcefile() and os.path.abspath() to remove
../ from the path instead. Not resolving symlinks reduces the startup time
for running a single test with lit by about 50ms for me.

Reviewed By: ldionne, yln
Differential Revision: https://reviews.llvm.org/D89186

Added: 
    

Modified: 
    llvm/utils/lit/lit/LitConfig.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py
index 58011b5986bf..92a4fcee2845 100644
--- a/llvm/utils/lit/lit/LitConfig.py
+++ b/llvm/utils/lit/lit/LitConfig.py
@@ -165,11 +165,10 @@ def _write_message(self, kind, message):
         f = inspect.currentframe()
         # Step out of _write_message, and then out of wrapper.
         f = f.f_back.f_back
-        file,line,_,_,_ = inspect.getframeinfo(f)
-        location = '%s:%d' % (file, line)
-
-        sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
-                                               kind, message))
+        file = os.path.abspath(inspect.getsourcefile(f))
+        line = inspect.getlineno(f)
+        sys.stderr.write('%s: %s:%d: %s: %s\n' % (self.progname, file, line,
+                                                  kind, message))
 
     def note(self, message):
         if not self.quiet:


        


More information about the llvm-commits mailing list