mirror of https://github.com/docker/cli.git
cli/command/container: runStats(): don't register unused event handlers
We were unconditionally registering event-handlers for these events, but the handler itself would ignore the event depending on the "all" option. This patch skips registering the event handlers, so that we're not handling them (saving some resources). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
2389768fb7
commit
5ed6c128e8
|
@ -129,15 +129,15 @@ func runStats(ctx context.Context, dockerCLI command.Cli, options *statsOptions)
|
||||||
// would "miss" a creation.
|
// would "miss" a creation.
|
||||||
started := make(chan struct{})
|
started := make(chan struct{})
|
||||||
eh := command.InitEventHandler()
|
eh := command.InitEventHandler()
|
||||||
eh.Handle(events.ActionCreate, func(e events.Message) {
|
if options.all {
|
||||||
if options.all {
|
eh.Handle(events.ActionCreate, func(e events.Message) {
|
||||||
s := NewStats(e.Actor.ID[:12])
|
s := NewStats(e.Actor.ID[:12])
|
||||||
if cStats.add(s) {
|
if cStats.add(s) {
|
||||||
waitFirst.Add(1)
|
waitFirst.Add(1)
|
||||||
go collect(ctx, s, apiClient, !options.noStream, waitFirst)
|
go collect(ctx, s, apiClient, !options.noStream, waitFirst)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
eh.Handle(events.ActionStart, func(e events.Message) {
|
eh.Handle(events.ActionStart, func(e events.Message) {
|
||||||
s := NewStats(e.Actor.ID[:12])
|
s := NewStats(e.Actor.ID[:12])
|
||||||
|
@ -147,11 +147,11 @@ func runStats(ctx context.Context, dockerCLI command.Cli, options *statsOptions)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
eh.Handle(events.ActionDie, func(e events.Message) {
|
if !options.all {
|
||||||
if !options.all {
|
eh.Handle(events.ActionDie, func(e events.Message) {
|
||||||
cStats.remove(e.Actor.ID[:12])
|
cStats.remove(e.Actor.ID[:12])
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
eventChan := make(chan events.Message)
|
eventChan := make(chan events.Message)
|
||||||
go eh.Watch(eventChan)
|
go eh.Watch(eventChan)
|
||||||
|
|
Loading…
Reference in New Issue