mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
GO-3508 Add dependencies tracing
This commit is contained in:
parent
862827aeab
commit
badb332739
2 changed files with 29 additions and 11 deletions
32
app/app.go
32
app/app.go
|
@ -57,14 +57,15 @@ type ComponentStatable interface {
|
||||||
// App is the central part of the application
|
// App is the central part of the application
|
||||||
// It contains and manages all components
|
// It contains and manages all components
|
||||||
type App struct {
|
type App struct {
|
||||||
parent *App
|
parent *App
|
||||||
components []Component
|
components []Component
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
startStat Stat
|
startStat Stat
|
||||||
stopStat Stat
|
stopStat Stat
|
||||||
deviceState int
|
deviceState int
|
||||||
versionName string
|
versionName string
|
||||||
anySyncVersion string
|
anySyncVersion string
|
||||||
|
componentListener func(comp Component)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns app name
|
// Name returns app name
|
||||||
|
@ -130,9 +131,10 @@ func VersionDescription() string {
|
||||||
// It doesn't call Start on any of the parent's components
|
// It doesn't call Start on any of the parent's components
|
||||||
func (app *App) ChildApp() *App {
|
func (app *App) ChildApp() *App {
|
||||||
return &App{
|
return &App{
|
||||||
parent: app,
|
parent: app,
|
||||||
deviceState: app.deviceState,
|
deviceState: app.deviceState,
|
||||||
anySyncVersion: app.AnySyncVersion(),
|
anySyncVersion: app.AnySyncVersion(),
|
||||||
|
componentListener: app.componentListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ func (app *App) Component(name string) Component {
|
||||||
for current != nil {
|
for current != nil {
|
||||||
for _, s := range current.components {
|
for _, s := range current.components {
|
||||||
if s.Name() == name {
|
if s.Name() == name {
|
||||||
|
app.onComponent(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,6 +187,7 @@ func MustComponent[i any](app *App) i {
|
||||||
for current != nil {
|
for current != nil {
|
||||||
for _, s := range current.components {
|
for _, s := range current.components {
|
||||||
if v, ok := s.(i); ok {
|
if v, ok := s.(i); ok {
|
||||||
|
app.onComponent(s)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,3 +388,9 @@ func (app *App) AnySyncVersion() string {
|
||||||
})
|
})
|
||||||
return app.anySyncVersion
|
return app.anySyncVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) onComponent(s Component) {
|
||||||
|
if app.componentListener != nil {
|
||||||
|
app.componentListener(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
8
app/apptrace.go
Normal file
8
app/apptrace.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//go:build appdebug
|
||||||
|
// +build appdebug
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
func (app *App) SetOnComponentListener(listener func(comp Component)) {
|
||||||
|
app.componentListener = listener
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue