[cfe-dev] FileManager re-factor
Chris Lattner
clattner at apple.com
Tue Dec 23 15:06:28 PST 2008
On Dec 23, 2008, at 2:56 PM, Chris Lattner wrote:
> There are two things wrong with this:
>
> 1. We're doing a stat followed by an open. We should just do an open
> and on failure, continue the search. If the open succeeded and we
> need size info etc, clang should do an fstat on the file descriptor.
>
> 2. We end up "checking" some directories many times. For example,
> Cocoa.h checks /Users/sabre/llvm/Debug/Headers/ 82 times for files in
> my example, and only succeeds 5 times. It would be better to have
> DirectoryEntry get the file/dir contents of the directory after some
> number of queries using 'getdirentries'. This would save the repeated
> negative hits to a directory.
>
> The first one is probably pretty easy, the second one is more
> involved. Both should only be done with careful attention to measured
> performance.
Ah, here's another interesting thing we're doing wrong. Printing out
the path to 'access' shows we also call 'access' unnecessarily for
framework lookup (this is a lookup of CarbonCore/ConditionalMacros.h):
stat:entry /Users/sabre/llvm/Debug/Headers/CarbonCore
stat:entry /usr/local/include/CarbonCore
stat:entry /usr/lib/gcc/i686-apple-darwin9/4.0.1/include/
CarbonCore
stat:entry /usr/lib/gcc/powerpc-apple-darwin9/4.0.1/include/
CarbonCore
stat:entry /usr/include/CarbonCore
access:entry /System/Library/Frameworks/CarbonCore.framework/
access:entry /Library/Frameworks/CarbonCore.framework/
stat:entry /System/Library/Frameworks/CoreServices.framework/
Frameworks/CarbonCore.framework/
stat:entry /System/Library/Frameworks/CoreServices.framework/
Frameworks/CarbonCore.framework/Headers
stat:entry /System/Library/Frameworks/CoreServices.framework/
Frameworks/CarbonCore.framework/Headers/ConditionalMacros.h
open_nocancel:entry /System/Library/Frameworks/CoreServices.framework/
Frameworks/CarbonCore.framework/Headers/ConditionalMacros.h
I don't see any reason to call 'access' on /S/L/F/
CarbonCore.framework/ and /L/F/CarbonCore.framework if we're about to
stat something underneath it.
Here's the dtrace command I used:
dtrace -n 'syscall:::entry /execname == "clang"/{ printf("%x %x",
arg0, arg1); } syscall::stat:entry /execname == "clang"/{ print"%s",
(copyinstr(arg0))); } syscall::open_nocancel:entry /execname ==
"clang"/{ printf("%s", copyinstr(arg0)); } syscall::access:entry /
execname == "clang"/{ printf("%s", copyinstr(arg0)); }' | & tee out.log
-Chris
More information about the cfe-dev
mailing list