// update scans procs and updates metrics for those which are tracked. Processes
// that have gone away get removed from the Tracked map. New processes are
// returned, along with the count of nonfatal errors.
765411
func (t *Tracker) update(procs Iter) ([]IDInfo, CollectErrors, error) {
	var newProcs []IDInfo
	var colErrs CollectErrors
	var now = time.Now()

	for procs.Next() {
		newProc, cerrs := t.handleProc(procs, now)
		if newProc != nil {
			newProcs = append(newProcs, *newProc)
		}
		colErrs.Read += cerrs.Read
		colErrs.Partial += cerrs.Partial
	}

	err := procs.Close()
	if err != nil {
		return nil, colErrs, fmt.Errorf("Error reading procs: %v", err)
	}

	// Rather than allocating a new map each time to detect procs that have
	// disappeared, we bump the last update time on those that are still
	// present.  Then as a second pass we traverse the map looking for
	// stale procs and removing them.
	for procID, pinfo := range t.tracked {
		if pinfo == nil {
			// TODO is this a bug? we're not tracking the proc so we don't see it go away so ProcIds
			// and Tracked are leaking?
			continue
		}
		if pinfo.lastUpdate != now {
			delete(t.tracked, procID)
			delete(t.procIds, procID.Pid)
		}
	}

	return newProcs, colErrs, nil
}
265434
func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
	// We want time spent per-cpu per CPUSTATE.
	// CPUSTATES (number of CPUSTATES) is defined as 5U.
	// Order: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR
	// sysctl kern.cp_times provides hw.ncpu * CPUSTATES long integers:
	//   hw.ncpu * (space-separated list of the above variables)
	//
	// Each value is a counter incremented at frequency
	//   kern.clockrate.(stathz | hz)
	//
	// Look into sys/kern/kern_clock.c for details.

	cpuTimes, err := getCPUTimes()
	if err != nil {
		return err
	}
	for cpu, t := range cpuTimes {
		lcpu := strconv.Itoa(cpu)
		ch <- c.cpu.mustNewConstMetric(float64(t.user), lcpu, "user")
		ch <- c.cpu.mustNewConstMetric(float64(t.nice), lcpu, "nice")
		ch <- c.cpu.mustNewConstMetric(float64(t.sys), lcpu, "system")
		ch <- c.cpu.mustNewConstMetric(float64(t.intr), lcpu, "interrupt")
		ch <- c.cpu.mustNewConstMetric(float64(t.idle), lcpu, "idle")

		temp, err := unix.SysctlUint32(fmt.Sprintf("dev.cpu.%d.temperature", cpu))
		if err != nil {
			if err == unix.ENOENT {
				// No temperature information for this CPU
				log.Debugf("no temperature information for CPU %d", cpu)
			} else {
				// Unexpected error
				ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu)
				log.Errorf("failed to query CPU temperature for CPU %d: %s", cpu, err)
			}
			continue
		}

		// Temp is a signed integer in deci-degrees Kelvin.
		// Cast uint32 to int32 and convert to float64 degrees Celsius.
		//
		// 2732 is used as the conversion constant for deci-degrees
		// Kelvin, in multiple places in the kernel that feed into this
		// sysctl, so we want to maintain consistency:
		//
		// sys/dev/amdtemp/amdtemp.c
		//   #define AMDTEMP_ZERO_C_TO_K 2732
		//
		// sys/dev/acpica/acpi_thermal.c
		//   #define TZ_ZEROC            2732
		//
		// sys/dev/coretemp/coretemp.c
		//   #define TZ_ZEROC            2732
		ch <- c.temp.mustNewConstMetric(float64(int32(temp)-2732)/10, lcpu)
	}
	return err
}
819429
func (s *Simple) Update(key string) {
	atomic.AddInt64(&s.stats.Updates, 1)
	atv := s.getOrCreateAtomicTimedValue(key)
	s.update(key, atv)
}
887358
func (p *Controller) Update(ctx context.Context, t *api.Task) error {
	p.logger.Debug("Update")
	return nil
}
808698
func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error {
	for _, m := range c.sysctls {
		v, err := m.Value()
		if err != nil {
			return fmt.Errorf("couldn't get memory: %s", err)
		}

		// Most are gauges.
		if m.valueType == 0 {
			m.valueType = prometheus.GaugeValue
		}

		ch <- prometheus.MustNewConstMetric(
			prometheus.NewDesc(
				prometheus.BuildFQName(namespace, memorySubsystem, m.name),
				m.description,
				nil, nil,
			), m.valueType, v)
	}

	swapUsed, err := c.kvm.SwapUsedPages()
	if err != nil {
		return fmt.Errorf("couldn't get kvm: %s", err)
	}

	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName(namespace, memorySubsystem, "swap_used_bytes"),
			"Currently allocated swap",
			nil, nil,
		), prometheus.GaugeValue, float64(swapUsed*c.pageSize))

	return nil
}
722236
func (m *Mercury) Update(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
	return m.BatchUpdate(ctx, map[string]string{key: val}, opts...)
}
982254
func (command S3LambdaEventSourceResource) Update(awsSession *session.Session,
	event *CloudFormationLambdaEvent,
	logger *logrus.Logger) (map[string]interface{}, error) {
	return command.updateNotification(true, awsSession, event, logger)
}
198606
func (s *SessionStatsCollector) Update(id int64, delta int64, count int64, colSize *map[int64]int64) {
	s.Lock()
	defer s.Unlock()
	s.mapper.update(id, delta, count, colSize)
}
613115
func (su *StatusUpdater) Update(status interface{}) {
	su.Status = status.(string)

	// initialize event ID
	if su.EventID == 0 {
		su.EventID = time.Now().UnixNano()
	}
}
693217
func (nn *FeedForward) Update(inputs []float64) []float64 {
	if len(inputs) != nn.NInputs-1 {
		log.Fatal("Error: wrong number of inputs")
	}

	for i := 0; i < nn.NInputs-1; i++ {
		nn.InputActivations[i] = inputs[i]
	}

	for i := 0; i < nn.NHiddens-1; i++ {
		var sum float64

		for j := 0; j < nn.NInputs; j++ {
			sum += nn.InputActivations[j] * nn.InputWeights[j][i]
		}

		// compute contexts sum
		for k := 0; k < len(nn.Contexts); k++ {
			for j := 0; j < nn.NHiddens-1; j++ {
				sum += nn.Contexts[k][j]
			}
		}

		nn.HiddenActivations[i] = sigmoid(sum)
	}

	// update the contexts
	if len(nn.Contexts) > 0 {
		for i := len(nn.Contexts) - 1; i > 0; i-- {
			nn.Contexts[i] = nn.Contexts[i-1]
		}
		nn.Contexts[0] = nn.HiddenActivations
	}

	for i := 0; i < nn.NOutputs; i++ {
		var sum float64
		for j := 0; j < nn.NHiddens; j++ {
			sum += nn.HiddenActivations[j] * nn.OutputWeights[j][i]
		}

		nn.OutputActivations[i] = sigmoid(sum)
	}

	return nn.OutputActivations
}
3561
func (tracker *VoteTracker) update(voteInfo *dcrjson.GetVoteInfoResult, blocks []int32,
	stakeInfo *dcrjson.GetStakeVersionInfoResult, stakeVersion uint32) {
	// Check if voteCounts are needed
	for idx := range voteInfo.Agendas {
		agenda := &voteInfo.Agendas[idx]
		if agenda.Status != statusDefined && agenda.Status != statusStarted {
			// check the cache
			counts := tracker.cachedCounts(agenda.ID)
			if counts == nil {
				counts = new(voteCount)
				var err error
				counts.yes, counts.abstain, counts.no, err = tracker.voteCounter(agenda.ID)
				if err != nil {
					log.Errorf("Error counting votes for %s: %v", agenda.ID, err)
					continue
				}
				tracker.cacheVoteCounts(agenda.ID, counts)
			}
			for idx := range agenda.Choices {
				choice := &agenda.Choices[idx]
				if choice.ID == choiceYes {
					choice.Count = counts.yes
				} else if choice.ID == choiceNo {
					choice.Count = counts.no
				} else {
					choice.Count = counts.abstain
				}
			}
		}
	}
	tracker.mtx.Lock()
	defer tracker.mtx.Unlock()
	tracker.voteInfo = voteInfo
	tracker.stakeInfo = stakeInfo
	ringLen := int(tracker.params.BlockUpgradeNumToCheck)
	for idx := range blocks {
		tracker.ringIndex = (tracker.ringIndex + 1) % ringLen
		tracker.blockRing[tracker.ringIndex] = blocks[idx]
	}
	tracker.blockVersion = tracker.blockRing[tracker.ringIndex]
	tracker.stakeVersion = stakeVersion
	tracker.ringHeight = voteInfo.CurrentHeight
	tracker.summary = tracker.newVoteSummary()
}
375629
func (c *projects) Update(projectResource *project.Project) (result *project.Project, err error) {
	result = &project.Project{}
	err = c.client.Put().
		Resource("projects").
		Name(projectResource.Name).
		Body(projectResource).
		Do().
		Into(result)
	return
}
1060876
func (c *Counter) Update(v int64) {
	atomic.AddInt64(&c.count, v)
}
1003204
func (tm *taskManager) Update(ctx context.Context, task *api.Task) error {
	select {
	case tm.updateq <- task:
		return nil
	case <-tm.closed:
		return ErrClosed
	case <-ctx.Done():
		return ctx.Err()
	}
}
717089
func (s *Server) Update(ctx context.Context, q *ClusterUpdateRequest) (*appv1.Cluster, error) {
	if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionUpdate, q.Cluster.Server); err != nil {
		return nil, err
	}
	err := kube.TestConfig(q.Cluster.RESTConfig())
	if err != nil {
		return nil, err
	}
	clust, err := s.db.UpdateCluster(ctx, q.Cluster)
	return redact(clust), err
}
252025
func (c *CompletionManager) Update(in Document) {
	c.tmp = c.completer(in)
	return
}
573234
func (pb *ProgressBar) Update() {
	c := atomic.LoadInt64(&pb.current)
	p := atomic.LoadInt64(&pb.previous)
	t := atomic.LoadInt64(&pb.Total)
	if p != c {
		pb.mu.Lock()
		pb.changeTime = time.Now()
		pb.mu.Unlock()
		atomic.StoreInt64(&pb.previous, c)
	}
	pb.write(t, c)
	if pb.AutoStat {
		if c == 0 {
			pb.startTime = time.Now()
			pb.startValue = 0
		} else if c >= t && pb.isFinish != true {
			pb.Finish()
		}
	}
}