mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-21 00:34:24 +00:00
Add platform metadata to reports
This commit is contained in:
@@ -223,7 +223,7 @@ func (d *Daemon) startServiceLocked(ctx context.Context, ownerUserID string, con
|
||||
})
|
||||
d.startedService.SetOOMKillerOptions(options.OOMKillerEnabled, options.OOMKillerDisabled, uint64(options.OOMMemoryLimit))
|
||||
if options.PowerReportEnabled {
|
||||
err = d.powerManager.Start(libbox.PowerReportOptions(d.startedService, nil))
|
||||
err = d.powerManager.Start(libbox.PowerReportOptions(d.startedService))
|
||||
if err != nil {
|
||||
d.logger.Warn("start power report recorder: ", err)
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ func archiveCrashReport(path string, crashReportsDir string) {
|
||||
reportMetadata: baseReportMetadata(),
|
||||
CrashedAt: crashTime.Format(time.RFC3339),
|
||||
}
|
||||
platformSnapshot := readPlatformSnapshot()
|
||||
if platformSnapshot != nil {
|
||||
metadata.Platform = platformSnapshot
|
||||
}
|
||||
writeReportMetadata(destPath, metadata)
|
||||
os.Remove(path)
|
||||
copyConfigSnapshot(destPath)
|
||||
|
||||
@@ -13,19 +13,14 @@ import (
|
||||
|
||||
type powerReportMetadata struct {
|
||||
reportMetadata
|
||||
StartedAt string `json:"startedAt"`
|
||||
IncludeAllNetworks *bool `json:"includeAllNetworks,omitempty"`
|
||||
StartedAt string `json:"startedAt"`
|
||||
}
|
||||
|
||||
func PowerReportOptions(startedService *daemon.StartedService, platformInterface PlatformInterface) powerreport.Options {
|
||||
func PowerReportOptions(startedService *daemon.StartedService) powerreport.Options {
|
||||
metadata := powerReportMetadata{
|
||||
reportMetadata: baseReportMetadata(),
|
||||
StartedAt: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
if platformInterface != nil && platformInterface.UnderNetworkExtension() {
|
||||
includeAllNetworks := platformInterface.IncludeAllNetworks()
|
||||
metadata.IncludeAllNetworks = &includeAllNetworks
|
||||
}
|
||||
return powerreport.Options{
|
||||
BasePath: sWorkingPath,
|
||||
Logger: log.StdLogger(),
|
||||
|
||||
@@ -16,15 +16,16 @@ import (
|
||||
)
|
||||
|
||||
type reportMetadata struct {
|
||||
Source string `json:"source,omitempty"`
|
||||
BundleIdentifier string `json:"bundleIdentifier,omitempty"`
|
||||
ProcessName string `json:"processName,omitempty"`
|
||||
ProcessPath string `json:"processPath,omitempty"`
|
||||
StartedAt string `json:"startedAt,omitempty"`
|
||||
AppVersion string `json:"appVersion,omitempty"`
|
||||
AppMarketingVersion string `json:"appMarketingVersion,omitempty"`
|
||||
CoreVersion string `json:"coreVersion,omitempty"`
|
||||
GoVersion string `json:"goVersion,omitempty"`
|
||||
Source string `json:"source,omitempty"`
|
||||
BundleIdentifier string `json:"bundleIdentifier,omitempty"`
|
||||
ProcessName string `json:"processName,omitempty"`
|
||||
ProcessPath string `json:"processPath,omitempty"`
|
||||
StartedAt string `json:"startedAt,omitempty"`
|
||||
AppVersion string `json:"appVersion,omitempty"`
|
||||
AppMarketingVersion string `json:"appMarketingVersion,omitempty"`
|
||||
CoreVersion string `json:"coreVersion,omitempty"`
|
||||
GoVersion string `json:"goVersion,omitempty"`
|
||||
Platform json.RawMessage `json:"platform,omitempty"`
|
||||
}
|
||||
|
||||
func baseReportMetadata() reportMetadata {
|
||||
@@ -41,6 +42,7 @@ func baseReportMetadata() reportMetadata {
|
||||
AppMarketingVersion: sAppMarketingVersion,
|
||||
CoreVersion: C.Version,
|
||||
GoVersion: GoVersion(),
|
||||
Platform: sPlatformMetadata,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +72,28 @@ func copyConfigSnapshot(destPath string) {
|
||||
writeReportFile(destPath, "configuration.json", content)
|
||||
}
|
||||
|
||||
func platformSnapshotPath() string {
|
||||
return filepath.Join(sWorkingPath, "PlatformMetadata-"+sCrashReportSource+".json")
|
||||
}
|
||||
|
||||
func savePlatformSnapshot() {
|
||||
snapshotPath := platformSnapshotPath()
|
||||
if sPlatformMetadata == nil {
|
||||
os.Remove(snapshotPath)
|
||||
return
|
||||
}
|
||||
os.WriteFile(snapshotPath, sPlatformMetadata, 0o666)
|
||||
chownReport(snapshotPath)
|
||||
}
|
||||
|
||||
func readPlatformSnapshot() json.RawMessage {
|
||||
content, err := os.ReadFile(platformSnapshotPath())
|
||||
if err != nil || !json.Valid(content) {
|
||||
return nil
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
func initReportDir(path string) {
|
||||
os.MkdirAll(path, 0o777)
|
||||
chownReport(path)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package libbox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -37,6 +38,7 @@ var (
|
||||
sOOMKillerDisabled bool
|
||||
sOOMMemoryLimit int64
|
||||
sPowerReportEnabled bool
|
||||
sPlatformMetadata []byte
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -60,6 +62,7 @@ type SetupOptions struct {
|
||||
OomKillerDisabled bool
|
||||
OomMemoryLimit int64
|
||||
PowerReportEnabled bool
|
||||
PlatformMetadata string
|
||||
}
|
||||
|
||||
func applySetupOptions(options *SetupOptions) {
|
||||
@@ -89,6 +92,11 @@ func ReloadSetupOptions(options *SetupOptions) {
|
||||
sOOMKillerDisabled = options.OomKillerDisabled
|
||||
sOOMMemoryLimit = options.OomMemoryLimit
|
||||
sPowerReportEnabled = options.PowerReportEnabled
|
||||
if json.Valid([]byte(options.PlatformMetadata)) {
|
||||
sPlatformMetadata = []byte(options.PlatformMetadata)
|
||||
} else {
|
||||
sPlatformMetadata = nil
|
||||
}
|
||||
if sOOMKillerEnabled {
|
||||
if sOOMMemoryLimit == 0 && C.IsIos {
|
||||
sOOMMemoryLimit = oomkiller.DefaultAppleNetworkExtensionMemoryLimit
|
||||
@@ -108,7 +116,9 @@ func Setup(options *SetupOptions) error {
|
||||
applySetupOptions(options)
|
||||
os.MkdirAll(sWorkingPath, 0o777)
|
||||
os.MkdirAll(sTempPath, 0o777)
|
||||
return redirectStderr(filepath.Join(sWorkingPath, "CrashReport-"+sCrashReportSource+".log"))
|
||||
err := redirectStderr(filepath.Join(sWorkingPath, "CrashReport-"+sCrashReportSource+".log"))
|
||||
savePlatformSnapshot()
|
||||
return err
|
||||
}
|
||||
|
||||
func SetLocale(localeID string) error {
|
||||
|
||||
Reference in New Issue
Block a user