// Track records the payload info in the hook context.
348934
func (c *Context) Track(pl payload.Payload) error {
	logger.Tracef("adding %q to hook context: %#v", pl.FullID(), pl)

	if err := pl.Validate(); err != nil {
		return errors.Trace(err)
	}

	// TODO(ericsnow) We are likely missing mechanism for local persistence.
	id := pl.FullID()
	c.updates[id] = pl
	return nil
}
1106001
func Trace(format string, err error, fields logrus.Fields, a ...interface{}) {
	if traceEnabled {
		log.WithError(err).WithFields(fields).Debugf(format)
	}
}
171835
func (l *Logger) Trace(v ...interface{}) {
	if l.getLevel() <= Trace {
		l.getHandler().Log(l.name, Trace, fmt.Sprint(v...), 1)
	}
}
432406
func (c *Context) Flush() error {
	logger.Tracef("flushing from hook context to state")
	// TODO(natefinch): make this a noop and move this code into set.

	if len(c.updates) > 0 {
		var updates []payload.Payload
		for _, pl := range c.updates {
			updates = append(updates, pl)
		}

		res, err := c.api.Track(updates...)
		if err != nil {
			return errors.Trace(err)
		}
		if len(res) > 0 && res[0].Error != nil {
			return errors.Trace(res[0].Error)
		}

		for k, v := range c.updates {
			c.payloads[k] = v
		}
		c.updates = map[string]payload.Payload{}
	}
	return nil
}
513117
func (a *EventCorrelator) Track(h *swf.HistoryEvent) {
	a.RemoveCorrelation(h)
	a.Correlate(h)
}
1341804
func (c *Client) Hook() (packer.Hook, error) {
	client, err := c.packrpcClient()
	if err != nil {
		return nil, err
	}

	return &cmdHook{client.Hook(), c}, nil
}
436322
func Payload(load context.Context) option {
	return func(c *sass) error {
		c.ctx.Payload = load
		return nil
	}
}
899548
func (c *Cover) Trace(event *topdown.Event) {
	switch event.Op {
	case topdown.ExitOp:
		if rule, ok := event.Node.(*ast.Rule); ok {
			c.setHit(rule.Head.Location)
		}
	case topdown.EvalOp:
		if expr := event.Node.(*ast.Expr); expr != nil {
			c.setHit(expr.Location)
		}
	}
}
505423
func (s *globalTaskService) TaskTrack(ctx types.Context) *types.Task {
	return &s.taskTrack(ctx).Task
}
919803
func (t *Track) ChunkData(endTrack bool) ([]byte, error) {
	buff := bytes.NewBuffer(nil)
	// time signature
	// TODO: don't have 4/4 36, 8 hardcoded
	buff.Write([]byte{0x00, 0xFF, 0x58, 0x04, 0x04, 0x02, 0x24, 0x08})

	if endTrack {
		if l := len(t.Events); l > 0 {
			if t.Events[l-1].Cmd != MetaByteMap["End of Track"] {
				t.Add(0, EndOfTrack())
			}
		}
	}
	for _, e := range t.Events {
		if _, err := buff.Write(e.Encode()); err != nil {
			return nil, err
		}
	}
	return buff.Bytes(), nil
}
857043
func (p *PeriodicDispatch) Tracked() []*structs.Job {
	p.l.RLock()
	defer p.l.RUnlock()
	tracked := make([]*structs.Job, len(p.tracked))
	i := 0
	for _, job := range p.tracked {
		tracked[i] = job
		i++
	}
	return tracked
}
579801
func (ac *AppClient) SetTrack(track string) error {
	// Although track is an omaha extension and theoretically not required
	// our Core Update server requires track to be set to a valid id/name.
	// TODO: deprecate track and use the standard cohort protocol fields.
	if track == "" {
		return errors.New("omaha: empty application update track/group")
	}

	ac.track = track
	return nil
}
422889
func (t *requestTracker) trackerLoop() {
	activeRequests := 0
	stopping := false
	sentStop := false
	graceTimer := time.NewTimer(time.Duration(math.MaxInt64))

	for !sentStop {
		select {
		case cmd := <-t.commandChan:
			switch cmd {
			case startRequest:
				activeRequests++
			case endRequest:
				activeRequests--
				if stopping && activeRequests == 0 {
					sentStop = t.sendStop(sentStop)
				}
			case shutdown:
				stopping = true
				atomic.StoreInt32(&t.shutdownState, shutDown)
				if activeRequests <= 0 {
					sentStop = t.sendStop(sentStop)
				} else {
					graceTimer.Reset(t.shutdownWait)
				}
			}
		case <-graceTimer.C:
			sentStop = t.sendStop(sentStop)
		}
	}
}
713691
func (s *Reporter) trackRequest(opType OpType, key []byte, endKey []byte) {
	if !s.TrackTopRequests {
		return
	}
	if len(key) == 0 {
		return
	}
	// take just the first two parts, otherwise too many distinct requests
	// can end up in the map
	parts := bytes.Split(key, []byte{Separator})
	if len(parts) > 3 {
		parts = parts[:3]
	}
	rangeSuffix := teleport.TagFalse
	if len(endKey) != 0 {
		// Range denotes range queries in stat entry
		rangeSuffix = teleport.TagTrue
	}
	counter, err := requests.GetMetricWithLabelValues(s.Component, string(bytes.Join(parts, []byte{Separator})), rangeSuffix)
	if err != nil {
		log.Warningf("Failed to get counter: %v", err)
		return
	}
	counter.Inc()
}
533340
func (t *TabletTracker) Track(stats []discovery.TabletStats) *topodatapb.Tablet {
	if len(stats) == 0 {
		panic("stats must not be empty")
	}
	t.mu.Lock()
	defer t.mu.Unlock()

	// Try to find a tablet which is not in use yet.
	for _, stat := range stats {
		key := topoproto.TabletAliasString(stat.Tablet.Alias)
		if _, ok := t.usedTablets[key]; !ok {
			t.usedTablets[key] = 1
			return stat.Tablet
		}
	}

	// If we reached this point, "stats" is a subset of "usedTablets" i.e.
	// all tablets are already in use. Take the least used one.
	for _, aliasString := range t.tabletsByUsage() {
		for _, stat := range stats {
			key := topoproto.TabletAliasString(stat.Tablet.Alias)
			if key == aliasString {
				t.usedTablets[key]++
				return stat.Tablet
			}
		}
	}
	panic("BUG: we did not add any tablet")
}
1020033
func (c *LayeredCache) TrackingGet(primary, secondary string) TrackedItem {
	item := c.Get(primary, secondary)
	if item == nil {
		return NilTracked
	}
	item.track()
	return item
}
550799
func Payloads2TrackArgs(payloads []payload.Payload) params.TrackPayloadArgs {
	var args params.TrackPayloadArgs
	for _, pl := range payloads {
		fullPayload := payload.FullPayloadInfo{Payload: pl}
		arg := api.Payload2api(fullPayload)
		args.Payloads = append(args.Payloads, arg)
	}
	return args
}