more logs

This commit is contained in:
Łukasz Magiera 2022-05-05 13:12:09 -04:00
parent 1249809283
commit 3c9a8a42d9

View File

@ -4,6 +4,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"time"
"golang.org/x/xerrors" "golang.org/x/xerrors"
) )
@ -15,6 +16,8 @@ type SizeInfo struct {
// FileSize returns bytes used by a file or directory on disk // FileSize returns bytes used by a file or directory on disk
// NOTE: We care about the allocated bytes, not file or directory size // NOTE: We care about the allocated bytes, not file or directory size
func FileSize(path string) (SizeInfo, error) { func FileSize(path string) (SizeInfo, error) {
start := time.Now()
var size int64 var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
@ -32,6 +35,11 @@ func FileSize(path string) (SizeInfo, error) {
} }
return err return err
}) })
if time.Now().Sub(start) >= 3*time.Second {
log.Warnw("very slow file size check", "took", time.Now().Sub(start), "path", path)
}
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return SizeInfo{}, os.ErrNotExist return SizeInfo{}, os.ErrNotExist