mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
[service] Fix SPN build
This commit is contained in:
parent
7f0b5ca149
commit
78e4a40750
1 changed files with 60 additions and 0 deletions
60
spn/debug.go
Normal file
60
spn/debug.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package spn
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/maruel/panicparse/v2/stack"
|
||||||
|
|
||||||
|
"github.com/safing/portmaster/base/utils/debug"
|
||||||
|
"github.com/safing/portmaster/service/mgr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetWorkerInfo returns the worker info of all running workers.
|
||||||
|
func (i *Instance) GetWorkerInfo() (*mgr.WorkerInfo, error) {
|
||||||
|
snapshot, _, err := stack.ScanSnapshot(bytes.NewReader(fullStack()), io.Discard, stack.DefaultOpts())
|
||||||
|
if err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, fmt.Errorf("get stack: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
infos := make([]*mgr.WorkerInfo, 0, 32)
|
||||||
|
for _, m := range i.serviceGroup.Modules() {
|
||||||
|
wi, _ := m.Manager().WorkerInfo(snapshot) // Does not fail when we provide a snapshot.
|
||||||
|
infos = append(infos, wi)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mgr.MergeWorkerInfo(infos...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddWorkerInfoToDebugInfo adds the worker info of all running workers to the debug info.
|
||||||
|
func (i *Instance) AddWorkerInfoToDebugInfo(di *debug.Info) {
|
||||||
|
info, err := i.GetWorkerInfo()
|
||||||
|
if err != nil {
|
||||||
|
di.AddSection(
|
||||||
|
"Worker Status Failed",
|
||||||
|
debug.UseCodeSection,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
di.AddSection(
|
||||||
|
fmt.Sprintf("Worker Status: %d/%d (%d?)", info.Running, len(info.Workers), info.Missing+info.Other),
|
||||||
|
debug.UseCodeSection,
|
||||||
|
info.Format(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func fullStack() []byte {
|
||||||
|
buf := make([]byte, 8096)
|
||||||
|
for {
|
||||||
|
n := runtime.Stack(buf, true)
|
||||||
|
if n < len(buf) {
|
||||||
|
return buf[:n]
|
||||||
|
}
|
||||||
|
buf = make([]byte, 2*len(buf))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue