Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions model/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions model/fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package fileinfo

import (
"github.com/sjmudd/ps-top/config"
"github.com/sjmudd/ps-top/model"
)

Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions model/interfaces.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions model/memoryusage/memoryusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package memoryusage

import (
"github.com/sjmudd/ps-top/config"
"github.com/sjmudd/ps-top/model"
)

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions model/mutexlatency/mutexlatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions model/stageslatency/stageslatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions model/tableio/tableio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions model/tablelocks/tablelocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package tablelocks

import (
"github.com/sjmudd/ps-top/config"
"github.com/sjmudd/ps-top/model"
)

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions model/userlatency/userlatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions presenter/fileinfolatency/fileinfolatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions presenter/memoryusage/memoryusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions presenter/mutexlatency/mutexlatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions presenter/stageslatency/stageslatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions presenter/tablelocklatency/tablelocklatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions presenter/userlatency/userlatency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pstable/pstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Loading