proc.go 1.31 KB
Newer Older
1 2
package hw

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

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

10 11
// instruction set architecture

12
// ISA enum indicates instruction set achitecture.
13 14 15
type ISA uint

const (
16
	Unknown ISA = iota
17
	// X86_64 indicates Intel x86 ISA with 64 bit addresses
18
	X86_64
19 20
)

21 22 23 24 25 26 27 28 29 30 31 32 33
func (i ISA) String() string {

	switch i {
	case Unknown:
		return "?"
	case X86_64:
		return "x86_64"
	default:
		return "?"
	}

}

34
// Proc represents a processor
35 36
type Proc struct {
	Base
Ryan Goodfellow's avatar
Ryan Goodfellow committed
37 38 39 40 41 42 43
	ISA           ISA    `json:"isa,omitempty"`
	Family        string `json:"family,omitempty"`
	BaseFrequency uint64 `json:"basefrequency,omitempty"`
	L2            uint64 `json:"l2,omitempty"`
	Cores         uint   `json:"cores,omitempty"`
	Threads       uint   `json:"threads,omitempty"`
	Tdp           uint   `json:"tdp,omitempty"`
44
}
45

Ryan Goodfellow's avatar
Ryan Goodfellow committed
46 47 48
func (p Proc) BaseInfo() Base { return p.Base }
func (p Proc) Show() string   { return p.Base.Model }

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
func ProcHeader(tw *tabwriter.Writer) {

	fmt.Fprintf(tw, "COUNT\tMODEL\tISA\tFAMILY\tBASE FREQUENCY\tL2\tCORES\tTHREADS\tTDP\n")

}

func (p Proc) Table(count int, tw *tabwriter.Writer) {

	fmt.Fprintf(tw, "%d\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%s\n",
		count,
		p.Base.Model,
		p.ISA,
		p.Family,
		humanize.SI(float64(p.BaseFrequency), "Hz"),
		humanize.IBytes(p.L2),
		p.Cores,
		p.Threads,
		humanize.SI(float64(p.Tdp), "W"),
	)

}