MCPcopy Create free account
hub / github.com/containerd/nerdctl / ResourceUsage

Function ResourceUsage

pkg/imgutil/imgutil.go:398–424  ·  view source on GitHub ↗

ResourceUsage will return: - the Usage value of the resource referenced by ID - the cumulative Usage value of the resource, and all parents, recursively Typically, for a running container, this will equal the size of the read-write layer, plus the sum of the size of all layers in the base image

(ctx context.Context, snapshotter snapshots.Snapshotter, resourceID string)

Source from the content-addressed store, hash-verified

396// - the cumulative Usage value of the resource, and all parents, recursively
397// Typically, for a running container, this will equal the size of the read-write layer, plus the sum of the size of all layers in the base image
398func ResourceUsage(ctx context.Context, snapshotter snapshots.Snapshotter, resourceID string) (snapshots.Usage, snapshots.Usage, error) {
399 first := snapshots.Usage{}
400 total := snapshots.Usage{}
401 var info snapshots.Info
402 for next := resourceID; next != ""; next = info.Parent {
403 // Get the resource usage info
404 usage, err := snapshotter.Usage(ctx, next)
405 if err != nil {
406 return first, total, err
407 }
408 // In case that's the first one, store that
409 if next == resourceID {
410 first = usage
411 }
412 // And increment totals
413 total.Size += usage.Size
414 total.Inodes += usage.Inodes
415
416 // Now, get the parent, if any and iterate
417 info, err = snapshotter.Stat(ctx, next)
418 if err != nil {
419 return first, total, err
420 }
421 }
422
423 return first, total, nil
424}
425
426// UnpackedImageSize is the size of the unpacked snapshots.
427// Does not contain the size of the blobs in the content store. (Corresponds to Docker).

Callers 4

HandlerMethod · 0.92
getContainerSizeFunction · 0.92
readManifestFunction · 0.92
UnpackedImageSizeFunction · 0.85

Calls 2

UsageMethod · 0.80
StatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…