lotus/extern/storage-sealing/stats.go
2021-01-21 17:40:50 +01:00

55 lines
970 B
Go

package sealing
import (
"sync"
"github.com/filecoin-project/go-state-types/abi"
)
type statSectorState int
const (
sstStaging statSectorState = iota
sstSealing
sstFailed
sstProving
nsst
)
type SectorStats struct {
lk sync.Mutex
bySector map[abi.SectorID]statSectorState
totals [nsst]uint64
}
func (ss *SectorStats) updateSector(id abi.SectorID, st SectorState) {
ss.lk.Lock()
defer ss.lk.Unlock()
oldst, found := ss.bySector[id]
if found {
ss.totals[oldst]--
}
sst := toStatState(st)
ss.bySector[id] = sst
ss.totals[sst]++
}
// return the number of sectors currently in the sealing pipeline
func (ss *SectorStats) curSealing() uint64 {
ss.lk.Lock()
defer ss.lk.Unlock()
return ss.totals[sstStaging] + ss.totals[sstSealing] + ss.totals[sstFailed]
}
// return the number of sectors waiting to enter the sealing pipeline
func (ss *SectorStats) curStaging() uint64 {
ss.lk.Lock()
defer ss.lk.Unlock()
return ss.totals[sstStaging]
}