mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-26 03:30:09 -05:00
064c398dec
You can run these yourself using the -perf flag, e.g. > noms serve & > go test -v -perf http://localhost:8000 ./samples/go/csv/csv-import > noms ds http://localhost:8000 Though you'll need to go-get github.com/attic-labs/testdata. Note that all of this only records test results, it doesn't have any concept of failing perf (unless test assertsions themselves fail). It will be the job of some other Noms client (work in progress) to do that. I will be setting this up to run continuously momentarily.
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package cpu
|
|
|
|
import (
|
|
"encoding/json"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/shirou/gopsutil/internal/common"
|
|
)
|
|
|
|
type TimesStat struct {
|
|
CPU string `json:"cpu"`
|
|
User float64 `json:"user"`
|
|
System float64 `json:"system"`
|
|
Idle float64 `json:"idle"`
|
|
Nice float64 `json:"nice"`
|
|
Iowait float64 `json:"iowait"`
|
|
Irq float64 `json:"irq"`
|
|
Softirq float64 `json:"softirq"`
|
|
Steal float64 `json:"steal"`
|
|
Guest float64 `json:"guest"`
|
|
GuestNice float64 `json:"guestNice"`
|
|
Stolen float64 `json:"stolen"`
|
|
}
|
|
|
|
type InfoStat struct {
|
|
CPU int32 `json:"cpu"`
|
|
VendorID string `json:"vendorId"`
|
|
Family string `json:"family"`
|
|
Model string `json:"model"`
|
|
Stepping int32 `json:"stepping"`
|
|
PhysicalID string `json:"physicalId"`
|
|
CoreID string `json:"coreId"`
|
|
Cores int32 `json:"cores"`
|
|
ModelName string `json:"modelName"`
|
|
Mhz float64 `json:"mhz"`
|
|
CacheSize int32 `json:"cacheSize"`
|
|
Flags []string `json:"flags"`
|
|
}
|
|
|
|
type lastPercent struct {
|
|
sync.Mutex
|
|
lastCPUTimes []TimesStat
|
|
lastPerCPUTimes []TimesStat
|
|
}
|
|
|
|
var lastCPUPercent lastPercent
|
|
var invoke common.Invoker
|
|
|
|
func init() {
|
|
invoke = common.Invoke{}
|
|
lastCPUPercent.Lock()
|
|
lastCPUPercent.lastCPUTimes, _ = Times(false)
|
|
lastCPUPercent.lastPerCPUTimes, _ = Times(true)
|
|
lastCPUPercent.Unlock()
|
|
}
|
|
|
|
func Counts(logical bool) (int, error) {
|
|
return runtime.NumCPU(), nil
|
|
}
|
|
|
|
func (c TimesStat) String() string {
|
|
v := []string{
|
|
`"cpu":"` + c.CPU + `"`,
|
|
`"user":` + strconv.FormatFloat(c.User, 'f', 1, 64),
|
|
`"system":` + strconv.FormatFloat(c.System, 'f', 1, 64),
|
|
`"idle":` + strconv.FormatFloat(c.Idle, 'f', 1, 64),
|
|
`"nice":` + strconv.FormatFloat(c.Nice, 'f', 1, 64),
|
|
`"iowait":` + strconv.FormatFloat(c.Iowait, 'f', 1, 64),
|
|
`"irq":` + strconv.FormatFloat(c.Irq, 'f', 1, 64),
|
|
`"softirq":` + strconv.FormatFloat(c.Softirq, 'f', 1, 64),
|
|
`"steal":` + strconv.FormatFloat(c.Steal, 'f', 1, 64),
|
|
`"guest":` + strconv.FormatFloat(c.Guest, 'f', 1, 64),
|
|
`"guestNice":` + strconv.FormatFloat(c.GuestNice, 'f', 1, 64),
|
|
`"stolen":` + strconv.FormatFloat(c.Stolen, 'f', 1, 64),
|
|
}
|
|
|
|
return `{` + strings.Join(v, ",") + `}`
|
|
}
|
|
|
|
// Total returns the total number of seconds in a CPUTimesStat
|
|
func (c TimesStat) Total() float64 {
|
|
total := c.User + c.System + c.Nice + c.Iowait + c.Irq + c.Softirq + c.Steal +
|
|
c.Guest + c.GuestNice + c.Idle + c.Stolen
|
|
return total
|
|
}
|
|
|
|
func (c InfoStat) String() string {
|
|
s, _ := json.Marshal(c)
|
|
return string(s)
|
|
}
|