memory.go 869 Bytes
Newer Older
1 2
package hw

3 4 5 6 7 8 9
import (
	"fmt"
	"text/tabwriter"

	"github.com/dustin/go-humanize"
)

Ryan Goodfellow's avatar
Ryan Goodfellow committed
10 11 12
type MemoryType int

const (
13 14
	MemoryTypeUnknown MemoryType = iota
	DDR3
Ryan Goodfellow's avatar
Ryan Goodfellow committed
15 16 17 18 19 20 21 22 23
	DDR4
)

func (t MemoryType) String() string {
	switch t {
	case DDR3:
		return "DDR3"
	case DDR4:
		return "DDR4"
24 25
	default:
		return "?"
Ryan Goodfellow's avatar
Ryan Goodfellow committed
26 27 28
	}
}

29
type Dimm struct {
Ryan Goodfellow's avatar
Ryan Goodfellow committed
30
	Base
Ryan Goodfellow's avatar
Ryan Goodfellow committed
31 32 33
	Type      MemoryType `json:"type,omitempty"`
	Capacity  uint64     `json:"capacity,omitempty"`
	Frequency uint64     `json:"frequency,omitempty"`
34 35
}

Ryan Goodfellow's avatar
Ryan Goodfellow committed
36 37 38
func (d Dimm) BaseInfo() Base { return d.Base }
func (d Dimm) Show() string   { return d.Base.Model }

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
func DimmHeader(tw *tabwriter.Writer) {

	fmt.Fprintf(tw, "COUNT\tTYPE\tCAPACITY\tFREQUENCY\n")

}

func (d Dimm) Table(count int, tw *tabwriter.Writer) {

	fmt.Fprintf(tw, "%d\t%s\t%s\t%s\n",
		count,
		d.Type,
		humanize.IBytes(d.Capacity),
		humanize.SI(float64(d.Frequency), "Hz"),
	)

54
}