2017-08-10 03:25:28 +02:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
//
|
|
|
|
// mock filesystem
|
|
|
|
//
|
|
|
|
|
|
|
|
bootstrap_go_package {
|
2017-12-22 00:46:01 +01:00
|
|
|
name: "soong-finder-fs",
|
|
|
|
pkgPath: "android/soong/finder/fs",
|
2017-08-10 03:25:28 +02:00
|
|
|
srcs: [
|
|
|
|
"fs.go",
|
Reimplement ioutil.ReadDir with a version that avoids calling lstat
ioutil.ReadDir returns []os.FileInfo, which contains information on
each entry in the directory that is only available by calling
os.Lstat on the entry. Finder only the name and type (regular,
directory or symlink) of the files, which on Linux kernels >= 2.6.4
is available in the return values of syscall.Getdents.
Replace ioutil.ReadDir with a call that uses syscall.Getdents
directly and collects the type information from the result.
Testing with:
rm -f /tmp/db && strace -fc finder -names Android.mk,Android.bp,Blueprints,CleanSpec.mk,TEST_MAPPING -exclude-dirs .git,.repo -prune-files .out-dir,.find-ignore -db /tmp/db .
Before:
7.01 52.688304 63 833398 1 lstat
1.90 14.246644 68 210523 getdents64
1.25 9.370471 90 104286 1 openat
After:
3.48 12.201385 117 104286 1 openat
3.06 10.729138 51 210523 getdents64
1.70 5.951892 57 104283 1 lstat
Pros:
Avoids 729115 calls to lstat.
Cons:
Requires copying ~200 lines of finicky buffer parsing code.
Puts all getdents calls (and possibly fallback lstat calls) onto
a non-blocking file descriptor, which will cause it to block a
thread and not just a goroutine.
Only works on Linux and Darwin.
Bug: 70897635
Test: m checkbuild
Change-Id: Iab9f82c38c8675d0b73b4e90540bb9e4d2ee52c1
2017-12-22 01:44:26 +01:00
|
|
|
"readdir.go",
|
|
|
|
],
|
|
|
|
testSrcs: [
|
|
|
|
"readdir_test.go",
|
2017-08-10 03:25:28 +02:00
|
|
|
],
|
2017-08-10 03:35:15 +02:00
|
|
|
darwin: {
|
|
|
|
srcs: [
|
|
|
|
"fs_darwin.go",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
linux: {
|
|
|
|
srcs: [
|
|
|
|
"fs_linux.go",
|
|
|
|
],
|
|
|
|
},
|
2017-08-10 03:25:28 +02:00
|
|
|
}
|
|
|
|
|