MCPcopy
hub / github.com/tailscale/tailscale / runDebug

Function runDebug

cmd/tailscale/cli/debug.go:438–496  ·  view source on GitHub ↗
(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

436}
437
438func runDebug(ctx context.Context, args []string) error {
439 if len(args) > 0 {
440 return fmt.Errorf("tailscale debug: unknown subcommand: %s", args[0])
441 }
442 var usedFlag bool
443 if out := debugArgs.cpuFile; out != "" {
444 usedFlag = true // TODO(bradfitz): add "pprof" subcommand
445 log.Printf("Capturing CPU profile for %v seconds ...", debugArgs.cpuSec)
446 if v, err := localClient.Pprof(ctx, "profile", debugArgs.cpuSec); err != nil {
447 return err
448 } else {
449 if err := writeProfile(out, v); err != nil {
450 return err
451 }
452 log.Printf("CPU profile written to %s", outName(out))
453 }
454 }
455 if out := debugArgs.memFile; out != "" {
456 usedFlag = true // TODO(bradfitz): add "pprof" subcommand
457 log.Printf("Capturing memory profile ...")
458 if v, err := localClient.Pprof(ctx, "heap", 0); err != nil {
459 return err
460 } else {
461 if err := writeProfile(out, v); err != nil {
462 return err
463 }
464 log.Printf("Memory profile written to %s", outName(out))
465 }
466 }
467 if debugArgs.file != "" {
468 usedFlag = true // TODO(bradfitz): add "file" subcommand
469 if debugArgs.file == "get" {
470 wfs, err := localClient.WaitingFiles(ctx)
471 if err != nil {
472 fatalf("%v\n", err)
473 }
474 e := json.NewEncoder(Stdout)
475 e.SetIndent("", "\t")
476 e.Encode(wfs)
477 return nil
478 }
479 if name, ok := strings.CutPrefix(debugArgs.file, "delete:"); ok {
480 return localClient.DeleteWaitingFile(ctx, name)
481 }
482 rc, size, err := localClient.GetWaitingFile(ctx, debugArgs.file)
483 if err != nil {
484 return err
485 }
486 log.Printf("Size: %v\n", size)
487 io.Copy(Stdout, rc)
488 return nil
489 }
490 if usedFlag {
491 // TODO(bradfitz): delete this path when all debug flags are migrated
492 // to subcommands.
493 return nil
494 }
495 return errors.New("tailscale debug: subcommand or flag required")

Callers

nothing calls this directly

Calls 11

writeProfileFunction · 0.85
outNameFunction · 0.85
fatalfFunction · 0.85
PrintfMethod · 0.80
PprofMethod · 0.80
EncodeMethod · 0.80
DeleteWaitingFileMethod · 0.80
GetWaitingFileMethod · 0.80
ErrorfMethod · 0.65
WaitingFilesMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…