use Access() instead of Lstat() for frequent use (#11911)

using Lstat() is causing tiny memory allocations,
that are usually wasted and never used, instead
we can simply uses Access() call that does 0
memory allocations.
This commit is contained in:
Harshavardhana
2021-03-29 08:07:23 -07:00
committed by GitHub
parent 7c5b35d20f
commit d93c6cb9c7
9 changed files with 101 additions and 67 deletions
+9
View File
@@ -39,6 +39,7 @@ const (
osMetricLstat
osMetricRemove
osMetricStat
osMetricAccess
// .... add more
osMetricLast
@@ -94,6 +95,14 @@ func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
return os.OpenFile(name, flag, perm)
}
// Access captures time taken to call syscall.Access()
// on windows, plan9 and solaris syscall.Access uses
// os.Lstat()
func Access(name string) error {
defer updateOSMetrics(osMetricAccess, name)()
return access(name)
}
// Open captures time taken to call os.Open
func Open(name string) (*os.File, error) {
defer updateOSMetrics(osMetricOpen, name)()