// returns a copy of the profiler's frequency.
558581
func (prof *Profiler) newFrequency() *Frequency {
	f := &Frequency{Timestamp: time.Now().UTC().UnixNano(), Sockets: prof.Frequency.Sockets, CPU: make([]CPU, len(prof.Frequency.CPU))}
	copy(f.CPU, prof.Frequency.CPU)
	return f
}
1343801
func (prof *Profiler) cpuMHzMin(x int) (float32, error) {
	v, err := ioutil.ReadFile(prof.cpuInfoFreqMinPath(x))
	if err != nil {
		return 0, err
	}
	// insert the . in the appropriate spot
	v = append(v[:len(v)-4], append([]byte{'.'}, v[len(v)-4:len(v)-1]...)...)
	m, err := strconv.ParseFloat(string(v[:len(v)-1]), 32)
	if err != nil {
		return 0, fmt.Errorf("cpu%d MHz min: conversion error: %s", x, err)
	}
	return float32(m), nil
}
1317472
func (s *CPU) SetFrequency(v string) *CPU {
	s.Frequency = &v
	return s
}
1296635
func NewProfiler() (prof *Profiler, err error) {
	p, err := o.NewProfiler()
	if err != nil {
		return nil, err
	}
	return &Profiler{Profiler: p}, nil
}
1288287
func (s *CreateReplicationJobInput) SetFrequency(v int64) *CreateReplicationJobInput {
	s.Frequency = &v
	return s
}
794363
func (s *Static) GetSampleRate(key string) int {
	if rate, found := s.Rates[key]; found {
		return rate
	}
	return s.Default
}
984800
func (remote *RemoteDebugger) GetPreciseCoverage(precise bool) ([]interface{}, error) {
	var res map[string]interface{}
	var err error

	if precise {
		res, err = remote.SendRequest("Profiler.takePreciseCoverage", nil)
	} else {
		res, err = remote.SendRequest("Profiler.getBestEffortCoverage", nil)
	}
	if res == nil || err != nil {
		return nil, err
	}
	log.Println(res)
	return res["result"].([]interface{}), nil
}
832842
func (prof *Profiler) Get() (u Uptime, err error) {
	err = prof.Reset()
	if err != nil {
		return u, err
	}
	var i int
	var v byte
	u.Timestamp = time.Now().UTC().UnixNano()
	for {
		prof.Line, err = prof.ReadSlice('\n')
		if err != nil {
			if err == io.EOF {
				break
			}
			return u, &joe.ReadError{Err: err}
		}
		// space delimits the two values
		for i, v = range prof.Line {
			if v == 0x20 {
				break
			}
		}
		u.Total, err = strconv.ParseFloat(string(prof.Line[:i]), 64)
		if err != nil {
			return u, &joe.ParseError{Info: "total", Err: err}
		}
		u.Idle, err = strconv.ParseFloat(string(prof.Line[i+1:len(prof.Line)-1]), 64)
		if err != nil {
			return u, &joe.ParseError{Info: "idle", Err: err}
		}

	}
	return u, nil
}
413844
func (prof *Profiler) Get() (*CPUs, error) {
	cpus := &CPUs{CPU: make([]CPU, prof.NumCPU)}
	var err error
	var pids []int32 // the physical ids encountered

	hasFreq := prof.hasCPUFreq()
	for x := 0; x < prof.NumCPU; x++ {
		var cpu CPU
		var found bool

		cpu.PhysicalPackageID, err = prof.physicalPackageID(x)
		if err != nil {
			return nil, err
		}
		// see if this is a new physical id; if so, add it to the inventory
		for _, v := range pids {
			if v == cpu.PhysicalPackageID {
				found = true
				break
			}
		}
		if !found {
			pids = append(pids, cpu.PhysicalPackageID)
		}
		cpu.CoreID, err = prof.coreID(x)
		if err != nil {
			return nil, err
		}
		err := prof.cache(x, &cpu)
		if err != nil {
			return nil, err
		}
		if hasFreq {
			cpu.MHzMin, err = prof.cpuMHzMin(x)
			if err != nil {
				return nil, err
			}
			cpu.MHzMax, err = prof.cpuMHzMax(x)
			if err != nil {
				return nil, err
			}
		}
		cpus.CPU[x] = cpu
	}
	cpus.Sockets = int32(len(pids))
	cpus.Possible, err = prof.Possible()
	if err != nil {
		return nil, err
	}

	cpus.Online, err = prof.Online()
	if err != nil {
		return nil, err
	}

	cpus.Offline, err = prof.Offline()
	if err != nil {
		return nil, err
	}

	cpus.Present, err = prof.Present()
	if err != nil {
		return nil, err
	}

	return cpus, nil
}
591452
func (a *AvgSampleWithMin) GetSampleRate(key string) int {
	a.lock.Lock()
	defer a.lock.Unlock()
	a.currentCounts[key]++
	if !a.haveData {
		return a.GoalSampleRate
	}
	if rate, found := a.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
203834
func NewProfiler() (prof *Profiler, err error) {
	proc, err := joe.NewProc(procFile)
	if err != nil {
		return nil, err
	}
	cpuProf := cpux.NewProfiler()
	nodeProf := node.NewProfiler()
	return &Profiler{Procer: proc, Buffer: joe.NewBuffer(), CPUProf: cpuProf, NodeProf: nodeProf}, nil
}
1006464
func (rs Recoverings) Frequency(num int, dur time.Duration) bool {
	if len(rs) >= num {
		first := rs[len(rs)-num].Time
		last := rs[len(rs)-1].Time
		return last.Sub(first) <= dur
	}
	return false
}
1088853
func (p Pitch) Freq() float64 {
	return concertFrequency * math.Pow(semitone, float64(p.Semitones()-middleA.Semitones()))
}
407670
func (s *Sinc) TransitionFreq() float64 {
	if s == nil {
		return 0
	}
	return s.CutOffFreq / float64(s.SamplingFreq)
}
1024977
func (prof *Profiler) Marshal(ut *util.CPUUtil) ([]byte, error) {
	return prof.Serialize(ut)
}
575212
func (prof *Profiler) Get() (stats *structs.DiskStats, err error) {
	err = prof.Reset()
	if err != nil {
		return nil, err
	}
	var (
		i, priorPos, pos, line, fieldNum int
		n                                uint64
		v                                byte
		dev                              structs.Device
	)

	stats = &structs.DiskStats{Timestamp: time.Now().UTC().UnixNano(), Device: make([]structs.Device, 0, 2)}

	// read each line until eof
	for {
		prof.Line, err = prof.ReadSlice('\n')
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, &joe.ReadError{Err: err}
		}
		line++
		pos = 0
		fieldNum = 0
		// process the fields in the line
		for {
			// ignore spaces on the first two fields
			if fieldNum < 2 {
				for i, v = range prof.Line[pos:] {
					if v != 0x20 {
						break
					}
				}
				pos += i
			}
			fieldNum++
			for i, v = range prof.Line[pos:] {
				if v == 0x20 || v == '\n' {
					break
				}
			}
			if fieldNum != 3 {
				n, err = helpers.ParseUint(prof.Line[pos : pos+i])
				if err != nil {
					return stats, &joe.ParseError{Info: fmt.Sprintf("line %d: field %d", line, fieldNum), Err: err}
				}
			}
			priorPos, pos = pos, pos+i+1
			if fieldNum < 8 {
				if fieldNum < 4 {
					if fieldNum < 2 {
						if fieldNum == 1 {
							dev.Major = uint32(n)
							continue
						}
						dev.Minor = uint32(n)
						continue
					}
					dev.Name = string(prof.Line[priorPos:pos])
					continue
				}
				if fieldNum < 6 {
					if fieldNum == 4 {
						dev.ReadsCompleted = n
						continue
					}
					dev.ReadsMerged = n
					continue
				}
				if fieldNum == 6 {
					dev.ReadSectors = n
					continue
				}
				dev.ReadingTime = n
				continue
			}
			if fieldNum < 12 {
				if fieldNum < 10 {
					if fieldNum == 8 {
						dev.WritesCompleted = n
						continue
					}
					dev.WritesMerged = n
					continue
				}
				if fieldNum == 10 {
					dev.WrittenSectors = n
					continue
				}
				dev.WritingTime = n
				continue
			}
			if fieldNum == 12 {
				dev.IOInProgress = int32(n)
				continue
			}
			if fieldNum == 13 {
				dev.IOTime = n
				continue
			}
			dev.WeightedIOTime = n
			break
		}
		stats.Device = append(stats.Device, dev)
	}
	return stats, nil
}
253400
func profile(profFile string, dieAfter time.Duration, readyCh <-chan struct{}) {
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, os.Interrupt)
	go func() {
		if readyCh != nil {
			<-readyCh
		}
		start := time.Now()
		initialUserTime, initialSysTime := getRusage()
		packetsInitiallySent, packetsInitiallyReceived := MQTT.GetStats()

		f, err := os.Create(profFile)
		if err != nil {
			Error.Fatalf("error creating profiling file: %s", err)
		}
		pprof.StartCPUProfile(f)

		// TBD: add timer
		var dieCh <-chan time.Time = nil
		if dieAfter > 0 {
			dieCh = time.After(dieAfter)
		}
		select {
		case <-ch:
		case <-dieCh:
		}
		newUserTime, newSysTime := getRusage()
		elapsed := time.Since(start)
		if elapsed == 0 {
			fmt.Fprintln(os.Stderr, "oops, no time elapsed?")
			return
		}
		elapsedUserTime := newUserTime - initialUserTime
		elapsedSysTime := newSysTime - initialSysTime
		elapsedCpuTime := elapsedUserTime + elapsedSysTime
		cpuLoadUser := float64(elapsedUserTime) * 100.0 / float64(elapsed)
		cpuLoadSys := float64(elapsedSysTime) * 100.0 / float64(elapsed)
		cpuLoad := float64(elapsedCpuTime) * 100.0 / float64(elapsed)

		newPacketsSent, newPacketsReceived := MQTT.GetStats()
		packetsSent := newPacketsSent - packetsInitiallySent
		packetsReceived := newPacketsReceived - packetsInitiallyReceived
		if packetsSent > 0 || packetsReceived > 0 {
			packetsSentPerSecond := float64(packetsSent) * float64(time.Second) /
				float64(elapsed)
			packetsReceivedPerSecond := float64(packetsReceived) * float64(time.Second) /
				float64(elapsed)
			packetsSentPerCpuSecond := float64(packetsSent) * float64(time.Second) /
				float64(elapsedCpuTime)
			packetsReceivedPerCpuSecond := float64(packetsReceived) * float64(time.Second) /
				float64(elapsedCpuTime)

			fmt.Printf("\n*** %d packets sent (%.2f per sec, %.2f per cpu sec), "+
				"%d packets received (%.2f per sec, %.2f per cpu sec)\n",
				packetsSent, packetsSentPerSecond, packetsSentPerCpuSecond,
				packetsReceived, packetsReceivedPerSecond, packetsReceivedPerCpuSecond)
		}

		fmt.Printf("*** %.2f seconds elapsed, %.2f user, %.2f sys\n",
			float64(elapsed)/float64(time.Second),
			float64(elapsedUserTime)/float64(time.Second),
			float64(elapsedSysTime)/float64(time.Second))
		fmt.Printf("*** %.2f%% CPU load, %.2f%% user, %.2f%% sys\n",
			cpuLoad, cpuLoadUser, cpuLoadSys)
		pprof.StopCPUProfile()
		os.Exit(130)
	}()
}