fs_usage on OSX not showing details when forked

0

On OSX (10.15.6), I am using fs_usage to measure disk IO for a process. When I invoke it via the command-line, it works as expected, providing the number of bytes written:

$ sudo fs_usage -f diskio 0

Yields

10:16:04.496784    WrMeta[AT1P]    D=0x0000022e  B=0x1000   /dev/disk1   0.004530 W kernel_task.691
10:16:04.496787    WrMeta[AT1P]    D=0x000008d5  B=0x1000   /dev/disk1   0.004480 W kernel_task.691
10:16:04.496789    WrMeta[AT1P]    D=0x00000b88  B=0x1000   /dev/disk1   0.004477 W kernel_task.691

However, when I run the same command via a go program which shells out, then the numerical details (D=..., B=...) are omitted.

func main() {
    cmd := exec.Command("fs_usage", "-f", "diskio", "0")

    stdout, err := cmd.StdoutPipe()
    if err != nil {
        log.Fatal(err)
    }

    err = cmd.Start()
    if err != nil {
        log.Fatal(err)
    }

    scanner := bufio.NewScanner(stdout)
    scanner.Split(bufio.ScanLines)
    for scanner.Scan() {
        line := scanner.Text()
        fmt.Println(line)
    }

    cmd.Wait()
}

Invoking go build main.go; sudo ./main yields:

10:19:27    WrMeta[AT1P]    /dev/disk1     0.000582 W kernel_task
10:19:27    WrMeta[AT1P]    /dev/disk1     0.000538 W kernel_task
10:19:27    WrMeta[AT1P]    /dev/disk1     0.000523 W kernel_task

Note that the actual disk IO metrics are missing. Why is this? How can I ensure the behavior of my go program is equivalent to my invoking in the terminal?

performance
go
disk
disk-io
performance-measuring
asked on Stack Overflow Aug 25, 2020 by poundifdef

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0