(ctx context.Context)
| 112 | } |
| 113 | |
| 114 | func (c *profileFlags) stop(ctx context.Context) { |
| 115 | if c.cpuProfileCloser != nil { |
| 116 | c.cpuProfileCloser() |
| 117 | c.cpuProfileCloser = nil |
| 118 | } |
| 119 | |
| 120 | if !c.saveProfiles { |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | if c.profileGCBeforeSaving { |
| 125 | // update profiles, otherwise they may not include activity after the last GC |
| 126 | runtime.GC() |
| 127 | } |
| 128 | |
| 129 | profDir, err := mkSubdirectories(c.outputDirectory, profDirName) |
| 130 | if err != nil { |
| 131 | log(ctx).Warn("cannot create directory to save profiles:", err) |
| 132 | } |
| 133 | |
| 134 | for _, p := range pprof.Profiles() { |
| 135 | func() { |
| 136 | fname := filepath.Join(profDir, p.Name()+".pprof") |
| 137 | |
| 138 | f, err := os.Create(fname) //nolint:gosec |
| 139 | if err != nil { |
| 140 | log(ctx).Warnf("unable to create profile output file '%s': %v", fname, err) |
| 141 | |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | defer func() { |
| 146 | if err := f.Close(); err != nil { |
| 147 | log(ctx).Warnf("unable to close profile output file '%s': %v", fname, err) |
| 148 | } |
| 149 | }() |
| 150 | |
| 151 | if err := p.WriteTo(f, 0); err != nil { |
| 152 | log(ctx).Warnf("unable to write profile to file '%s': %v", fname, err) |
| 153 | } |
| 154 | }() |
| 155 | } |
| 156 | } |
nothing calls this directly
no test coverage detected