// Stop signals the timer to end monitoring and return elapsed time so far.
Stop signals the timer to end monitoring and return elapsed time so far.
// Stop signals the timer to end monitoring and return elapsed time so far .
func (t *PCPTimer) Stop() (float64, error) {
	t.mutex.Lock()
	defer t.mutex.Unlock()
	if !t.started {
		return 0, errors.New("trying to stop a stopped timer")
	}
	d := time.Since(t.since)
	var inc float64
	switch t.pcpMetricDesc.Unit() {
	case NanosecondUnit:
		inc = float64(d.Nanoseconds())
	case MicrosecondUnit:
		inc = float64(d.Nanoseconds()) * 1e-3
	case MillisecondUnit:
		inc = float64(d.Nanoseconds()) * 1e-6
	case SecondUnit:
		inc = d.Seconds()
	case MinuteUnit:
		inc = d.Minutes()
	case HourUnit:
		inc = d.Hours()
	}
	v := t.val.(float64)
	err := t.set(v + inc)
	if err != nil {
		return -1, err
	}
	t.started = false
	return v + inc, nil
}
func ( t * PCPTimer ) Stop ( ) ( float64 , error ) { t . mutex . Lock ( ) defer t . mutex . Unlock ( ) if ! t . started { return 0 , errors . New ( " " ) } d := time . Since ( t . since ) var inc float64 switch t . pcpMetricDesc . Unit ( ) { case NanosecondUnit : inc = float64 ( d . Nanoseconds ( ) ) case MicrosecondUnit : inc = float64 ( d . Nanoseconds ( ) ) * 1e-3 case MillisecondUnit : inc = float64 ( d . Nanoseconds ( ) ) * 1e-6 case SecondUnit : inc = d . Seconds ( ) case MinuteUnit : inc = d . Minutes ( ) case HourUnit : inc = d . Hours ( ) } v := t . val . ( float64 ) err := t . set ( v + inc ) if err != nil { return - 1 , err } t . started = false return v + inc , nil }
Stop signals the timer to end monitoring and return elapsed time so far.
Stop signals the timer to end monitoring and return elapsed time so far .