// CPUsInCore returns all of the logical CPU IDs associated with the
// given core ID in this CPUDetails.
963896
func (d CPUDetails) CPUsInCore(id int) cpuset.CPUSet {
	b := cpuset.NewBuilder()
	for cpu, info := range d {
		if info.CoreID == id {
			b.Add(cpu)
		}
	}
	return b.Result()
}
1054807
func (c cpuInfo) logicalcpu() int {
	if c.maxFunc < 1 {
		return -1
	}
	_, ebx, _, _ := cpuid(1)
	return int(ebx >> 24)
}
1250966
func CpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
	dataSize := 16 * protocol.MinBlockSize
	bs := make([]byte, dataSize)
	rand.Reader.Read(bs)

	var perf float64
	for i := 0; i < iterations; i++ {
		if v := cpuBenchOnce(duration, useWeakHash, bs); v > perf {
			perf = v
		}
	}
	blocksResult = nil
	return perf
}
592764
func (s CPUSet) Contains(cpu int) bool {
	_, found := s.elems[cpu]
	return found
}
87881
func (s *Stat) CPUStats() *CPUStats {
	s.Lock()
	defer s.Unlock()

	var cpu *CPUStats
	do(func() {

		cpup := C.sg_get_cpu_percents_of(C.sg_new_diff_cpu_percent, nil)

		loadStat := C.sg_get_load_stats(nil)

		cpu = &CPUStats{
			User:      float64(cpup.user),
			Kernel:    float64(cpup.kernel),
			Idle:      float64(cpup.idle),
			IOWait:    float64(cpup.iowait),
			Swap:      float64(cpup.swap),
			Nice:      float64(cpup.nice),
			LoadMin1:  float64(loadStat.min1),
			LoadMin5:  float64(loadStat.min5),
			LoadMin15: float64(loadStat.min15),
			Period:    time.Duration(int(cpup.time_taken)) * time.Second,
			TimeTaken: time.Now(),
		}
	})
	return cpu
}
876277
func (c *CPUs) GetCPU(pID, coreID int32) (cpu CPU, found bool) {
	for i := 0; i < len(c.CPU); i++ {
		if c.CPU[i].PhysicalPackageID == pID && c.CPU[i].CoreID == coreID {
			return c.CPU[i], true
		}
	}
	return CPU{}, false
}
89984
func (d CPUDetails) CPUs() cpuset.CPUSet {
	b := cpuset.NewBuilder()
	for cpuID := range d {
		b.Add(cpuID)
	}
	return b.Result()
}
676547
func (r *SearchRequest) TrackScores(trackScores bool) *SearchRequest {
	r.searchSource = r.searchSource.TrackScores(trackScores)
	return r
}
873712
func (c *CpuStats) Percent(cpuTime float64) float64 {
	now := time.Now()

	if c.prevCpuTime == 0.0 {
		// invoked first time
		c.prevCpuTime = cpuTime
		c.prevTime = now
		return 0.0
	}

	timeDelta := now.Sub(c.prevTime).Nanoseconds()
	ret := c.calculatePercent(c.prevCpuTime, cpuTime, timeDelta)
	c.prevCpuTime = cpuTime
	c.prevTime = now
	return ret
}
1221699
func (db *DB) ZRangeByScore(key []byte, min int64, max int64,
	offset int, count int) ([]ScorePair, error) {
	return db.ZRangeByScoreGeneric(key, min, max, offset, count, false)
}
699214
func (s *CreateCoreDefinitionVersionInput) SetCores(v []*Core) *CreateCoreDefinitionVersionInput {
	s.Cores = v
	return s
}
1349003
func (c *Container) CPUs() uint {
	var cores uint
	if v := c.Config["limits.cpu"]; v != "" {
		_, err := fmt.Sscanf(v, "%d", &cores)
		if err != nil {
			logger.Errorf("failed to parse %q into uint, ignoring err: %s", v, err)
		}
	}
	return cores
}
1260336
func (d CPUDetails) Cores() cpuset.CPUSet {
	b := cpuset.NewBuilder()
	for _, info := range d {
		b.Add(info.CoreID)
	}
	return b.Result()
}
954571
func (topo *CPUTopology) CPUsPerCore() int {
	if topo.NumCores == 0 {
		return 0
	}
	return topo.NumCPUs / topo.NumCores
}
887798
func (prof *Profiler) calculateUtilization(cur *stats.CPUStats) *CPUUtil {
	u := &CPUUtil{
		Timestamp:  cur.Timestamp,
		TimeDelta:  cur.Timestamp - prof.prior.Timestamp,
		BTimeDelta: int32(cur.Timestamp/1000000000 - cur.BTime),
		CtxtDelta:  cur.Ctxt - prof.prior.Ctxt,
		Processes:  int32(cur.Processes),
		CPU:        make([]Utilization, len(cur.CPU)),
	}
	var dUser, dNice, dSys, dIdle, tot float32
	// Rest of the calculations are per core
	for i := 0; i < len(cur.CPU); i++ {
		v := Utilization{ID: cur.CPU[i].ID}
		dUser = float32(cur.CPU[i].User - prof.prior.CPU[i].User)
		dNice = float32(cur.CPU[i].Nice - prof.prior.CPU[i].Nice)
		dSys = float32(cur.CPU[i].System - prof.prior.CPU[i].System)
		dIdle = float32(cur.CPU[i].Idle - prof.prior.CPU[i].Idle)
		tot = dUser + dNice + dSys + dIdle
		v.Usage = (dUser + dNice + dSys) / tot * float32(cur.ClkTck)
		v.User = dUser / tot * float32(cur.ClkTck)
		v.Nice = dNice / tot * float32(cur.ClkTck)
		v.System = dSys / tot * float32(cur.ClkTck)
		v.Idle = dIdle / tot * float32(cur.ClkTck)
		v.IOWait = float32(cur.CPU[i].IOWait-prof.prior.CPU[i].IOWait) / tot * float32(cur.ClkTck)
		u.CPU[i] = v
	}
	return u
}
199151
func Serialize(cpus *cpux.CPUs) (p []byte) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std = NewProfiler()
	}
	return std.Serialize(cpus)
}
77060
func CpuRestGetInfo(context *gin.Context) {
	body, err := cpu.ServiceGetInfo()
	util.RestHandleResponse(context, body, err)
}