snapshot returns a point-in-time copy of the tracked container list (the slice of *Stats pointers). The returned slice is safe for use without holding the stats lock, but the underlying Stats values may continue to change concurrently.
()
| 54 | // without holding the stats lock, but the underlying Stats values may |
| 55 | // continue to change concurrently. |
| 56 | func (s *stats) snapshot() []*Stats { |
| 57 | s.mu.RLock() |
| 58 | defer s.mu.RUnlock() |
| 59 | if len(s.cs) == 0 { |
| 60 | return nil |
| 61 | } |
| 62 | // https://github.com/golang/go/issues/53643 |
| 63 | cp := make([]*Stats, len(s.cs)) |
| 64 | copy(cp, s.cs) |
| 65 | return cp |
| 66 | } |
| 67 | |
| 68 | func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, streamStats bool, waitFirst *sync.WaitGroup) { //nolint:gocyclo |
| 69 | var getFirst bool |