// runtimeStats is used to return various runtime information
335117
func runtimeStats() map[string]string {
	return map[string]string{
		"os":         runtime.GOOS,
		"arch":       runtime.GOARCH,
		"version":    runtime.Version(),
		"max_procs":  strconv.FormatInt(int64(runtime.GOMAXPROCS(0)), 10),
		"goroutines": strconv.FormatInt(int64(runtime.NumGoroutine()), 10),
		"cpu_count":  strconv.FormatInt(int64(runtime.NumCPU()), 10),
	}
}
385809
func (s *Server) ContainerStats(ctx context.Context, req *pb.ContainerStatsRequest) (resp *pb.ContainerStatsResponse, err error) {
	const operation = "container_stats"
	defer func() {
		recordOperation(operation, time.Now())
		recordError(operation, err)
	}()

	container := s.GetContainer(req.ContainerId)
	if container == nil {
		return nil, fmt.Errorf("invalid container")
	}

	stats, err := s.Runtime().ContainerStats(container)
	if err != nil {
		return nil, err
	}

	return &pb.ContainerStatsResponse{Stats: buildContainerStats(stats, container)}, nil
}
1072452
func (p *BulkProcessor) Stats() BulkProcessorStats {
	p.statsMu.Lock()
	defer p.statsMu.Unlock()
	return *p.stats.dup()
}
1220413
func (a *ReqLatencyCounter) ModStats(ctx context.Context) {
	a.ModStatsTime(RequestTime(ctx))
}
865794
func GetStats() (stats Stats, err error) {
	stats.TotalRAM, err = getHwPhysmem()
	return stats, err
}
393204
func (r *Runc) Stats(context context.Context, id string) (*Stats, error) {
	cmd := r.command(context, "events", "--stats", id)
	rd, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	ec, err := Monitor.Start(cmd)
	if err != nil {
		return nil, err
	}
	defer func() {
		rd.Close()
		Monitor.Wait(cmd, ec)
	}()
	var e Event
	if err := json.NewDecoder(rd).Decode(&e); err != nil {
		return nil, err
	}
	return e.Stats, nil
}
1285582
func memoryStats() (*memory, error) {
	mstat := struct {
		size      uint32
		_         uint32
		totalPhys uint64
		availPhys uint64
		_         [5]uint64
	}{}

	// windows sets return value to 0 when function fails.
	mstat.size = uint32(unsafe.Sizeof(mstat))
	ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mstat)))
	if ret == 0 {
		return nil, err
	}

	// memoryStats functions from other platforms return memory usage in bytes.
	return &memory{
		Usage: mstat.totalPhys - mstat.availPhys,
		Total: mstat.totalPhys,
	}, nil

}
29299
func bufferStats(us []uint32) (BufferStats, error) {
	if l := len(us); l != 9 {
		return BufferStats{}, fmt.Errorf("incorrect number of values for XFS buffer stats: %d", l)
	}

	return BufferStats{
		Get:             us[0],
		Create:          us[1],
		GetLocked:       us[2],
		GetLockedWaited: us[3],
		BusyLocked:      us[4],
		MissLocked:      us[5],
		PageRetries:     us[6],
		PageFound:       us[7],
		GetRead:         us[8],
	}, nil
}
246220
func RunningTime(pid int) int64 {
	upTimeFile, err := os.Open("/proc/uptime")
	if err != nil {
		panic(err)
	}
	defer upTimeFile.Close()
	bs, err := ioutil.ReadAll(upTimeFile)
	if err != nil {
		panic(err)
	}
	//uptime is first paramater in uptime file
	upTime, err := strconv.ParseFloat(strings.Split(string(bs), " ")[0], 64)
	if err != nil {
		panic(err)
	}
	stat, err := os.Open("/proc/" + strconv.Itoa(pid) + "/stat")
	if err != nil {
		panic(err)
	}
	defer stat.Close()
	bs, err = ioutil.ReadAll(stat)
	if err != nil {
		panic(err)
	}
	//startTime is 22nd paramater in the stat file
	startTime, err := strconv.ParseInt(strings.Split(string(bs), " ")[21], 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(upTime*1000) - int64(startTime*1000)/sc_clk_tck
}
335776
func (c *StatsConnection) GetInterfaceStats() (*api.InterfaceStats, error) {
	stats, err := c.statsClient.DumpStats(InterfaceStatsPrefix)
	if err != nil {
		return nil, err
	}

	ifStats := &api.InterfaceStats{}

	var setPerIf = func(perIf []uint64, fn func(c *api.InterfaceCounters, v uint64)) {
		if ifStats.Interfaces == nil {
			ifStats.Interfaces = make([]api.InterfaceCounters, len(perIf))
			for i := range perIf {
				ifStats.Interfaces[i].InterfaceIndex = uint32(i)
			}
		}
		for i, v := range perIf {
			if len(ifStats.Interfaces) <= i {
				break
			}
			ifCounters := ifStats.Interfaces[i]
			fn(&ifCounters, v)
			ifStats.Interfaces[i] = ifCounters
		}
	}

	for _, stat := range stats {
		switch stat.Name {
		case InterfaceStats_Names:
			if names, ok := stat.Data.(adapter.NameStat); !ok {
				return nil, fmt.Errorf("invalid stat type for %s", stat.Name)
			} else {
				if ifStats.Interfaces == nil {
					ifStats.Interfaces = make([]api.InterfaceCounters, len(names))
					for i := range names {
						ifStats.Interfaces[i].InterfaceIndex = uint32(i)
					}
				}
				for i, name := range names {
					ifStats.Interfaces[i].InterfaceName = string(name)
				}
			}
		case InterfaceStats_Drops:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.Drops = v
			})
		case InterfaceStats_Punt:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.Punts = v
			})
		case InterfaceStats_IP4:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.IP4 = v
			})
		case InterfaceStats_IP6:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.IP6 = v
			})
		case InterfaceStats_RxNoBuf:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.RxNoBuf = v
			})
		case InterfaceStats_RxMiss:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.RxMiss = v
			})
		case InterfaceStats_RxError:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.RxErrors = v
			})
		case InterfaceStats_TxError:
			setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
				c.TxErrors = v
			})
		case InterfaceStats_Rx:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.RxPackets = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.RxBytes = v
			})
		case InterfaceStats_RxUnicast:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.RxUnicast[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.RxUnicast[1] = v
			})
		case InterfaceStats_RxMulticast:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.RxMulticast[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.RxMulticast[1] = v
			})
		case InterfaceStats_RxBroadcast:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.RxBroadcast[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.RxBroadcast[1] = v
			})
		case InterfaceStats_Tx:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.TxPackets = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.TxBytes = v
			})
		case InterfaceStats_TxUnicastMiss:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.TxUnicastMiss[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.TxUnicastMiss[1] = v
			})
		case InterfaceStats_TxMulticast:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.TxMulticast[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.TxMulticast[1] = v
			})
		case InterfaceStats_TxBroadcast:
			per := reduceCombinedCounterStat(stat.Data)
			setPerIf(per[0], func(c *api.InterfaceCounters, v uint64) {
				c.TxBroadcast[0] = v
			})
			setPerIf(per[1], func(c *api.InterfaceCounters, v uint64) {
				c.TxBroadcast[1] = v
			})
		}
	}

	return ifStats, nil
}
472602
func (bs *benchmarkServer) getStats(reset bool) *testpb.ServerStats {
	bs.mu.RLock()
	defer bs.mu.RUnlock()
	wallTimeElapsed := time.Since(bs.lastResetTime).Seconds()
	rusageLatest := syscall.GetRusage()
	uTimeElapsed, sTimeElapsed := syscall.CPUTimeDiff(bs.rusageLastReset, rusageLatest)

	if reset {
		bs.lastResetTime = time.Now()
		bs.rusageLastReset = rusageLatest
	}
	return &testpb.ServerStats{
		TimeElapsed: wallTimeElapsed,
		TimeUser:    uTimeElapsed,
		TimeSystem:  sTimeElapsed,
	}
}
914668
func (a *StatsAdapter)  DumpStats(patterns ...string) ([]*adapter.StatEntry, error) {
	return a.entries, nil
}
737453
func LogStats() {
	var m runtime.MemStats
	runtime.ReadMemStats(&m)
	log.Infof("Alloc=%v TotalAlloc=%v Sys=%v NumGC=%v Goroutines=%d",
		m.Alloc/1024, m.TotalAlloc/1024, m.Sys/1024, m.NumGC, runtime.NumGoroutine())

}
1206931
func NewLogStats(ctx context.Context, methodName string) *LogStats {
	return &LogStats{
		Ctx:       ctx,
		Method:    methodName,
		StartTime: time.Now(),
	}
}
1023074
func (r *runtimeOCI) ContainerStats(c *Container) (*ContainerStats, error) {
	c.opLock.Lock()
	defer c.opLock.Unlock()

	return r.containerStats(c)
}
376329
func (client *Client) GetRunstatusService(ctx context.Context, service RunstatusService) (*RunstatusService, error) {
	if service.URL != "" {
		return client.getRunstatusService(ctx, service.URL)
	}

	if service.PageURL == "" {
		return nil, fmt.Errorf("empty Page URL in %#v", service)
	}

	page, err := client.getRunstatusPage(ctx, service.PageURL)
	if err != nil {
		return nil, err
	}

	for i := range page.Services {
		s := &page.Services[i]
		if s.Match(service) {
			if err := s.FakeID(); err != nil {
				log.Printf("bad fake ID for %#v, %s", s, err)
			}
			return s, nil
		}
	}

	return nil, fmt.Errorf("%#v not found", service)
}
503540
func (la *LogicalApply) DeriveStats(childStats []*property.StatsInfo) (*property.StatsInfo, error) {
	leftProfile := childStats[0]
	la.stats = &property.StatsInfo{
		RowCount:    leftProfile.RowCount,
		Cardinality: make([]float64, la.schema.Len()),
	}
	copy(la.stats.Cardinality, leftProfile.Cardinality)
	if la.JoinType == LeftOuterSemiJoin || la.JoinType == AntiLeftOuterSemiJoin {
		la.stats.Cardinality[len(la.stats.Cardinality)-1] = 2.0
	} else {
		for i := la.children[0].Schema().Len(); i < la.schema.Len(); i++ {
			la.stats.Cardinality[i] = leftProfile.RowCount
		}
	}
	return la.stats, nil
}