// Period reads from pwm period path and returns value in nanoseconds
183708
func (p *PWMPin) Period() (period uint32, err error) {
	buf, err := p.read(p.pwmPeriodPath())
	if err != nil {
		return
	}
	if len(buf) == 0 {
		return 0, nil
	}

	v := bytes.TrimRight(buf, "\n")
	val, e := strconv.Atoi(string(v))
	return uint32(val), e
}
500826
func (s *QuotaSettings) SetPeriod(v string) *QuotaSettings {
	s.Period = &v
	return s
}
361180
func (f *CGroupFingerprint) Periodic() (bool, time.Duration) {
	return true, interval * time.Second
}
423141
func (r Range) Duration() time.Duration {
	return r.End.Sub(r.Start)
}
405551
func (e *Adaptor) PwmWrite(pin string, val byte) (err error) {
	pwmPin, err := e.PWMPin(pin)
	if err != nil {
		return
	}
	period, err := pwmPin.Period()
	if err != nil {
		return err
	}
	duty := gobot.FromScale(float64(val), 0, 255.0)
	return pwmPin.SetDutyCycle(uint32(float64(period) * duty))
}
812755
func Interval(db XODB, v0 pgtypes.Reltime, v1 time.Time, v2 *time.Duration, v3 int) (*time.Duration, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.interval($1, $2, $3, $4)`

	// run query
	var ret *time.Duration
	XOLog(sqlstr, v0, v1, v2, v3)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3).Scan(&ret)
	if err != nil {
		return nil, err
	}

	return ret, nil
}
1197236
func Duration(max time.Duration) time.Duration {
	nbNanoseconds := 1 + int(rand.Int63n(max.Nanoseconds()))
	return time.Duration(nbNanoseconds) * time.Nanosecond
}
922711
func (servo *Servo) WriteMicroseconds(ms int) {
	// just pass to the underlying PWM pin.
	servo.PWM.SetDuty(servo.Pin, int64(ms*1000))
}
1159915
func (d Duration) Time(unit Duration, bpm int) time.Duration {
	val := (60.0 / float64(bpm)) / (float64(d.Value) / 4.0) / (float64(unit.Value) / 4.0)

	for i := 0; i < d.Dots; i++ {
		val += val / 2.0
	}

	if d.Triplet {
		val = val / 3.0
	}

	return time.Duration(val * ns)
}
1021563
func (t *Timedelta) Duration() time.Duration {
	return t.Days*24*time.Hour +
		t.Seconds*time.Second +
		t.Microseconds*time.Microsecond +
		t.Milliseconds*time.Millisecond +
		t.Minutes*time.Minute +
		t.Hours*time.Hour +
		t.Weeks*7*24*time.Hour
}
666655
func (t UnixTime) Duration() time.Duration {
	return time.Time(t).Sub(unixEpoch)
}
377912
func (p *parserMixin) Duration() (target *time.Duration) {
	target = new(time.Duration)
	p.DurationVar(target)
	return
}
883167
func (s *server) HeartbeatInterval() time.Duration {
	s.mutex.RLock()
	defer s.mutex.RUnlock()
	return s.heartbeatInterval
}
896788
func (spec *ConnectionSpec) Heartbeat(period time.Duration) *ConnectionSpec {
	spec.heartbeat = period
	return spec
}
218963
func (bp *Bypass) Period() time.Duration {
	if bp.Stopped() {
		return -1
	}

	bp.mux.RLock()
	defer bp.mux.RUnlock()

	return bp.period
}
481313
func periodic() {
	contents, err := ioutil.ReadFile(procStatFile)
	if err != nil {
		return
	}
	fields := bytes.Fields(contents)

	// PCPU
	pstart := parseInt64(fields[startPos])
	utime := parseInt64(fields[utimePos])
	stime := parseInt64(fields[stimePos])
	total := utime + stime

	var sysinfo syscall.Sysinfo_t
	if err := syscall.Sysinfo(&sysinfo); err != nil {
		return
	}

	seconds := int64(sysinfo.Uptime) - (pstart / ticks)

	// Save off temps
	lt := lastTotal
	ls := lastSeconds

	// Update last sample
	lastTotal = total
	lastSeconds = seconds

	// Adjust to current time window
	total -= lt
	seconds -= ls

	if seconds > 0 {
		atomic.StoreInt64(&ipcpu, (total*1000/ticks)/seconds)
	}

	time.AfterFunc(1*time.Second, periodic)
}
600161
func (s *PutMetricAlarmInput) SetPeriod(v int64) *PutMetricAlarmInput {
	s.Period = &v
	return s
}