2020-08-17 13:26:18 +00:00
|
|
|
package sectorstorage
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-08-27 21:14:33 +00:00
|
|
|
import (
|
2020-09-23 17:26:26 +00:00
|
|
|
"time"
|
2020-09-30 17:32:19 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
2020-09-30 17:32:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
2020-08-27 21:14:33 +00:00
|
|
|
)
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
func (m *Manager) WorkerStats() map[uuid.UUID]storiface.WorkerStats {
|
2020-08-13 09:31:18 +00:00
|
|
|
m.sched.workersLk.RLock()
|
|
|
|
defer m.sched.workersLk.RUnlock()
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
out := map[uuid.UUID]storiface.WorkerStats{}
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-04-27 18:37:31 +00:00
|
|
|
for id, handle := range m.sched.workers {
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(id)] = storiface.WorkerStats{
|
|
|
|
Info: handle.info,
|
|
|
|
Enabled: handle.enabled,
|
|
|
|
|
2020-04-27 20:43:42 +00:00
|
|
|
MemUsedMin: handle.active.memUsedMin,
|
|
|
|
MemUsedMax: handle.active.memUsedMax,
|
|
|
|
GpuUsed: handle.active.gpuUsed,
|
|
|
|
CpuUse: handle.active.cpuUse,
|
2020-03-23 14:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
2020-07-21 18:01:25 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
func (m *Manager) WorkerJobs() map[uuid.UUID][]storiface.WorkerJob {
|
|
|
|
out := map[uuid.UUID][]storiface.WorkerJob{}
|
2020-09-23 17:26:26 +00:00
|
|
|
calls := map[storiface.CallID]struct{}{}
|
2020-07-21 18:01:25 +00:00
|
|
|
|
2020-10-28 13:23:38 +00:00
|
|
|
for _, t := range m.sched.workTracker.Running() {
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(t.worker)] = append(out[uuid.UUID(t.worker)], t.job)
|
2020-09-23 17:26:26 +00:00
|
|
|
calls[t.job.ID] = struct{}{}
|
2020-09-23 12:56:37 +00:00
|
|
|
}
|
2020-08-27 21:14:33 +00:00
|
|
|
|
2020-09-23 17:26:26 +00:00
|
|
|
m.sched.workersLk.RLock()
|
|
|
|
|
2020-09-23 12:56:37 +00:00
|
|
|
for id, handle := range m.sched.workers {
|
2020-08-27 21:14:33 +00:00
|
|
|
handle.wndLk.Lock()
|
2020-08-28 16:26:17 +00:00
|
|
|
for wi, window := range handle.activeWindows {
|
2020-08-27 21:14:33 +00:00
|
|
|
for _, request := range window.todo {
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(id)] = append(out[uuid.UUID(id)], storiface.WorkerJob{
|
2020-09-07 14:12:46 +00:00
|
|
|
ID: storiface.UndefCall,
|
2020-08-27 21:14:33 +00:00
|
|
|
Sector: request.sector,
|
|
|
|
Task: request.taskType,
|
2020-08-28 16:26:17 +00:00
|
|
|
RunWait: wi + 1,
|
2020-08-27 21:14:33 +00:00
|
|
|
Start: request.start,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handle.wndLk.Unlock()
|
2020-07-21 18:01:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 17:26:26 +00:00
|
|
|
m.sched.workersLk.RUnlock()
|
|
|
|
|
|
|
|
m.workLk.Lock()
|
|
|
|
defer m.workLk.Unlock()
|
|
|
|
|
2020-09-24 09:55:11 +00:00
|
|
|
for id, work := range m.callToWork {
|
2020-09-23 17:26:26 +00:00
|
|
|
_, found := calls[id]
|
|
|
|
if found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID{}] = append(out[uuid.UUID{}], storiface.WorkerJob{
|
2020-09-23 17:26:26 +00:00
|
|
|
ID: id,
|
|
|
|
Sector: id.Sector,
|
2020-09-24 09:55:11 +00:00
|
|
|
Task: work.Method,
|
2020-09-23 17:26:26 +00:00
|
|
|
RunWait: -1,
|
|
|
|
Start: time.Time{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-21 18:01:25 +00:00
|
|
|
return out
|
|
|
|
}
|