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)
| 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 |
| 398 | func 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). |
no test coverage detected
searching dependent graphs…