// Usage retrieves the disk usage of the top-level snapshot.
13595
func (b *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
	return b.usage(ctx, key)
}
947001
func usage(out io.Writer, a Application, includeAdvanced bool) {
	usageTemplate := `{{.Title}}

Usage:  {{.Name}} [command] [arguments]

Commands:{{range .Commands}}
  {{.Name | printf "%%-%ds"}}  {{.ShortDesc}}{{end}}

{{if .EnvVars}}Environment Variables:{{range .EnvVars}}
  {{.Name | printf "%%-%ds"}}  {{.ShortDesc}}{{if .Default}} (Default: {{.Default | printf "%%q"}}){{end}}{{end}}

{{end}}
Use "{{.Name}} help [command]" for more information about a command.{{if .ShowAdvancedTip}}
Use "{{.Name}} help -advanced" to display all commands.{{end}}

`

	widestCmd := 0
	allCmds := a.GetCommands()
	cmds := make([]*Command, 0, len(allCmds))
	hasAdvanced := false
	for _, c := range allCmds {
		hasAdvanced = hasAdvanced || c.Advanced

		if !c.Advanced || includeAdvanced {
			// We need to include this command
			if namLen := len(c.Name()); namLen > widestCmd {
				widestCmd = namLen
			}
			cmds = append(cmds, c)
		}
	}

	type envVarEntry struct {
		Name      string
		ShortDesc string
		Default   string
	}
	widestEnvVar := 0
	envVars := []envVarEntry(nil)
	if envVarMap := a.GetEnvVars(); len(envVarMap) > 0 {
		envVarKeys := make(sort.StringSlice, 0, len(envVarMap))
		for k, v := range envVarMap {
			if v.Advanced {
				hasAdvanced = true
			}
			if !v.Advanced || includeAdvanced {
				if keyLen := len(k); keyLen > widestEnvVar {
					widestEnvVar = keyLen
				}
				envVarKeys = append(envVarKeys, k)
			}
		}
		envVarKeys.Sort()
		envVars = make([]envVarEntry, 0, len(envVarKeys))
		for _, k := range envVarKeys {
			v := envVarMap[k]
			envVars = append(envVars, envVarEntry{k, v.ShortDesc, v.Default})
		}
	}
	data := map[string]interface{}{
		"Title":           a.GetTitle(),
		"Name":            a.GetName(),
		"Commands":        cmds,
		"EnvVars":         envVars,
		"ShowAdvancedTip": (hasAdvanced && !includeAdvanced),
	}
	tmpl(out, fmt.Sprintf(usageTemplate, widestCmd, widestEnvVar), data)
}
848351
func (daemon *Daemon) SystemDiskUsage(ctx context.Context) (*types.DiskUsage, error) {
	if !atomic.CompareAndSwapInt32(&daemon.diskUsageRunning, 0, 1) {
		return nil, fmt.Errorf("a disk usage operation is already running")
	}
	defer atomic.StoreInt32(&daemon.diskUsageRunning, 0)

	// Retrieve container list
	allContainers, err := daemon.Containers(&types.ContainerListOptions{
		Size: true,
		All:  true,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve container list: %v", err)
	}

	// Get all top images with extra attributes
	allImages, err := daemon.imageService.Images(filters.NewArgs(), false, true)
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve image list: %v", err)
	}

	localVolumes, err := daemon.volumes.LocalVolumesSize(ctx)
	if err != nil {
		return nil, err
	}

	allLayersSize, err := daemon.imageService.LayerDiskUsage(ctx)
	if err != nil {
		return nil, err
	}

	return &types.DiskUsage{
		LayersSize: allLayersSize,
		Containers: allContainers,
		Volumes:    localVolumes,
		Images:     allImages,
	}, nil
}
35926
func (b *Builder) DiskUsage(ctx context.Context) ([]*types.BuildCache, error) {
	duResp, err := b.controller.DiskUsage(ctx, &controlapi.DiskUsageRequest{})
	if err != nil {
		return nil, err
	}

	var items []*types.BuildCache
	for _, r := range duResp.Record {
		items = append(items, &types.BuildCache{
			ID:          r.ID,
			Parent:      r.Parent,
			Type:        r.RecordType,
			Description: r.Description,
			InUse:       r.InUse,
			Shared:      r.Shared,
			Size:        r.Size_,
			CreatedAt:   r.CreatedAt,
			LastUsedAt:  r.LastUsedAt,
			UsageCount:  int(r.UsageCount),
		})
	}
	return items, nil
}
855468
func (q *Quotas) Usage(name string, qo *QueryOptions) (*QuotaUsage, *QueryMeta, error) {
	var resp QuotaUsage
	qm, err := q.client.query("/v1/quota/usage/"+name, &resp, qo)
	if err != nil {
		return nil, nil, err
	}
	return &resp, qm, nil
}
490929
func (r *PortAllocator) Used() int {
	return r.portRange.Size - r.alloc.Free()
}
1323179
func (c *Client) GetUsage(i *GetUsageInput) (*UsageResponse, error) {
	r, err := c.Get("/stats/usage", &RequestOptions{
		Params: map[string]string{
			"from":   i.From,
			"to":     i.To,
			"by":     i.By,
			"region": i.Region,
		},
	})
	if err != nil {
		return nil, err
	}
	var sr *UsageResponse
	if err := decodeJSON(&sr, r.Body); err != nil {
		return nil, err
	}

	return sr, nil
}
1133245
func DiskRestGetUsage(context *gin.Context) {
	body, err := disk.ServiceGetUsage()
	util.RestHandleResponse(context, body, err)
}
1345212
func (s *Server) Use(m Middleware) {
	s.middlewares = append(s.middlewares, m)
}
620193
func (d *Failstore) DiskUsage() (uint64, error) {
	if err := d.errfunc("disk-usage"); err != nil {
		return 0, err
	}
	return ds.DiskUsage(d.child)
}
954439
func (p *serviceEvaluator) Usage(item runtime.Object) (corev1.ResourceList, error) {
	result := corev1.ResourceList{}
	svc, err := toExternalServiceOrError(item)
	if err != nil {
		return result, err
	}
	ports := len(svc.Spec.Ports)
	// default service usage
	result[serviceObjectCountName] = *(resource.NewQuantity(1, resource.DecimalSI))
	result[corev1.ResourceServices] = *(resource.NewQuantity(1, resource.DecimalSI))
	result[corev1.ResourceServicesLoadBalancers] = resource.Quantity{Format: resource.DecimalSI}
	result[corev1.ResourceServicesNodePorts] = resource.Quantity{Format: resource.DecimalSI}
	switch svc.Spec.Type {
	case corev1.ServiceTypeNodePort:
		// node port services need to count node ports
		value := resource.NewQuantity(int64(ports), resource.DecimalSI)
		result[corev1.ResourceServicesNodePorts] = *value
	case corev1.ServiceTypeLoadBalancer:
		// load balancer services need to count node ports and load balancers
		value := resource.NewQuantity(int64(ports), resource.DecimalSI)
		result[corev1.ResourceServicesNodePorts] = *value
		result[corev1.ResourceServicesLoadBalancers] = *(resource.NewQuantity(1, resource.DecimalSI))
	}
	return result, nil
}
225801
func DiskUsage(d Datastore) (uint64, error) {
	persDs, ok := d.(PersistentDatastore)
	if !ok {
		return 0, nil
	}
	return persDs.DiskUsage()
}
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
}
545603
func Usage(format string, a ...interface{}) {
	console.ErrStyle("usage", format, a...)
	os.Exit(BadUsage)
}
384396
func (s *Session) Use(database string) {
	s.mu.Lock()
	defer s.mu.Unlock()

	s.opts.Database = database
}
230753
func (fs *FlagSet) usage() {
	if fs == CommandLine {
		Usage()
	} else if fs.Usage == nil {
		defaultUsage(fs)
	} else {
		fs.Usage()
	}
}
791677
func (s *Service) Usage() {
	fmt.Printf("Usage of %s\n", os.Args[0])
	if s.commands["help"] != nil {
		fmt.Printf("    %-16s %s\n", "help", s.commands["help"].ShortUsage)
	}
	if s.commands["start"] != nil {
		fmt.Printf("    %-16s %s\n", "start", s.commands["start"].ShortUsage)
	}
	for k, cmd := range s.commands {
		if k == "start" || k == "help" {
			continue
		}
		fmt.Printf("    %-16s %s\n", k, cmd.ShortUsage)
	}
}