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
101 lines
2.4 KiB
Go
101 lines
2.4 KiB
Go
// Package main is the entry point for the Yellowjacket application.
|
|
package main
|
|
|
|
import (
|
|
"embed"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/golang-cz/devslog"
|
|
"github.com/wailsapp/wails/v2"
|
|
"github.com/wailsapp/wails/v2/pkg/options"
|
|
"github.com/wailsapp/wails/v2/pkg/options/linux"
|
|
|
|
"yellowjacket/backend"
|
|
"yellowjacket/backend/assets"
|
|
"yellowjacket/backend/logging"
|
|
"yellowjacket/backend/profiling"
|
|
"yellowjacket/internal/dev"
|
|
)
|
|
|
|
// version and commit are set at build time via ldflags.
|
|
var (
|
|
version = "dev"
|
|
commit = "unknown"
|
|
)
|
|
|
|
//go:embed all:frontend/dist
|
|
var frontendDistAssets embed.FS
|
|
|
|
func main() {
|
|
isDev := dev.IsDev
|
|
// create sLogger
|
|
var loglevel slog.Level
|
|
if isDev {
|
|
loglevel = slog.LevelDebug
|
|
} else {
|
|
loglevel = slog.LevelInfo
|
|
}
|
|
|
|
sLogger := slog.New(devslog.NewHandler(os.Stdout, &devslog.Options{
|
|
HandlerOptions: &slog.HandlerOptions{
|
|
Level: loglevel,
|
|
},
|
|
}))
|
|
slog.SetDefault(sLogger)
|
|
sLogger.Info("starting yellowjacket", "version", version, "commit", commit)
|
|
|
|
// Start profiling server (pprof + trace). In production builds this
|
|
// is a no-op — the compiler eliminates all profiling code.
|
|
stopProfiler := profiling.Start(sLogger)
|
|
|
|
// create asset handler
|
|
assetHandler, err := assets.NewAssetHandler(sLogger, frontendDistAssets)
|
|
if err != nil {
|
|
sLogger.Error("could not create asset handler", "err", err.Error())
|
|
stopProfiler()
|
|
os.Exit(1)
|
|
}
|
|
|
|
yjApp, err := backend.NewYellowJacketApp(sLogger, assetHandler)
|
|
if err != nil {
|
|
sLogger.Error("problem initializing yellowjacket", "err", err.Error())
|
|
stopProfiler()
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Create application with options
|
|
winCfg := yjApp.WindowConfig()
|
|
|
|
err = wails.Run(&options.App{
|
|
Title: "yellowjacket",
|
|
Width: winCfg.Width,
|
|
Height: winCfg.Height,
|
|
Logger: logging.NewLogger(
|
|
sLogger,
|
|
[]string{},
|
|
),
|
|
AssetServer: assetHandler.Options,
|
|
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
|
|
OnStartup: yjApp.OnStartup,
|
|
OnDomReady: yjApp.OnDomReady,
|
|
OnBeforeClose: yjApp.OnBeforeClose,
|
|
OnShutdown: yjApp.OnShutdown,
|
|
Bind: yjApp.FEBindings,
|
|
MinWidth: 512,
|
|
MinHeight: 384,
|
|
MaxWidth: 0,
|
|
MaxHeight: 0,
|
|
Linux: &linux.Options{
|
|
WebviewGpuPolicy: linux.WebviewGpuPolicyAlways,
|
|
},
|
|
})
|
|
|
|
stopProfiler()
|
|
|
|
if err != nil {
|
|
sLogger.Error("application error", "err", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|