New Upstream Release - golang-github-pkg-profile
Ready changes
Summary
Merged new upstream version: 1.7.0 (was: 1.2.1).
Resulting package
Built on 2023-01-01T04:34 (took 5m53s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases golang-github-pkg-profile-dev
Lintian Result
Diff
diff --git a/.travis.yml b/.travis.yml
index 192c5c2..0b895c9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,9 @@
language: go
go_import_path: github.com/pkg/profile
go:
- - 1.4.3
- - 1.5.2
- - 1.6.3
+ - 1.13.x
+ - 1.14.x
- tip
script:
- - go test github.com/pkg/profile
- go test -race github.com/pkg/profile
diff --git a/README.md b/README.md
index 37bfa58..8bae598 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ func main() {
options
-------
-What to profile is controlled by config value passed to profile.Start.
+What to profile is controlled by config value passed to profile.Start.
By default CPU profiling is enabled.
```go
@@ -39,6 +39,9 @@ func main() {
// ensure profiling information is written to disk.
p := profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook)
...
+ // You can enable different kinds of memory profiling, either Heap or Allocs where Heap
+ // profiling is the default with profile.MemProfile.
+ p := profile.Start(profile.MemProfileAllocs, profile.ProfilePath("."), profile.NoShutdownHook)
}
```
diff --git a/debian/changelog b/debian/changelog
index ccf1920..8b4e3cd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,12 @@
-golang-github-pkg-profile (1.2.1-3) UNRELEASED; urgency=medium
+golang-github-pkg-profile (1.7.0-1) UNRELEASED; urgency=medium
+ [ Alexandre Viau ]
* Point Vcs-* urls to salsa.debian.org.
- -- Alexandre Viau <aviau@debian.org> Mon, 02 Apr 2018 20:02:10 -0400
+ [ Debian Janitor ]
+ * New upstream release.
+
+ -- Alexandre Viau <aviau@debian.org> Sun, 01 Jan 2023 04:29:03 -0000
golang-github-pkg-profile (1.2.1-2) unstable; urgency=medium
diff --git a/example_test.go b/example_test.go
index 98a54b5..11d8943 100644
--- a/example_test.go
+++ b/example_test.go
@@ -29,6 +29,16 @@ func ExampleMemProfileRate() {
defer profile.Start(profile.MemProfileRate(2048)).Stop()
}
+func ExampleMemProfileHeap() {
+ // use heap memory profiling.
+ defer profile.Start(profile.MemProfileHeap).Stop()
+}
+
+func ExampleMemProfileAllocs() {
+ // use allocs memory profiling.
+ defer profile.Start(profile.MemProfileAllocs).Stop()
+}
+
func ExampleProfilePath() {
// set the location that the profile will be written to
defer profile.Start(profile.ProfilePath(os.Getenv("HOME"))).Stop()
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..6dd15d7
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module github.com/pkg/profile
+
+go 1.13
+
+require github.com/felixge/fgprof v0.9.3
diff --git a/mutex.go b/mutex.go
deleted file mode 100644
index e69c5b4..0000000
--- a/mutex.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// +build go1.8
-
-package profile
-
-import "runtime"
-
-func enableMutexProfile() {
- runtime.SetMutexProfileFraction(1)
-}
-
-func disableMutexProfile() {
- runtime.SetMutexProfileFraction(0)
-}
diff --git a/mutex17.go b/mutex17.go
deleted file mode 100644
index b004c21..0000000
--- a/mutex17.go
+++ /dev/null
@@ -1,9 +0,0 @@
-// +build !go1.8
-
-package profile
-
-// mock mutex support for Go 1.7 and earlier.
-
-func enableMutexProfile() {}
-
-func disableMutexProfile() {}
diff --git a/profile.go b/profile.go
index c44913a..ea4e853 100644
--- a/profile.go
+++ b/profile.go
@@ -10,7 +10,10 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
+ "runtime/trace"
"sync/atomic"
+
+ "github.com/felixge/fgprof"
)
const (
@@ -19,6 +22,9 @@ const (
mutexMode
blockMode
traceMode
+ threadCreateMode
+ goroutineMode
+ clockMode
)
// Profile represents an active profiling session.
@@ -40,6 +46,10 @@ type Profile struct {
// memProfileRate holds the rate for the memory profile.
memProfileRate int
+ // memProfileType holds the profile type for memory
+ // profiles. Allowed values are `heap` and `allocs`.
+ memProfileType string
+
// closer holds a cleanup function that run after each profile
closer func()
@@ -81,19 +91,44 @@ func MemProfileRate(rate int) func(*Profile) {
}
}
+// MemProfileHeap changes which type of memory profiling to profile
+// the heap.
+func MemProfileHeap(p *Profile) {
+ p.memProfileType = "heap"
+ p.mode = memMode
+}
+
+// MemProfileAllocs changes which type of memory to profile
+// allocations.
+func MemProfileAllocs(p *Profile) {
+ p.memProfileType = "allocs"
+ p.mode = memMode
+}
+
// MutexProfile enables mutex profiling.
// It disables any previous profiling settings.
-//
-// Mutex profiling is a no-op before go1.8.
func MutexProfile(p *Profile) { p.mode = mutexMode }
// BlockProfile enables block (contention) profiling.
// It disables any previous profiling settings.
func BlockProfile(p *Profile) { p.mode = blockMode }
-// Trace profile controls if execution tracing will be enabled. It disables any previous profiling settings.
+// Trace profile enables execution tracing.
+// It disables any previous profiling settings.
func TraceProfile(p *Profile) { p.mode = traceMode }
+// ThreadcreationProfile enables thread creation profiling..
+// It disables any previous profiling settings.
+func ThreadcreationProfile(p *Profile) { p.mode = threadCreateMode }
+
+// GoroutineProfile enables goroutine profiling.
+// It disables any previous profiling settings.
+func GoroutineProfile(p *Profile) { p.mode = goroutineMode }
+
+// ClockProfile enables wall clock (fgprof) profiling.
+// It disables any previous profiling settings.
+func ClockProfile(p *Profile) { p.mode = clockMode }
+
// ProfilePath controls the base path where various profiling
// files are written. If blank, the base path will be generated
// by ioutil.TempDir.
@@ -148,6 +183,10 @@ func Start(options ...func(*Profile)) interface {
}
}
+ if prof.memProfileType == "" {
+ prof.memProfileType = "heap"
+ }
+
switch prof.mode {
case cpuMode:
fn := filepath.Join(path, "cpu.pprof")
@@ -173,7 +212,7 @@ func Start(options ...func(*Profile)) interface {
runtime.MemProfileRate = prof.memProfileRate
logf("profile: memory profiling enabled (rate %d), %s", runtime.MemProfileRate, fn)
prof.closer = func() {
- pprof.Lookup("heap").WriteTo(f, 0)
+ pprof.Lookup(prof.memProfileType).WriteTo(f, 0)
f.Close()
runtime.MemProfileRate = old
logf("profile: memory profiling disabled, %s", fn)
@@ -185,14 +224,14 @@ func Start(options ...func(*Profile)) interface {
if err != nil {
log.Fatalf("profile: could not create mutex profile %q: %v", fn, err)
}
- enableMutexProfile()
+ runtime.SetMutexProfileFraction(1)
logf("profile: mutex profiling enabled, %s", fn)
prof.closer = func() {
if mp := pprof.Lookup("mutex"); mp != nil {
mp.WriteTo(f, 0)
}
f.Close()
- disableMutexProfile()
+ runtime.SetMutexProfileFraction(0)
logf("profile: mutex profiling disabled, %s", fn)
}
@@ -211,20 +250,64 @@ func Start(options ...func(*Profile)) interface {
logf("profile: block profiling disabled, %s", fn)
}
+ case threadCreateMode:
+ fn := filepath.Join(path, "threadcreation.pprof")
+ f, err := os.Create(fn)
+ if err != nil {
+ log.Fatalf("profile: could not create thread creation profile %q: %v", fn, err)
+ }
+ logf("profile: thread creation profiling enabled, %s", fn)
+ prof.closer = func() {
+ if mp := pprof.Lookup("threadcreate"); mp != nil {
+ mp.WriteTo(f, 0)
+ }
+ f.Close()
+ logf("profile: thread creation profiling disabled, %s", fn)
+ }
+
case traceMode:
fn := filepath.Join(path, "trace.out")
f, err := os.Create(fn)
if err != nil {
log.Fatalf("profile: could not create trace output file %q: %v", fn, err)
}
- if err := startTrace(f); err != nil {
+ if err := trace.Start(f); err != nil {
log.Fatalf("profile: could not start trace: %v", err)
}
logf("profile: trace enabled, %s", fn)
prof.closer = func() {
- stopTrace()
+ trace.Stop()
logf("profile: trace disabled, %s", fn)
}
+
+ case goroutineMode:
+ fn := filepath.Join(path, "goroutine.pprof")
+ f, err := os.Create(fn)
+ if err != nil {
+ log.Fatalf("profile: could not create goroutine profile %q: %v", fn, err)
+ }
+ logf("profile: goroutine profiling enabled, %s", fn)
+ prof.closer = func() {
+ if mp := pprof.Lookup("goroutine"); mp != nil {
+ mp.WriteTo(f, 0)
+ }
+ f.Close()
+ logf("profile: goroutine profiling disabled, %s", fn)
+ }
+
+ case clockMode:
+ fn := filepath.Join(path, "clock.pprof")
+ f, err := os.Create(fn)
+ if err != nil {
+ log.Fatalf("profile: could not create clock profile %q: %v", fn, err)
+ }
+ logf("profile: clock profiling enabled, %s", fn)
+ stop := fgprof.Start(f, fgprof.FormatPprof)
+ prof.closer = func() {
+ stop()
+ f.Close()
+ logf("profile: clock profiling disabled, %s", fn)
+ }
}
if !prof.noShutdownHook {
diff --git a/profile_test.go b/profile_test.go
index e33012c..b4cd651 100644
--- a/profile_test.go
+++ b/profile_test.go
@@ -122,6 +122,22 @@ func main() {
Stderr("profile: mutex profiling enabled"),
NoErr,
},
+ }, {
+ name: "clock profile",
+ code: `
+package main
+
+import "github.com/pkg/profile"
+
+func main() {
+ defer profile.Start(profile.ClockProfile).Stop()
+}
+`,
+ checks: []checkFn{
+ NoStdout,
+ Stderr("profile: clock profiling enabled"),
+ NoErr,
+ },
}, {
name: "profile path",
code: `
diff --git a/trace.go b/trace.go
deleted file mode 100644
index b349ed8..0000000
--- a/trace.go
+++ /dev/null
@@ -1,8 +0,0 @@
-// +build go1.7
-
-package profile
-
-import "runtime/trace"
-
-var startTrace = trace.Start
-var stopTrace = trace.Stop
diff --git a/trace16.go b/trace16.go
deleted file mode 100644
index 6aa6566..0000000
--- a/trace16.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// +build !go1.7
-
-package profile
-
-import "io"
-
-// mock trace support for Go 1.6 and earlier.
-
-func startTrace(w io.Writer) error { return nil }
-func stopTrace() {}
Debdiff
[The following lists of changes regard files as different if they have different names, permissions or owners.]
Files in second set of .debs but not in first
-rw-r--r-- root/root /usr/share/gocode/src/github.com/pkg/profile/go.mod
Files in first set of .debs but not in second
-rw-r--r-- root/root /usr/share/gocode/src/github.com/pkg/profile/mutex.go -rw-r--r-- root/root /usr/share/gocode/src/github.com/pkg/profile/mutex17.go -rw-r--r-- root/root /usr/share/gocode/src/github.com/pkg/profile/trace.go -rw-r--r-- root/root /usr/share/gocode/src/github.com/pkg/profile/trace16.go
No differences were encountered in the control files