ipn/localapi: rename /profile to /pprof

Avoids name collision with profiles for user switching.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
pull/6270/head
Mihai Parparita 2 years ago committed by Mihai Parparita
parent 9a05cdd2b5
commit 7a07bc654b

@ -255,8 +255,8 @@ func (lc *LocalClient) DaemonMetrics(ctx context.Context) ([]byte, error) {
return lc.get200(ctx, "/localapi/v0/metrics") return lc.get200(ctx, "/localapi/v0/metrics")
} }
// Profile returns a pprof profile of the Tailscale daemon. // Pprof returns a pprof profile of the Tailscale daemon.
func (lc *LocalClient) Profile(ctx context.Context, pprofType string, sec int) ([]byte, error) { func (lc *LocalClient) Pprof(ctx context.Context, pprofType string, sec int) ([]byte, error) {
var secArg string var secArg string
if sec < 0 || sec > 300 { if sec < 0 || sec > 300 {
return nil, errors.New("duration out of range") return nil, errors.New("duration out of range")
@ -264,7 +264,7 @@ func (lc *LocalClient) Profile(ctx context.Context, pprofType string, sec int) (
if sec != 0 || pprofType == "profile" { if sec != 0 || pprofType == "profile" {
secArg = fmt.Sprint(sec) secArg = fmt.Sprint(sec)
} }
return lc.get200(ctx, fmt.Sprintf("/localapi/v0/profile?name=%s&seconds=%v", url.QueryEscape(pprofType), secArg)) return lc.get200(ctx, fmt.Sprintf("/localapi/v0/pprof?name=%s&seconds=%v", url.QueryEscape(pprofType), secArg))
} }
// BugReportOpts contains options to pass to the Tailscale daemon when // BugReportOpts contains options to pass to the Tailscale daemon when

@ -188,9 +188,9 @@ func runDebug(ctx context.Context, args []string) error {
} }
var usedFlag bool var usedFlag bool
if out := debugArgs.cpuFile; out != "" { if out := debugArgs.cpuFile; out != "" {
usedFlag = true // TODO(bradfitz): add "profile" subcommand usedFlag = true // TODO(bradfitz): add "pprof" subcommand
log.Printf("Capturing CPU profile for %v seconds ...", debugArgs.cpuSec) log.Printf("Capturing CPU profile for %v seconds ...", debugArgs.cpuSec)
if v, err := localClient.Profile(ctx, "profile", debugArgs.cpuSec); err != nil { if v, err := localClient.Pprof(ctx, "profile", debugArgs.cpuSec); err != nil {
return err return err
} else { } else {
if err := writeProfile(out, v); err != nil { if err := writeProfile(out, v); err != nil {
@ -200,9 +200,9 @@ func runDebug(ctx context.Context, args []string) error {
} }
} }
if out := debugArgs.memFile; out != "" { if out := debugArgs.memFile; out != "" {
usedFlag = true // TODO(bradfitz): add "profile" subcommand usedFlag = true // TODO(bradfitz): add "pprof" subcommand
log.Printf("Capturing memory profile ...") log.Printf("Capturing memory profile ...")
if v, err := localClient.Profile(ctx, "heap", 0); err != nil { if v, err := localClient.Pprof(ctx, "heap", 0); err != nil {
return err return err
} else { } else {
if err := writeProfile(out, v); err != nil { if err := writeProfile(out, v); err != nil {

@ -71,7 +71,7 @@ var handler = map[string]localAPIHandler{
"metrics": (*Handler).serveMetrics, "metrics": (*Handler).serveMetrics,
"ping": (*Handler).servePing, "ping": (*Handler).servePing,
"prefs": (*Handler).servePrefs, "prefs": (*Handler).servePrefs,
"profile": (*Handler).serveProfile, "pprof": (*Handler).servePprof,
"set-dns": (*Handler).serveSetDNS, "set-dns": (*Handler).serveSetDNS,
"set-expiry-sooner": (*Handler).serveSetExpirySooner, "set-expiry-sooner": (*Handler).serveSetExpirySooner,
"status": (*Handler).serveStatus, "status": (*Handler).serveStatus,
@ -437,22 +437,22 @@ func (h *Handler) serveComponentDebugLogging(w http.ResponseWriter, r *http.Requ
json.NewEncoder(w).Encode(res) json.NewEncoder(w).Encode(res)
} }
// serveProfileFunc is the implementation of Handler.serveProfile, after auth, // servePprofFunc is the implementation of Handler.servePprof, after auth,
// for platforms where we want to link it in. // for platforms where we want to link it in.
var serveProfileFunc func(http.ResponseWriter, *http.Request) var servePprofFunc func(http.ResponseWriter, *http.Request)
func (h *Handler) serveProfile(w http.ResponseWriter, r *http.Request) { func (h *Handler) servePprof(w http.ResponseWriter, r *http.Request) {
// Require write access out of paranoia that the profile dump // Require write access out of paranoia that the profile dump
// might contain something sensitive. // might contain something sensitive.
if !h.PermitWrite { if !h.PermitWrite {
http.Error(w, "profile access denied", http.StatusForbidden) http.Error(w, "profile access denied", http.StatusForbidden)
return return
} }
if serveProfileFunc == nil { if servePprofFunc == nil {
http.Error(w, "not implemented on this platform", http.StatusServiceUnavailable) http.Error(w, "not implemented on this platform", http.StatusServiceUnavailable)
return return
} }
serveProfileFunc(w, r) servePprofFunc(w, r)
} }
func (h *Handler) serveCheckIPForwarding(w http.ResponseWriter, r *http.Request) { func (h *Handler) serveCheckIPForwarding(w http.ResponseWriter, r *http.Request) {

@ -15,10 +15,10 @@ import (
) )
func init() { func init() {
serveProfileFunc = serveProfile servePprofFunc = servePprof
} }
func serveProfile(w http.ResponseWriter, r *http.Request) { func servePprof(w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name") name := r.FormValue("name")
switch name { switch name {
case "profile": case "profile":
Loading…
Cancel
Save