diff --git a/cmd/lotus-miner/info.go b/cmd/lotus-miner/info.go index f6629fcf4..0d254e4f1 100644 --- a/cmd/lotus-miner/info.go +++ b/cmd/lotus-miner/info.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "math" corebig "math/big" "os" @@ -343,6 +344,38 @@ func handleMiningInfo(ctx context.Context, cctx *cli.Context, fullapi v0api.Full } } + { + fmt.Println() + + ws, err := nodeApi.WorkerStats(ctx) + if err != nil { + return xerrors.Errorf("getting worker stats: %w", err) + } + + var nseal, nwdpost, nwinpost int + + wloop: + for _, st := range ws { + if !st.Enabled { + continue + } + + for _, task := range st.Tasks { + if task == sealtasks.TTGenerateWindowPoSt { + nwdpost++ + continue wloop + } + if task == sealtasks.TTGenerateWinningPoSt { + nwinpost++ + continue wloop + } + } + nseal++ + } + + fmt.Printf("Workers: Seal(%d) WdPoSt(%d) WinPoSt(%d)\n", nseal, nwdpost, nwinpost) + } + if cctx.IsSet("blocks") { fmt.Println("Produced newest blocks:") err = producedBlocks(ctx, cctx.Int("blocks"), maddr, fullapi) @@ -350,9 +383,6 @@ func handleMiningInfo(ctx context.Context, cctx *cli.Context, fullapi v0api.Full return err } } - // TODO: grab actr state / info - // * Sealed sectors (count / bytes) - // * Power return nil } diff --git a/extern/sector-storage/sched_post.go b/extern/sector-storage/sched_post.go index cf22d5f93..58d79fc86 100644 --- a/extern/sector-storage/sched_post.go +++ b/extern/sector-storage/sched_post.go @@ -223,10 +223,10 @@ func (ps *poStScheduler) schedClose() { } } -func (ps *poStScheduler) WorkerStats(cb func(wid storiface.WorkerID, worker *workerHandle)) { +func (ps *poStScheduler) WorkerStats(ctx context.Context, cb func(ctx context.Context, wid storiface.WorkerID, worker *workerHandle)) { ps.lk.RLock() defer ps.lk.RUnlock() for id, w := range ps.workers { - cb(id, w) + cb(ctx, id, w) } } diff --git a/extern/sector-storage/stats.go b/extern/sector-storage/stats.go index 2090047a6..9b374f328 100644 --- a/extern/sector-storage/stats.go +++ b/extern/sector-storage/stats.go @@ -1,22 +1,39 @@ package sectorstorage import ( + "context" "time" "github.com/google/uuid" + "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" ) -func (m *Manager) WorkerStats() map[uuid.UUID]storiface.WorkerStats { +func (m *Manager) WorkerStats(ctx context.Context) map[uuid.UUID]storiface.WorkerStats { m.sched.workersLk.RLock() out := map[uuid.UUID]storiface.WorkerStats{} - cb := func(id storiface.WorkerID, handle *workerHandle) { + cb := func(ctx context.Context, id storiface.WorkerID, handle *workerHandle) { handle.lk.Lock() + + ctx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + + tt, err := handle.workerRpc.TaskTypes(ctx) + var taskList []sealtasks.TaskType + if err != nil { + log.Warnw("getting worker task types in WorkerStats", "error", err) + } else { + for taskType := range tt { + taskList = append(taskList, taskType) + } + } + out[uuid.UUID(id)] = storiface.WorkerStats{ Info: handle.info, + Tasks: taskList, Enabled: handle.enabled, MemUsedMin: handle.active.memUsedMin, MemUsedMax: handle.active.memUsedMax, @@ -27,14 +44,14 @@ func (m *Manager) WorkerStats() map[uuid.UUID]storiface.WorkerStats { } for id, handle := range m.sched.workers { - cb(id, handle) + cb(ctx, id, handle) } m.sched.workersLk.RUnlock() //list post workers - m.winningPoStSched.WorkerStats(cb) - m.windowPoStSched.WorkerStats(cb) + m.winningPoStSched.WorkerStats(ctx, cb) + m.windowPoStSched.WorkerStats(ctx, cb) return out } diff --git a/extern/sector-storage/storiface/worker.go b/extern/sector-storage/storiface/worker.go index 40ff047fa..e37df31b5 100644 --- a/extern/sector-storage/storiface/worker.go +++ b/extern/sector-storage/storiface/worker.go @@ -68,6 +68,7 @@ func (wr WorkerResources) ResourceSpec(spt abi.RegisteredSealProof, tt sealtasks type WorkerStats struct { Info WorkerInfo + Tasks []sealtasks.TaskType Enabled bool MemUsedMin uint64 diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 86dcc2182..dabf8d8d2 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -131,8 +131,8 @@ func (sm *StorageMinerAPI) ServeRemote(perm bool) func(w http.ResponseWriter, r } } -func (sm *StorageMinerAPI) WorkerStats(context.Context) (map[uuid.UUID]storiface.WorkerStats, error) { - return sm.StorageMgr.WorkerStats(), nil +func (sm *StorageMinerAPI) WorkerStats(ctx context.Context) (map[uuid.UUID]storiface.WorkerStats, error) { + return sm.StorageMgr.WorkerStats(ctx), nil } func (sm *StorageMinerAPI) WorkerJobs(ctx context.Context) (map[uuid.UUID][]storiface.WorkerJob, error) {