diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-04-23 16:10:05 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-23 16:10:54 -0700 |
commit | 908edee04f92055a8c53a63d1b8d57ffe56aa682 (patch) | |
tree | 18d9e67a6d603cd332164056305d06a094e7843c /pkg | |
parent | df21460cfdf589299e98171407741e3c253debe4 (diff) |
Replace os.File with fd.FD in fsgofer
os.NewFile() accounts for 38% of CPU time in localFile.Walk().
This change switchs to use fd.FD which is much cheaper to create.
Now, fd.New() in localFile.Walk() accounts for only 4%.
PiperOrigin-RevId: 244944983
Change-Id: Ic892df96cf2633e78ad379227a213cb93ee0ca46
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/fd/fd.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/fd/fd.go b/pkg/fd/fd.go index a2edf2aa6..d40758c22 100644 --- a/pkg/fd/fd.go +++ b/pkg/fd/fd.go @@ -167,6 +167,24 @@ func NewFromFile(file *os.File) (*FD, error) { return New(fd), nil } +// Open is equivallent to open(2). +func Open(path string, openmode int, perm uint32) (*FD, error) { + f, err := syscall.Open(path, openmode|syscall.O_LARGEFILE, perm) + if err != nil { + return nil, err + } + return New(f), nil +} + +// OpenAt is equivallent to openat(2). +func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error) { + f, err := syscall.Openat(dir.FD(), path, flags, mode) + if err != nil { + return nil, err + } + return New(f), nil +} + // Close closes the file descriptor contained in the FD. // // Close is safe to call multiple times, but will return an error after the |