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

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 06:44:23 PDT 2020


arichardson created this revision.
arichardson added reviewers: ldionne, yln.
Herald added subscribers: llvm-commits, dexonsmith, delcypher.
Herald added a project: LLVM.
arichardson requested review of this revision.

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.normpath 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89186

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


Index: llvm/utils/lit/lit/LitConfig.py
===================================================================
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -178,11 +178,10 @@
         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.normpath(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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89186.297410.patch
Type: text/x-patch
Size: 881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201010/dfc98191/attachment.bin>


More information about the llvm-commits mailing list