From 9a6ae91128fa53b427f2da9765f042faed5533a6 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 19 Oct 2020 16:21:10 +0100 Subject: [PATCH] [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 --- llvm/utils/lit/lit/LitConfig.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py index 58011b5..92a4fce 100644 --- a/llvm/utils/lit/lit/LitConfig.py +++ b/llvm/utils/lit/lit/LitConfig.py @@ -165,11 +165,10 @@ class LitConfig(object): 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: -- 2.7.4