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
This commit is contained in:
parent
b275c53fa7
commit
22e3eec153
@ -40,6 +40,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@ -50,11 +51,10 @@ const (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s [-loop] PATH\n", myName)
|
fmt.Fprintf(os.Stderr, "Usage: %s PATH\n", myName)
|
||||||
fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH\n")
|
fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH in a 100ms loop until we hit an error\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
loop := flag.Bool("loop", false, "Run in a loop")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if flag.NArg() != 1 {
|
if flag.NArg() != 1 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
@ -62,14 +62,14 @@ func main() {
|
|||||||
path := flag.Arg(0)
|
path := flag.Arg(0)
|
||||||
|
|
||||||
tmp := make([]byte, 10000)
|
tmp := make([]byte, 10000)
|
||||||
for {
|
for i := 1; ; i++ {
|
||||||
sum := 0
|
sum := 0
|
||||||
fd, err := unix.Open(path, unix.O_RDONLY, 0)
|
fd, err := unix.Open(path, unix.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("unix.Open returned err=%v\n", err)
|
fmt.Printf("%3d: unix.Open returned err=%v\n", err)
|
||||||
continue
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Printf("unix.Getdents: ")
|
fmt.Printf("%3d: unix.Getdents: ", i)
|
||||||
for {
|
for {
|
||||||
n, err := unix.Getdents(fd, tmp)
|
n, err := unix.Getdents(fd, tmp)
|
||||||
fmt.Printf("n=%d; ", n)
|
fmt.Printf("n=%d; ", n)
|
||||||
@ -83,8 +83,6 @@ func main() {
|
|||||||
sum += n
|
sum += n
|
||||||
}
|
}
|
||||||
unix.Close(fd)
|
unix.Close(fd)
|
||||||
if !*loop {
|
time.Sleep(100 * time.Millisecond)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,37 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if(argc < 2) {
|
if(argc != 2) {
|
||||||
printf("Usage: %s PATH\n", argv[0]);
|
printf("Usage: %s PATH\n", argv[0]);
|
||||||
printf("Run getdents(2) on PATH\n");
|
printf("Run getdents(2) on PATH in a 100ms loop\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *path = argv[1];
|
const char *path = argv[1];
|
||||||
int fd = open(path, O_RDONLY);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror("open");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char tmp[10000];
|
for (int i = 1 ; ; i ++ ) {
|
||||||
int sum = 0;
|
int fd = open(path, O_RDONLY);
|
||||||
for ( ; ; ) {
|
if (fd == -1) {
|
||||||
int n = syscall(SYS_getdents64, fd, tmp, sizeof(tmp));
|
perror("open");
|
||||||
printf("getdents64 fd%d: n=%d, errno=%d\n", fd, n, errno);
|
exit(1);
|
||||||
if (n <= 0) {
|
|
||||||
printf("total %d bytes\n", sum);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
sum += n;
|
|
||||||
|
char tmp[10000];
|
||||||
|
int sum = 0;
|
||||||
|
printf("%3d: getdents64: ", i);
|
||||||
|
for ( ; ; ) {
|
||||||
|
int n = syscall(SYS_getdents64, fd, tmp, sizeof(tmp));
|
||||||
|
printf("n=%d; ", n);
|
||||||
|
if (n <= 0) {
|
||||||
|
printf("errno=%d total %d bytes\n", errno, sum);
|
||||||
|
if (n < 0) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sum += n;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
usleep(100000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user