add dev-only profiling with pprof, runtime/trace, and operation timing

Wire up Go's standard profiling toolkit so it's automatically available
in dev builds and completely absent from production. The profiling
package uses build tags (dev/!dev) to eliminate all pprof, trace, and
timing code from release binaries with zero new dependencies.

- backend/profiling: pprof HTTP server on :6060, /debug/trace endpoint,
  block/mutex profiling, and TimeOp helper for structured operation timing
- scripts/profile.sh: interactive menu-driven script that auto-selects
  free ports (8080-8089) so multiple profiles can be open simultaneously
- Instrumented key operations: app init, database init, player load/restore,
  queue set/restore
- Makefile targets: profile, profile-cpu, profile-heap, profile-trace
- .gitignore: exclude trace-*.out and *.pprof artifacts
This commit is contained in:
2026-02-20 18:27:25 -06:00
parent 402789e763
commit 2a3a79652c
13 changed files with 629 additions and 0 deletions
+7
View File
@@ -22,6 +22,7 @@ import (
"yellowjacket/backend/events"
"yellowjacket/backend/library"
"yellowjacket/backend/metadata"
"yellowjacket/backend/profiling"
)
// Player handles audio playback and state management.
@@ -64,6 +65,8 @@ var speakerSampleRate = beep.SampleRate(44100)
// NewPlayer creates a player and initializes the audio speaker.
func NewPlayer(ctx context.Context, logger *slog.Logger, db *database.DB) (*Player, error) {
defer profiling.TimeOp(logger, "player.NewPlayer")()
player := &Player{
ctx: ctx,
logger: logger,
@@ -313,6 +316,8 @@ func (p *Player) startPaused() {
// LoadFile opens and decodes an audio file for playback.
func (p *Player) LoadFile(filePath string) error {
defer profiling.TimeOp(p.logger, "player.LoadFile")()
// opening file
f, err := os.Open(filePath)
if err != nil {
@@ -724,6 +729,8 @@ func (p *Player) saveState() {
// RestoreState loads the persisted player state from the database.
func (p *Player) RestoreState() {
defer profiling.TimeOp(p.logger, "player.RestoreState")()
if p.db == nil {
p.logger.Warn("No database available, cannot restore player state")