• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 21656192014

04 Feb 2026 02:35AM UTC coverage: 23.031% (-0.02%) from 23.05%
21656192014

push

github

web-flow
refactor: profiling, Retry, assignAddress, runIfLinkExists (#6258)

- Add pkg/util/profiling with DumpProfile(); use from cmd/cmdmain.go and cmd/controller/cmdmain.go
- cmd/cmdmain.go: remove local dumpProfile, use profiling.DumpProfile()
- cmd/controller/cmdmain.go: remove duplicated dumpProfile, use profiling.DumpProfile()
- cmd/daemon/cniserver.go: Retry param ctrl->cfg, return nil on success
- cmd/daemon/init.go: add runIfLinkExists helper for initForOS and setVxlanNicTxOff
- cmd/cni/cni.go: assignAddress(ipAddress, gateway, protocol, mask), merge IPv4/IPv6 case in generateCNIResult

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>

0 of 50 new or added lines in 2 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

12416 of 53909 relevant lines covered (23.03%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/util/profiling/profiling.go
1
package profiling
2

3
import (
4
        "fmt"
5
        "os"
6
        "os/signal"
7
        "path/filepath"
8
        "runtime/pprof"
9
        "syscall"
10
        "time"
11

12
        "k8s.io/klog/v2"
13
)
14

15
const (
16
        timeFormat         = "2006-01-02_15:04:05"
17
        CPUProfileDuration = 30 * time.Second
18
)
19

NEW
20
func writeProfileToTemp(pattern string, writeFn func(*os.File) error) {
×
NEW
21
        path := filepath.Join(os.TempDir(), fmt.Sprintf(pattern, time.Now().Format(timeFormat)))
×
NEW
22
        f, err := os.Create(path) // #nosec G303,G304
×
NEW
23
        if err != nil {
×
NEW
24
                klog.Errorf("failed to create profile file: %v", err)
×
NEW
25
                return
×
NEW
26
        }
×
NEW
27
        defer func() {
×
NEW
28
                if err := f.Close(); err != nil {
×
NEW
29
                        klog.Errorf("failed to close file %q: %v", path, err)
×
NEW
30
                }
×
31
        }()
NEW
32
        if err := writeFn(f); err != nil {
×
NEW
33
                klog.Errorf("failed to write profile: %v", err)
×
NEW
34
        }
×
35
}
36

37
// DumpProfile starts a goroutine that handles SIGUSR1 (CPU profile) and SIGUSR2 (heap profile).
NEW
38
func DumpProfile() {
×
NEW
39
        ch := make(chan os.Signal, 1)
×
NEW
40
        signal.Notify(ch, syscall.SIGUSR1, syscall.SIGUSR2)
×
NEW
41
        go func() {
×
NEW
42
                for sig := range ch {
×
NEW
43
                        switch sig {
×
NEW
44
                        case syscall.SIGUSR1:
×
NEW
45
                                writeProfileToTemp("cpu-profile-%s.pprof", func(f *os.File) error {
×
NEW
46
                                        if err := pprof.StartCPUProfile(f); err != nil {
×
NEW
47
                                                return err
×
NEW
48
                                        }
×
NEW
49
                                        time.Sleep(CPUProfileDuration)
×
NEW
50
                                        pprof.StopCPUProfile()
×
NEW
51
                                        return nil
×
52
                                })
NEW
53
                        case syscall.SIGUSR2:
×
NEW
54
                                writeProfileToTemp("mem-profile-%s.pprof", func(f *os.File) error {
×
NEW
55
                                        return pprof.WriteHeapProfile(f)
×
NEW
56
                                })
×
57
                        }
58
                }
59
        }()
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc