diff options
author | Jakob Unterwurzacher | 2020-05-28 23:21:35 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2020-05-28 23:23:53 +0200 |
commit | 22e3eec15302eac28c1a2ac3f9af29c2c9e82a3c (patch) | |
tree | f1e3311175a72aa2d8b0c19eb20fe1e5c5531af6 /contrib/getdents-debug/getdents/getdents.go | |
parent | b275c53fa79c7acc555f382e0831c81491be3183 (diff) |
getdents-debug: loop and stop on first error
Also try to improve and unify output a little.
$ ./getdents /usr/share/man/man1
1: unix.Getdents: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; err=<nil>; total 122112 bytes
2: unix.Getdents: n=9984; n=48; n=9976; n=9968; n=9976; n=9976; n=9992; n=9984; n=9992; n=10000; n=9976; n=9968; n=10000; n=2272; n=0; err=<nil>; total 122112 bytes
3: unix.Getdents: n=9984; n=9984; n=9968; n=704; n=10000; n=10000; n=9968; n=9968; n=9992; n=10000; n=9960; n=9992; n=9992; n=1600; n=0; err=<nil>; total 122112 bytes
4: unix.Getdents: n=9984; n=9984; n=9968; n=9976; n=9984; n=32; n=9992; n=9984; n=9992; n=10000; n=9976; n=9968; n=10000; n=2272; n=0; err=<nil>; total 122112 bytes
$ ./getdents_c /usr/share/man/man1
1: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
2: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
3: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
4: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
Diffstat (limited to 'contrib/getdents-debug/getdents/getdents.go')
-rw-r--r-- | contrib/getdents-debug/getdents/getdents.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/contrib/getdents-debug/getdents/getdents.go b/contrib/getdents-debug/getdents/getdents.go index cd1e49d..d7dac78 100644 --- a/contrib/getdents-debug/getdents/getdents.go +++ b/contrib/getdents-debug/getdents/getdents.go @@ -40,6 +40,7 @@ import ( "flag" "fmt" "os" + "time" "golang.org/x/sys/unix" ) @@ -50,11 +51,10 @@ const ( func main() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: %s [-loop] PATH\n", myName) - fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH\n") + fmt.Fprintf(os.Stderr, "Usage: %s PATH\n", myName) + fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH in a 100ms loop until we hit an error\n") os.Exit(1) } - loop := flag.Bool("loop", false, "Run in a loop") flag.Parse() if flag.NArg() != 1 { flag.Usage() @@ -62,14 +62,14 @@ func main() { path := flag.Arg(0) tmp := make([]byte, 10000) - for { + for i := 1; ; i++ { sum := 0 fd, err := unix.Open(path, unix.O_RDONLY, 0) if err != nil { - fmt.Printf("unix.Open returned err=%v\n", err) - continue + fmt.Printf("%3d: unix.Open returned err=%v\n", err) + os.Exit(1) } - fmt.Printf("unix.Getdents: ") + fmt.Printf("%3d: unix.Getdents: ", i) for { n, err := unix.Getdents(fd, tmp) fmt.Printf("n=%d; ", n) @@ -83,8 +83,6 @@ func main() { sum += n } unix.Close(fd) - if !*loop { - break - } + time.Sleep(100 * time.Millisecond) } } |