// RoundDown will round tp down to next "full" d.
509
func RoundDown(t time.Time, d TimeDelta) time.Time {
	td := d.RoundDown(t)
	DebugLogger.Printf("RoundDown( %s, %s ) --> %s", t.Format("2006-01-02 15:04:05 (Mon)"), d.String(),
		td.Format("2006-01-02 15:04:05 (Mon)"))
	return td
}
247014
func Round(f float64, n int) float64 {
	pow10n := math.Pow10(n)
	return math.Trunc((f+0.5/pow10n)*pow10n) / pow10n
}
671290
func (t *requestTracker) markedDown() error {
	ss := atomic.LoadInt32(&t.shutdownState)
	if ss != running {
		reason := t.shutdownReason.Load().(*error)
		if reason == nil {
			return nil
		}
		return *reason
	}
	return nil
}
634245
func (t *instrumentedHTTPRoundTripper) RoundTrip(origReq *http.Request) (*http.Response, error) {
	req := *origReq

	// If a request body was provided, wrap it in a CountingReader so we can see
	// how big it was after it's been sent.
	var requestBodyReader *iotools.CountingReader
	if req.Body != nil {
		requestBodyReader = &iotools.CountingReader{Reader: req.Body}
		req.Body = struct {
			io.Reader
			io.Closer
		}{requestBodyReader, req.Body}
	}

	start := clock.Now(t.ctx)
	resp, err := t.base.RoundTrip(&req)
	duration := clock.Now(t.ctx).Sub(start)

	var requestBytes int64
	if requestBodyReader != nil {
		requestBytes = requestBodyReader.Count
	}

	var code int
	var responseBytes int64
	if resp != nil {
		code = resp.StatusCode
		responseBytes = resp.ContentLength
	}

	UpdateHTTPMetrics(t.ctx, req.URL.Host, t.client, code, duration, requestBytes, responseBytes)

	return resp, err
}
281974
func (el *ChannelEventListener) RegAccountShutdown() *ChannelEventListener {
	el.Shutdown = make(chan struct{})
	el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
		el.Shutdown <- struct{}{}
	}, event.EventShutdown))
	return el
}
1363557
func (auto *AutoGcd) Shutdown() error {
	if auto.shutdown {
		return errors.New("AutoGcd already shut down.")
	}

	auto.tabLock.Lock()
	for _, tab := range auto.tabs {
		tab.close() // exit go routines
		auto.debugger.CloseTab(tab.ChromeTarget)

	}
	auto.tabLock.Unlock()

	if !auto.settings.connectToInstance {
		err := auto.debugger.ExitProcess()
		if auto.settings.removeUserDir == true {
			return os.RemoveAll(auto.settings.userDir)
		}
		return err
	}

	auto.shutdown = true
	return nil
}
704768
func (process *TeleportProcess) StartShutdown(ctx context.Context) context.Context {
	process.BroadcastEvent(Event{Name: TeleportExitEvent, Payload: ctx})
	localCtx, cancel := context.WithCancel(ctx)
	go func() {
		defer cancel()
		process.Supervisor.Wait()
		process.Debugf("All supervisor functions are completed.")
		localAuth := process.getLocalAuth()
		if localAuth != nil {
			if err := process.localAuth.Close(); err != nil {
				process.Warningf("Failed closing auth server: %v.", err)
			}
		}
	}()
	go process.printShutdownStatus(localCtx)
	return localCtx
}
404733
func RoundUpToGBInt(size resource.Quantity) (int, error) {
	requestBytes := size.Value()
	return roundUpSizeInt(requestBytes, GB)
}
770419
func (a *decimal) RoundUp(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}

	// round up
	for i := nd - 1; i >= 0; i-- {
		c := a.d[i]
		if c < '9' { // can stop after this digit
			a.d[i]++
			a.nd = i + 1
			return
		}
	}

	// Number is all 9s.
	// Change to single 1 with adjusted decimal point.
	a.d[0] = '1'
	a.nd = 1
	a.dp++
}
428987
func round(a float64) float64 {
	if a < 0 {
		return math.Ceil(a - 0.5)
	}
	return math.Floor(a + 0.5)
}
1040372
func round(d, r int64) int64 {
	neg := d < 0
	if neg {
		d = -d
	}
	if m := d % r; m+m < r {
		d = d - m
	} else {
		d = d + r - m
	}
	if neg {
		return -d
	}
	return d
}
554960
func Roundtrip(addr string) (string, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return "", err
	}
	defer conn.Close()
	return RoundtripWithConn(conn)
}
353397
func (a *aggPushDownSolver) aggPushDown(p LogicalPlan) {
	if agg, ok := p.(*Aggregation); ok {
		child := agg.GetChildByIndex(0)
		if join, ok1 := child.(*Join); ok1 && a.checkValidJoin(join) {
			if valid, leftAggFuncs, rightAggFuncs, leftGbyCols, rightGbyCols := a.splitAggFuncsAndGbyCols(agg, join); valid {
				var lChild, rChild LogicalPlan
				// If there exist count or sum functions in left join path, we can't push any
				// aggregate function into right join path.
				rightInvalid := a.checkAnyCountAndSum(leftAggFuncs)
				leftInvalid := a.checkAnyCountAndSum(rightAggFuncs)
				if rightInvalid {
					rChild = join.GetChildByIndex(1).(LogicalPlan)
				} else {
					rChild = a.tryToPushDownAgg(rightAggFuncs, rightGbyCols, join, 1)
				}
				if leftInvalid {
					lChild = join.GetChildByIndex(0).(LogicalPlan)
				} else {
					lChild = a.tryToPushDownAgg(leftAggFuncs, leftGbyCols, join, 0)
				}
				join.SetChildren(lChild, rChild)
				lChild.SetParents(join)
				rChild.SetParents(join)
				join.SetSchema(expression.MergeSchema(lChild.GetSchema(), rChild.GetSchema()))
			}
		} else if proj, ok1 := child.(*Projection); ok1 {
			// TODO: This optimization is not always reasonable. We have not supported pushing projection to kv layer yet,
			// so we must do this optimization.
			for i, gbyItem := range agg.GroupByItems {
				agg.GroupByItems[i] = expression.ColumnSubstitute(gbyItem, proj.schema, proj.Exprs)
			}
			agg.collectGroupByColumns()
			for _, aggFunc := range agg.AggFuncs {
				newArgs := make([]expression.Expression, 0, len(aggFunc.GetArgs()))
				for _, arg := range aggFunc.GetArgs() {
					newArgs = append(newArgs, expression.ColumnSubstitute(arg, proj.schema, proj.Exprs))
				}
				aggFunc.SetArgs(newArgs)
			}
			projChild := proj.children[0]
			agg.SetChildren(projChild)
			projChild.SetParents(agg)
		} else if union, ok1 := child.(*Union); ok1 {
			pushedAgg := a.makeNewAgg(agg.AggFuncs, agg.groupByCols)
			newChildren := make([]Plan, 0, len(union.children))
			for _, child := range union.children {
				newChild := a.pushAggCrossUnion(pushedAgg, union.schema, child.(LogicalPlan))
				newChildren = append(newChildren, newChild)
				newChild.SetParents(union)
			}
			union.SetChildren(newChildren...)
			union.SetSchema(pushedAgg.schema)
		}
	}
	for _, child := range p.GetChildren() {
		a.aggPushDown(child.(LogicalPlan))
	}
}
761207
func roundTime(t gotime.Time, fsp int) gotime.Time {
	d := gotime.Duration(math.Pow10(9 - fsp))
	return t.Round(d)
}
718879
func RoundUpToMiB(size resource.Quantity) int64 {
	requestBytes := size.Value()
	return roundUpSize(requestBytes, MiB)
}
586500
func (rm ReachMap) FlattenAll(stdlib bool) []string {
	return rm.flatten(func(pkg string) bool { return true }, stdlib)
}
862614
func (a *decimal) Round(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}
	if shouldRoundUp(a, nd) {
		a.RoundUp(nd)
	} else {
		a.RoundDown(nd)
	}
}