From dab8cd81c1824b284e5ae7209de12eb41d5e3d2a Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Tue, 31 Mar 2026 13:50:43 +0200 Subject: [PATCH] create model.Config interface containing needed config.Config fields - models now use this interface - presenters now use this interface --- model/base.go | 8 +++----- model/fileinfo/fileinfo.go | 3 +-- model/interfaces.go | 13 +++++++++++++ model/memoryusage/memoryusage.go | 3 +-- model/mutexlatency/mutexlatency.go | 3 +-- model/stageslatency/stageslatency.go | 3 +-- model/tableio/tableio.go | 3 +-- model/tablelocks/tablelocks.go | 3 +-- model/userlatency/userlatency.go | 3 +-- presenter/fileinfolatency/fileinfolatency.go | 4 ++-- presenter/memoryusage/memoryusage.go | 4 ++-- presenter/mutexlatency/mutexlatency.go | 4 ++-- presenter/stageslatency/stageslatency.go | 4 ++-- presenter/tablelocklatency/tablelocklatency.go | 4 ++-- presenter/userlatency/userlatency.go | 4 ++-- pstable/pstable.go | 4 ++-- 16 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 model/interfaces.go diff --git a/model/base.go b/model/base.go index 269b3b4..127694a 100644 --- a/model/base.go +++ b/model/base.go @@ -2,15 +2,13 @@ package model import ( "time" - - "github.com/sjmudd/ps-top/config" ) // BaseCollector encapsulates the common collection state and logic for all models. // T is the row type (e.g., tableio.Row, memoryusage.Row) // R is a slice of T (e.g., []Row, or a named type like Rows) type BaseCollector[T any, R ~[]T] struct { - config *config.Config + config Config db QueryExecutor FirstCollected time.Time @@ -23,7 +21,7 @@ type BaseCollector[T any, R ~[]T] struct { } // NewBaseCollector creates a new BaseCollector with the given config, database, and process function. -func NewBaseCollector[T any, R ~[]T](cfg *config.Config, db QueryExecutor, process ProcessFunc[T, R]) *BaseCollector[T, R] { +func NewBaseCollector[T any, R ~[]T](cfg Config, db QueryExecutor, process ProcessFunc[T, R]) *BaseCollector[T, R] { return &BaseCollector[T, R]{ config: cfg, db: db, @@ -86,7 +84,7 @@ func (bc *BaseCollector[T, R]) ResetStatistics() { } // Config returns the collector's configuration -func (bc *BaseCollector[T, R]) Config() *config.Config { +func (bc *BaseCollector[T, R]) Config() Config { return bc.config } diff --git a/model/fileinfo/fileinfo.go b/model/fileinfo/fileinfo.go index eef6144..274f5b6 100644 --- a/model/fileinfo/fileinfo.go +++ b/model/fileinfo/fileinfo.go @@ -2,7 +2,6 @@ package fileinfo import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" ) @@ -14,7 +13,7 @@ type FileIoLatency struct { // NewFileSummaryByInstance creates a new structure and include various variable values: // - datadir, relay_log // There's no checking that these are actually provided! -func NewFileSummaryByInstance(cfg *config.Config, db model.QueryExecutor) *FileIoLatency { +func NewFileSummaryByInstance(cfg model.Config, db model.QueryExecutor) *FileIoLatency { process := func(last, first Rows) (Rows, Row) { results := make(Rows, len(last)) copy(results, last) diff --git a/model/interfaces.go b/model/interfaces.go new file mode 100644 index 0000000..ea409a3 --- /dev/null +++ b/model/interfaces.go @@ -0,0 +1,13 @@ +package model + +import ( + "github.com/sjmudd/ps-top/global" + "github.com/sjmudd/ps-top/model/filter" +) + +// Config defines the minimal configuration required by data models. +type Config interface { + WantRelativeStats() bool + DatabaseFilter() *filter.DatabaseFilter + Variables() *global.Variables +} diff --git a/model/memoryusage/memoryusage.go b/model/memoryusage/memoryusage.go index 0bfe7ad..fb095bd 100644 --- a/model/memoryusage/memoryusage.go +++ b/model/memoryusage/memoryusage.go @@ -3,7 +3,6 @@ package memoryusage import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" ) @@ -13,7 +12,7 @@ type MemoryUsage struct { } // NewMemoryUsage returns a pointer to a MemoryUsage struct -func NewMemoryUsage(cfg *config.Config, db model.QueryExecutor) *MemoryUsage { +func NewMemoryUsage(cfg model.Config, db model.QueryExecutor) *MemoryUsage { process := func(last, _ []Row) ([]Row, Row) { results := make([]Row, len(last)) copy(results, last) diff --git a/model/mutexlatency/mutexlatency.go b/model/mutexlatency/mutexlatency.go index b10c11a..ad937c1 100644 --- a/model/mutexlatency/mutexlatency.go +++ b/model/mutexlatency/mutexlatency.go @@ -3,7 +3,6 @@ package mutexlatency import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/common" ) @@ -14,7 +13,7 @@ type MutexLatency struct { } // NewMutexLatency creates a new MutexLatency instance. -func NewMutexLatency(cfg *config.Config, db model.QueryExecutor) *MutexLatency { +func NewMutexLatency(cfg model.Config, db model.QueryExecutor) *MutexLatency { process := func(last, first Rows) (Rows, Row) { results := make(Rows, len(last)) copy(results, last) diff --git a/model/stageslatency/stageslatency.go b/model/stageslatency/stageslatency.go index e0e6966..bd7be0e 100644 --- a/model/stageslatency/stageslatency.go +++ b/model/stageslatency/stageslatency.go @@ -2,7 +2,6 @@ package stageslatency import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/common" ) @@ -13,7 +12,7 @@ type StagesLatency struct { } // NewStagesLatency creates a new StagesLatency instance. -func NewStagesLatency(cfg *config.Config, db model.QueryExecutor) *StagesLatency { +func NewStagesLatency(cfg model.Config, db model.QueryExecutor) *StagesLatency { process := func(last, first Rows) (Rows, Row) { results := make(Rows, len(last)) copy(results, last) diff --git a/model/tableio/tableio.go b/model/tableio/tableio.go index 7f4ee39..782ef2e 100644 --- a/model/tableio/tableio.go +++ b/model/tableio/tableio.go @@ -2,7 +2,6 @@ package tableio import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/common" ) @@ -14,7 +13,7 @@ type TableIo struct { } // NewTableIo creates a new TableIo instance. -func NewTableIo(cfg *config.Config, db model.QueryExecutor) *TableIo { +func NewTableIo(cfg model.Config, db model.QueryExecutor) *TableIo { process := func(last, first Rows) (Rows, Row) { results := make(Rows, len(last)) copy(results, last) diff --git a/model/tablelocks/tablelocks.go b/model/tablelocks/tablelocks.go index b561914..3c5a941 100644 --- a/model/tablelocks/tablelocks.go +++ b/model/tablelocks/tablelocks.go @@ -2,7 +2,6 @@ package tablelocks import ( - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" ) @@ -12,7 +11,7 @@ type TableLocks struct { } // NewTableLocks creates a new TableLocks instance. -func NewTableLocks(cfg *config.Config, db model.QueryExecutor) *TableLocks { +func NewTableLocks(cfg model.Config, db model.QueryExecutor) *TableLocks { process := func(last, first Rows) (Rows, Row) { results := make(Rows, len(last)) copy(results, last) diff --git a/model/userlatency/userlatency.go b/model/userlatency/userlatency.go index aa44221..1a4c737 100644 --- a/model/userlatency/userlatency.go +++ b/model/userlatency/userlatency.go @@ -5,7 +5,6 @@ import ( "regexp" "strings" - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/processlist" ) @@ -18,7 +17,7 @@ type UserLatency struct { } // NewUserLatency creates a new UserLatency instance. -func NewUserLatency(cfg *config.Config, db model.QueryExecutor) *UserLatency { +func NewUserLatency(cfg model.Config, db model.QueryExecutor) *UserLatency { process := func(last, _ []Row) ([]Row, Row) { // last already contains aggregated rows; just copy and compute totals results := make([]Row, len(last)) diff --git a/presenter/fileinfolatency/fileinfolatency.go b/presenter/fileinfolatency/fileinfolatency.go index e8ec179..e4750de 100644 --- a/presenter/fileinfolatency/fileinfolatency.go +++ b/presenter/fileinfolatency/fileinfolatency.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/fileinfo" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -59,7 +59,7 @@ type Presenter struct { } // NewFileSummaryByInstance creates a presenter for FileIoLatency. -func NewFileSummaryByInstance(cfg *config.Config, db *sql.DB) *Presenter { +func NewFileSummaryByInstance(cfg model.Config, db *sql.DB) *Presenter { fiol := fileinfo.NewFileSummaryByInstance(cfg, db) bp := presenter.NewBasePresenter( fiol, diff --git a/presenter/memoryusage/memoryusage.go b/presenter/memoryusage/memoryusage.go index af922d6..23c36ae 100644 --- a/presenter/memoryusage/memoryusage.go +++ b/presenter/memoryusage/memoryusage.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/memoryusage" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -19,7 +19,7 @@ type Presenter struct { } // NewMemoryUsage creates a presenter for MemoryUsage. -func NewMemoryUsage(cfg *config.Config, db *sql.DB) *Presenter { +func NewMemoryUsage(cfg model.Config, db *sql.DB) *Presenter { mu := memoryusage.NewMemoryUsage(cfg, db) // Sort by CurrentBytesUsed descending, then Name ascending. diff --git a/presenter/mutexlatency/mutexlatency.go b/presenter/mutexlatency/mutexlatency.go index e90b0f0..844fc6d 100644 --- a/presenter/mutexlatency/mutexlatency.go +++ b/presenter/mutexlatency/mutexlatency.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/mutexlatency" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -43,7 +43,7 @@ type Presenter struct { } // NewMutexLatency creates a presenter for mutexlatency. -func NewMutexLatency(cfg *config.Config, db *sql.DB) *Presenter { +func NewMutexLatency(cfg model.Config, db *sql.DB) *Presenter { ml := mutexlatency.NewMutexLatency(cfg, db) bp := presenter.NewBasePresenter( ml, diff --git a/presenter/stageslatency/stageslatency.go b/presenter/stageslatency/stageslatency.go index 85cbe42..16406ff 100644 --- a/presenter/stageslatency/stageslatency.go +++ b/presenter/stageslatency/stageslatency.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/stageslatency" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -43,7 +43,7 @@ type Presenter struct { } // NewStagesLatency creates a presenter for stageslatency. -func NewStagesLatency(cfg *config.Config, db *sql.DB) *Presenter { +func NewStagesLatency(cfg model.Config, db *sql.DB) *Presenter { sl := stageslatency.NewStagesLatency(cfg, db) bp := presenter.NewBasePresenter( sl, diff --git a/presenter/tablelocklatency/tablelocklatency.go b/presenter/tablelocklatency/tablelocklatency.go index 38cb2c4..71ca797 100644 --- a/presenter/tablelocklatency/tablelocklatency.go +++ b/presenter/tablelocklatency/tablelocklatency.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/tablelocks" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -73,7 +73,7 @@ type Presenter struct { } // NewTableLockLatency creates a presenter for TableLockLatency. -func NewTableLockLatency(cfg *config.Config, db *sql.DB) *Presenter { +func NewTableLockLatency(cfg model.Config, db *sql.DB) *Presenter { tl := tablelocks.NewTableLocks(cfg, db) bp := presenter.NewBasePresenter( tl, diff --git a/presenter/userlatency/userlatency.go b/presenter/userlatency/userlatency.go index 091adbd..d67ddfb 100644 --- a/presenter/userlatency/userlatency.go +++ b/presenter/userlatency/userlatency.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/sjmudd/ps-top/config" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/userlatency" "github.com/sjmudd/ps-top/presenter" "github.com/sjmudd/ps-top/utils" @@ -106,7 +106,7 @@ type Presenter struct { } // NewUserLatency creates a presenter for UserLatency. -func NewUserLatency(cfg *config.Config, db *sql.DB) *Presenter { +func NewUserLatency(cfg model.Config, db *sql.DB) *Presenter { ul := userlatency.NewUserLatency(cfg, db) bp := presenter.NewBasePresenter( ul, diff --git a/pstable/pstable.go b/pstable/pstable.go index c4ec98c..ba3a97b 100644 --- a/pstable/pstable.go +++ b/pstable/pstable.go @@ -6,8 +6,8 @@ import ( "database/sql" "time" - "github.com/sjmudd/ps-top/config" "github.com/sjmudd/ps-top/log" + "github.com/sjmudd/ps-top/model" "github.com/sjmudd/ps-top/model/tableio" "github.com/sjmudd/ps-top/presenter/fileinfolatency" "github.com/sjmudd/ps-top/presenter/memoryusage" @@ -47,7 +47,7 @@ type Tabler interface { } // NewTabler returns a Tabler of the requested tablerType and parameters -func NewTabler(tablerType TablerType, cfg *config.Config, db *sql.DB) Tabler { +func NewTabler(tablerType TablerType, cfg model.Config, db *sql.DB) Tabler { var t Tabler log.Printf("NewTabler(%v,%v,%v)\n", tablerType, cfg, db)