// DiskUsage reports how much data is allocated by the cache
438345
func (fsc *FSCache) DiskUsage(ctx context.Context) (int64, error) {
	return fsc.store.DiskUsage(ctx)
}
1133245
func DiskRestGetUsage(context *gin.Context) {
	body, err := disk.ServiceGetUsage()
	util.RestHandleResponse(context, body, err)
}
643392
func (d *Datastore) DiskUsage() (uint64, error) {
	if d.path == "" { // in-mem
		return 0, nil
	}

	var du uint64

	err := filepath.Walk(d.path, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		du += uint64(info.Size())
		return nil
	})

	if err != nil {
		return 0, err
	}

	return du, nil
}
696
func GetUsage() Usage {
	memStats := new(runtime.MemStats)
	runtime.ReadMemStats(memStats)
	return Usage{
		Mem: memStats.Sys,
	}
}
1031900
func (db *Database) Size() (common.StorageSize, common.StorageSize) {
	db.lock.RLock()
	defer db.lock.RUnlock()

	// db.dirtiesSize only contains the useful data in the cache, but when reporting
	// the total memory consumption, the maintenance metadata is also needed to be
	// counted.
	var metadataSize = common.StorageSize((len(db.dirties) - 1) * cachedNodeSize)
	var metarootRefs = common.StorageSize(len(db.dirties[common.Hash{}].children) * (common.HashLength + 2))
	return db.dirtiesSize + db.childrenSize + metadataSize - metarootRefs, db.preimagesSize
}
1308066
func updateUsage(v *Varz) {
	var rss, vss int64
	var pcpu float64

	pse.ProcUsage(&pcpu, &rss, &vss)

	v.Mem = rss
	v.CPU = pcpu
	v.Cores = numCores
}
252155
func (s *BulkProcessorService) BulkSize(bulkSize int) *BulkProcessorService {
	s.bulkSize = bulkSize
	return s
}
829493
func (d *Datastore) DiskUsage() (uint64, error) {
	var size uint64
	err := d.runOp(func() error {
		var err error
		size, err = ds.DiskUsage(d.Batching)
		return err
	})
	return size, err
}
662498
func (v *volumeClient) CapacityUsage(
	ID string,
) (*api.CapacityUsageResponse, error) {
	requests := &api.CapacityUsageResponse{}
	resp := v.c.Get().Resource(volumePath + "/usage").Instance(ID).Do()

	if resp.Error() != nil {
		return nil, resp.FormatError()
	}

	if err := resp.Unmarshal(requests); err != nil {
		return nil, err
	}

	return requests, nil
}
865963
func containerUsage(podStats statsapi.PodStats, statsToMeasure []fsStatsType) v1.ResourceList {
	disk := resource.Quantity{Format: resource.BinarySI}
	inodes := resource.Quantity{Format: resource.DecimalSI}
	for _, container := range podStats.Containers {
		if hasFsStatsType(statsToMeasure, fsStatsRoot) {
			disk.Add(*diskUsage(container.Rootfs))
			inodes.Add(*inodeUsage(container.Rootfs))
		}
		if hasFsStatsType(statsToMeasure, fsStatsLogs) {
			disk.Add(*diskUsage(container.Logs))
			inodes.Add(*inodeUsage(container.Logs))
		}
	}
	return v1.ResourceList{
		v1.ResourceEphemeralStorage: disk,
		resourceInodes:              inodes,
	}
}
472510
func (o *Organization) GetDiskUsage() int {
	if o == nil || o.DiskUsage == nil {
		return 0
	}
	return *o.DiskUsage
}
1227850
func (md *metricsDu) runDiskUsage(metrics *Metrics) error {
	used, err := fs.DiskUsage(md.path)
	if err != nil {
		return err
	}
	metrics.Used = used
	return nil
}
981226
func (r *Cache) Capacity() int {
	if r.cacher == nil {
		return 0
	}
	return r.cacher.Capacity()
}
1202545
func (c *Chunk) MemoryUsage() (sum int64) {
	for _, col := range c.columns {
		curColMemUsage := int64(unsafe.Sizeof(*col)) + int64(cap(col.nullBitmap)) + int64(cap(col.offsets)*4) + int64(cap(col.data)) + int64(cap(col.elemBuf))
		sum += curColMemUsage
	}
	return
}
310274
func (c *DiskTokenCache) writeCacheFile(cache *cacheFile, now time.Time) error {
	// Throw away old entries.
	cleaned := *cache
	cleaned.Cache = make([]*cacheFileEntry, 0, len(cache.Cache))
	cleaned.LastUpdate = now
	for _, entry := range cache.Cache {
		if entry.isOld(now) {
			logging.Debugf(c.Context, "Cleaning up old token cache entry: %s", entry.Key.Key)
		} else {
			cleaned.Cache = append(cleaned.Cache, entry)
		}
	}

	// Nothing left? Remove the file completely.
	if len(cleaned.Cache) == 0 {
		if err := os.Remove(c.absPath()); err != nil && !os.IsNotExist(err) {
			return err
		}
		return nil
	}

	blob, err := json.MarshalIndent(cleaned, "", "  ")
	if err != nil {
		return err
	}

	// Write to temp file first.
	if err := os.MkdirAll(c.SecretsDir, 0700); err != nil {
		logging.WithError(err).Warningf(c.Context, "Failed to mkdir token cache dir")
		// carry on, TempFile will fail too.
	}
	tmp, err := ioutil.TempFile(c.SecretsDir, CacheFilename)
	if err != nil {
		return err
	}

	cleanup := func() {
		if err := os.Remove(tmp.Name()); err != nil {
			logging.WithError(err).Warningf(c.Context, "Failed to remove temp creds cache file: %s", tmp.Name())
		}
	}

	_, writeErr := tmp.Write(blob)
	closeErr := tmp.Close()
	switch {
	case writeErr != nil:
		err = writeErr
	case closeErr != nil:
		err = closeErr
	}
	if err != nil {
		cleanup()
		return err
	}

	// Note that TempFile creates the file in 0600 mode already, so we don't need
	// to chmod it.
	//
	// On Windows Rename may fail with sharing violation error if some other
	// process has opened the file. We treat it as transient error, to trigger
	// a retry in updateCacheFile.
	if err = os.Rename(tmp.Name(), c.absPath()); err != nil {
		cleanup()
		return transient.Tag.Apply(err)
	}
	return nil
}
1295112
func (m *MockVolumeDriver) CapacityUsage(arg0 string) (*api.CapacityUsageResponse, error) {
	ret := m.ctrl.Call(m, "CapacityUsage", arg0)
	ret0, _ := ret[0].(*api.CapacityUsageResponse)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1037871
func Serialize(u *structs.DiskUsage) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(u), nil
}