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

a1y-developer / doc-formatter / 20651112757

02 Jan 2026 04:49AM UTC coverage: 74.257% (-5.6%) from 79.901%
20651112757

Pull #28

github

web-flow
Merge 405e32efb into ba5d98a5b
Pull Request #28: feat: root cmd

0 of 137 new or added lines in 3 files covered. (0.0%)

1125 of 1515 relevant lines covered (74.26%)

0.81 hits per line

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

0.0
/cmd/profiling.go
1
package cmd
2

3
import (
4
        "fmt"
5
        "os"
6
        "os/signal"
7
        "runtime"
8
        "runtime/pprof"
9

10
        "github.com/spf13/pflag"
11
)
12

13
var (
14
        profileName   string
15
        profileOutput string
16
)
17

NEW
18
func addProfilingFlags(flags *pflag.FlagSet) {
×
NEW
19
        flags.StringVar(&profileName, "profile", "none", "Name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex)")
×
NEW
20
        flags.StringVar(&profileOutput, "profile-output", "profile.pprof", "Name of the file to write the profile to")
×
NEW
21
}
×
22

NEW
23
func initProfiling() error {
×
NEW
24
        var (
×
NEW
25
                f   *os.File
×
NEW
26
                err error
×
NEW
27
        )
×
NEW
28
        switch profileName {
×
NEW
29
        case "none":
×
NEW
30
                return nil
×
NEW
31
        case "cpu":
×
NEW
32
                f, err = os.Create(profileOutput)
×
NEW
33
                if err != nil {
×
NEW
34
                        return err
×
NEW
35
                }
×
NEW
36
                err = pprof.StartCPUProfile(f)
×
NEW
37
                if err != nil {
×
NEW
38
                        return err
×
NEW
39
                }
×
40
        // Block and mutex profiles need a call to Set{Block,Mutex}ProfileRate to
41
        // output anything. We choose to sample all events.
NEW
42
        case "block":
×
NEW
43
                runtime.SetBlockProfileRate(1)
×
NEW
44
        case "mutex":
×
NEW
45
                runtime.SetMutexProfileFraction(1)
×
NEW
46
        default:
×
NEW
47
                // Check the profile name is valid.
×
NEW
48
                if profile := pprof.Lookup(profileName); profile == nil {
×
NEW
49
                        return fmt.Errorf("unknown profile '%s'", profileName)
×
NEW
50
                }
×
51
        }
52

53
        // If the command is interrupted before the end (ctrl-c), flush the
54
        // profiling files
NEW
55
        c := make(chan os.Signal, 1)
×
NEW
56
        signal.Notify(c, os.Interrupt)
×
NEW
57
        go func() {
×
NEW
58
                <-c
×
NEW
59
                f.Close()
×
NEW
60
                flushProfiling()
×
NEW
61
                os.Exit(0)
×
NEW
62
        }()
×
63

NEW
64
        return nil
×
65
}
66

NEW
67
func flushProfiling() error {
×
NEW
68
        switch profileName {
×
NEW
69
        case "none":
×
NEW
70
                return nil
×
NEW
71
        case "cpu":
×
NEW
72
                pprof.StopCPUProfile()
×
NEW
73
        case "heap":
×
NEW
74
                runtime.GC()
×
NEW
75
                fallthrough
×
NEW
76
        default:
×
NEW
77
                profile := pprof.Lookup(profileName)
×
NEW
78
                if profile == nil {
×
NEW
79
                        return nil
×
NEW
80
                }
×
NEW
81
                f, err := os.Create(profileOutput)
×
NEW
82
                if err != nil {
×
NEW
83
                        return err
×
NEW
84
                }
×
NEW
85
                defer f.Close()
×
NEW
86
                profile.WriteTo(f, 0)
×
87
        }
88

NEW
89
        return nil
×
90
}
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