Skip to content

Commit

Permalink
fix: use different signal for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren committed Jan 31, 2025
1 parent 67f37c1 commit 62621e1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 23 deletions.
28 changes: 5 additions & 23 deletions profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"errors"
"expvar"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"sync"
"syscall"
"time"
)

"net/http/pprof"
const (
defaultTimeout = 30 * time.Minute
defaultListen = ":6666"
)

// Hooker represents the interface for Profiler hooks
Expand All @@ -36,27 +39,6 @@ type Profiler struct {
evt EventHandler
}

// New returns a new profiler
// Defaults:
// - Signal : syscall.SIGUSR1
// - Address: ":6666"
// - Timeout: 30m
func New(options ...Option) *Profiler {
p := Profiler{
signal: syscall.SIGUSR1,
address: ":6666",
timeout: 30 * time.Minute,

evt: DefaultEventHandler(),
}

for _, option := range options {
option(&p)
}

return &p
}

// Address returns the listen address for the debug endpoint
func (p *Profiler) Address() string {
return p.address
Expand Down
2 changes: 2 additions & 0 deletions profiler_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

package profiler

import (
Expand Down
3 changes: 3 additions & 0 deletions profiler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

package profiler_test

import (
Expand Down Expand Up @@ -377,6 +379,7 @@ func (hfs *HookFailedStart) IsShutdown() bool {

return hfs.Shutdown
}

func TestFailedStart(t *testing.T) {
var buf bytes.Buffer
var mu sync.Mutex
Expand Down
29 changes: 29 additions & 0 deletions profiler_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build !windows

// Package profiler implements functions to start a handler
package profiler

import (
"syscall"
)

// New returns a new profiler
// Defaults:
// - Signal : syscall.SIGUSR1
// - Address: ":6666"
// - Timeout: 30m
func New(options ...Option) *Profiler {
p := Profiler{
signal: syscall.SIGUSR1,
address: defaultListen,
timeout: defaultTimeout,

evt: DefaultEventHandler(),
}

for _, option := range options {
option(&p)
}

return &p
}
27 changes: 27 additions & 0 deletions profiler_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Package profiler implements functions to start a handler
package profiler

import (
"syscall"
)

// New returns a new profiler
// Defaults:
// - Signal : syscall.SIGHUB
// - Address: ":6666"
// - Timeout: 30m
func New(options ...Option) *Profiler {
p := Profiler{
signal: syscall.SIGHUP,
address: defaultListen,
timeout: defaultTimeout,

evt: DefaultEventHandler(),
}

for _, option := range options {
option(&p)
}

return &p
}

0 comments on commit 62621e1

Please sign in to comment.