davecgh / go-spew

Implements a deep pretty printer for Go data structures to aid in debugging
ISC License
5.98k stars 361 forks source link

No pretty-print on FreeBSD VMs #125

Closed xxxserxxx closed 4 years ago

xxxserxxx commented 4 years ago

According to the README, Dump is supposed to pretty-print structures, with fields separated by newlines. This does not happen under some circumstances.

Environment

Program

package main

import "github.com/shirou/gopsutil/mem"
import "github.com/davecgh/go-spew/spew"

func main() {
        m, e := mem.VirtualMemory()
        if e != nil {
               panic(e)
        }
        s, e := mem.SwapMemory()
        if e != nil {
                panic(e)
        }
        spew.Dump(m,s)
}

Output

root@freebsd:~/memory # go run main.go
(*mem.VirtualMemoryStat)(0xc000086000)({"total":93827072,"available":39833600,"used":53993472,"usedPercent":57.54572837997118,"free":34660352,"active":4718592,"inactive":4960256,"wired":44883968,"laundry":212992,"buffers":18677760,"cached":0,"writeback":0,"dirty":0,"writebacktmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pagetables":0,"swapcached":0,"commitlimit":0,"committedas":0,"hightotal":0,"highfree":0,"lowtotal":0,"lowfree":0,"swaptotal":0,"swapfree":0,"mapped":0,"vmalloctotal":0,"vmallocused":0,"vmallocchunk":0,"hugepagestotal":0,"hugepagesfree":0,"hugepagesize":0})
(*mem.SwapMemoryStat)(0xc000018190)({"total":1073741824,"used":26644480,"free":1047097344,"usedPercent":2.4814605712890625,"sin":0,"sout":0,"pgin":0,"pgout":0,"pgfault":0})

Expected

More newlines. Or any newlines.

jrick commented 4 years ago

This is because the types implement fmt.Stringer, and that is how they are formatting themselves.

xxxserxxx commented 4 years ago

Ok, thank you.