Update to Go 1.21, only produce single profile
This commit is contained in:
parent
b322f65c8b
commit
27345e42a5
71
collector.go
71
collector.go
|
@ -4,12 +4,12 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
pprofile "github.com/google/pprof/profile"
|
||||
"golang.org/x/exp/slices"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -32,6 +32,7 @@ func main() {
|
|||
var endpoints stringList
|
||||
flag.Var(&endpoints, "endpoint", "Endpoint where a pprof HTTP API is exposed at, for example, http://127.0.0.1:6060. Can specify multiple")
|
||||
profileDirectory := flag.String("profile-directory", "/tmp", "Place where to dump generated merged profiles")
|
||||
profileName := flag.String("profile-name", "pgo-profile-latest.pprof", "Prefix to give latest generated file")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
@ -95,41 +96,45 @@ func main() {
|
|||
//maybe redundant
|
||||
compactProfile = mergedProfile.Compact()
|
||||
}
|
||||
profilePath := path.Join(*profileDirectory, fmt.Sprintf("pgo-profile-%d.pprof", time.Now().UTC().Unix()))
|
||||
if f, err := os.Create(profilePath); err != nil {
|
||||
log.Printf("error opening output profile %s: %s", profilePath, err)
|
||||
} else {
|
||||
func() {
|
||||
defer f.Close()
|
||||
if err = compactProfile.Write(f); err != nil {
|
||||
log.Printf("error writing output profile %s: %s", profilePath, err)
|
||||
} else {
|
||||
log.Printf("wrote profile %s", profilePath)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//copies to latest atomically
|
||||
if err := func() error {
|
||||
r, err := os.Open(profilePath)
|
||||
func() {
|
||||
temporaryFile, err := os.CreateTemp("/tmp", "pgo-*")
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("error opening temporary output profile: %s", err)
|
||||
} else {
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
func() {
|
||||
defer temporaryFile.Sync()
|
||||
if err = compactProfile.Write(temporaryFile); err != nil {
|
||||
log.Printf("error writing temporary output profile: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
//copies to latest atomically
|
||||
|
||||
if err := func() error {
|
||||
if _, err = temporaryFile.Seek(0, io.SeekStart); err != nil {
|
||||
return err
|
||||
}
|
||||
w, err := os.Create(path.Join(*profileDirectory, *profileName+".tmp"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Close()
|
||||
if _, err := io.Copy(w, temporaryFile); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
log.Printf("error writing latest profile: %s", err)
|
||||
} else {
|
||||
_ = os.Chmod(path.Join(*profileDirectory, *profileName+".tmp"), 0666)
|
||||
_ = os.Rename(path.Join(*profileDirectory, *profileName+".tmp"), path.Join(*profileDirectory, *profileName))
|
||||
log.Printf("wrote profile %s at %d", path.Join(*profileDirectory, *profileName), time.Now().UTC().Unix())
|
||||
}
|
||||
}
|
||||
defer r.Close()
|
||||
w, err := os.Create(path.Join(*profileDirectory, "pgo-profile-latest-temp.pprof"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Close()
|
||||
if _, err := io.Copy(w, r); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
log.Printf("error writing latest profile: %s", err)
|
||||
} else {
|
||||
_ = os.Rename(path.Join(*profileDirectory, "pgo-profile-latest-temp.pprof"), path.Join(*profileDirectory, "pgo-profile-latest.pprof"))
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
7
go.mod
7
go.mod
|
@ -1,8 +1,5 @@
|
|||
module git.gammaspectra.live/P2Pool/pgo-collector
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3
|
||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
|
||||
)
|
||||
require github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,10 +1,2 @@
|
|||
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3 h1:2XF1Vzq06X+inNqgJ9tRnGuw+ZVCB3FazXODD6JE1R8=
|
||||
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20220517205856-0058ec4f073c h1:rwmN+hgiyp8QyBqzdEX43lTjKAxaqCrYHaU5op5P9J8=
|
||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
|
||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
|
||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
|
||||
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA=
|
||||
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA=
|
||||
|
|
Loading…
Reference in a new issue