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

a1y-developer / doc-formatter / 21928001817

12 Feb 2026 12:02AM UTC coverage: 80.925% (-0.5%) from 81.411%
21928001817

Pull #34

github

web-flow
Merge ebd8293af into 0c863fd2c
Pull Request #34: ValidateToken method added

18 of 23 new or added lines in 3 files covered. (78.26%)

9 existing lines in 1 file now uncovered.

1714 of 2118 relevant lines covered (80.93%)

0.88 hits per line

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

63.33
/pkg/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

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

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

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

64
        return nil
1✔
65
}
66

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

89
        return nil
1✔
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