Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add support for pprof incoder agent#1985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 8 commits intomainfrommafredri/feat-add-pprof-to-agent
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix: Disable USR1 on Windows (no signal)
  • Loading branch information
@mafredri
mafredri committedJun 3, 2022
commitec54e019cf44b9bde6ab963ff6fc2490cb428206
22 changes: 2 additions & 20 deletionscli/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,9 +6,7 @@ import (
_ "net/http/pprof" //nolint: gosec
"net/url"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"

"cloud.google.com/go/compute/metadata"
Expand DownExpand Up@@ -54,29 +52,14 @@ func workspaceAgent() *cobra.Command {
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
client := codersdk.New(coderURL)

usr1 := make(chan os.Signal, 1)
if pprofEnabled {
close(usr1)
srvClose := serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")
defer srvClose()
} else {
// If pprof wasn't enabled at startup, allow a
// `kill -USR1 $agent_pid` to start it.
signal.Notify(usr1, syscall.SIGUSR1)
go func() {
defer close(usr1)
defer signal.Stop(usr1)

select {
case <-usr1:
signal.Stop(usr1)
srvClose := serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")
defer srvClose()
case <-cmd.Context().Done():
return
}
<-cmd.Context().Done() // Prevent defer close until done.
}()
srvClose := agentPPROFStartOnUSR1(cmd.Context(), logger, pprofAddress)
defer srvClose()
}

// exchangeToken returns a session token.
Expand DownExpand Up@@ -164,7 +147,6 @@ func workspaceAgent() *cobra.Command {
},
})
<-cmd.Context().Done()
<-usr1 // Wait for server to close (if started).
return closer.Close()
},
}
Expand Down
33 changes: 33 additions & 0 deletionscli/agent_unix.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
package cli

import (
"context"
"os"
"os/signal"
"syscall"

"cdr.dev/slog"
)

func agentPPROFStartOnUSR1(ctx context.Context, logger slog.Logger, pprofAddress string) (srvClose func()) {
usr1 := make(chan os.Signal, 1)
signal.Notify(usr1, syscall.SIGUSR1)
go func() {
defer close(usr1)
defer signal.Stop(usr1)

select {
case <-usr1:
signal.Stop(usr1)
srvClose := serveHandler(ctx, logger, nil, pprofAddress, "pprof")
defer srvClose()
case <-ctx.Done():
return
}
<-ctx.Done() // Prevent defer close until done.
}()

return func() {
<-usr1 // Wait until usr1 is closed, ensures srvClose was run.
}
}
15 changes: 15 additions & 0 deletionscli/agent_windows.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
package cli

import (
"context"
"os"
"os/signal"
"syscall"

"cdr.dev/slog"
)

// agentPPROFStartOnUSR1 is no-op on Windows (no SIGUSR1 signal).
func agentPPROFStartOnUSR1(ctx context.Context, logger slog.Logger, pprofAddress string) (srvClose func()) {
return func() {}
}

[8]ページ先頭

©2009-2025 Movatter.jp