cli: Show separate worker types in miner info

This commit is contained in:
Łukasz Magiera 2022-03-18 21:31:15 +01:00
parent 36f1dd7bb3
commit 5365ccfdb1
5 changed files with 60 additions and 12 deletions

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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

View File

@ -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) {