sigs.k8s.io/kueue@v0.6.2/pkg/debugger/debugger.go (about) 1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package debugger 18 19 import ( 20 "context" 21 "os" 22 "os/signal" 23 "syscall" 24 25 ctrl "sigs.k8s.io/controller-runtime" 26 27 "sigs.k8s.io/kueue/pkg/cache" 28 "sigs.k8s.io/kueue/pkg/queue" 29 ) 30 31 type Dumper struct { 32 cache *cache.Cache 33 queues *queue.Manager 34 } 35 36 func NewDumper(c *cache.Cache, q *queue.Manager) *Dumper { 37 return &Dumper{cache: c, queues: q} 38 } 39 40 // ListenForSignal starts a goroutine that will trigger the Dumper's 41 // behavior when the process receives SIGUSR2. 42 func (d *Dumper) ListenForSignal(ctx context.Context) { 43 signalCh := make(chan os.Signal, 1) 44 signal.Notify(signalCh, syscall.SIGUSR2) 45 go func() { 46 for { 47 select { 48 case <-ctx.Done(): 49 return 50 case <-signalCh: 51 d.DumpAll(ctx) 52 } 53 } 54 }() 55 } 56 57 func (d *Dumper) DumpAll(ctx context.Context) { 58 log := ctrl.LoggerFrom(ctx).WithName("dumper") 59 log.Info("Started dump") 60 snap := d.cache.Snapshot() 61 snap.Log(log) 62 d.queues.LogDump(log) 63 log.Info("Ended dump") 64 }