milo task status
This commit is contained in:
@@ -69,6 +69,9 @@ local context = {
|
||||
plugins = { },
|
||||
loggers = { },
|
||||
|
||||
taskTimer = 0,
|
||||
taskCounter = 0,
|
||||
|
||||
storage = Storage(),
|
||||
turtleInventory = {
|
||||
name = localName,
|
||||
@@ -119,6 +122,7 @@ end)
|
||||
|
||||
_G._debug('Tasks\n-----')
|
||||
for _, task in ipairs(context.tasks) do
|
||||
task.execTime = 0
|
||||
_G._debug('%d: %s', task.priority, task.name)
|
||||
end
|
||||
|
||||
@@ -143,15 +147,20 @@ Event.on({ 'milo_cycle', 'milo_queue' }, function(e)
|
||||
end
|
||||
|
||||
if e == 'milo_cycle' and not Milo:isCraftingPaused() then
|
||||
local taskTimer = Util.timer()
|
||||
Milo:resetCraftingStatus()
|
||||
|
||||
for _, task in ipairs(context.tasks) do
|
||||
local timer = Util.timer()
|
||||
local s, m = pcall(function() task:cycle(context) end)
|
||||
if not s and m then
|
||||
_G._debug(task.name .. ' crashed')
|
||||
_G._debug(m)
|
||||
end
|
||||
task.execTime = task.execTime + timer()
|
||||
end
|
||||
context.taskTimer = context.taskTimer + taskTimer()
|
||||
context.taskCounter = context.taskCounter + 1
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ function Storage:listItems(throttle)
|
||||
return self.cache
|
||||
end
|
||||
|
||||
local timer = Util.Timer()
|
||||
local timer = Util.timer()
|
||||
local cache = { }
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
|
||||
@@ -100,6 +100,14 @@ local function createPage(node)
|
||||
tpsText = UI.Text {
|
||||
x = 18, ex = -2, y = 3,
|
||||
},
|
||||
tasksLabel = UI.Text {
|
||||
x = -18, y = 3,
|
||||
value = 'Proc time',
|
||||
},
|
||||
tasksText = UI.Text {
|
||||
x = -6, ex = -2, y = 3,
|
||||
align = 'right',
|
||||
},
|
||||
storageLabel = UI.Text {
|
||||
x = 2, ex = -1, y = 6,
|
||||
},
|
||||
@@ -157,6 +165,20 @@ local function createPage(node)
|
||||
--visible = true,
|
||||
},
|
||||
},
|
||||
[6] = UI.Tab {
|
||||
tabTitle = 'Tasks',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
values = context.tasks,
|
||||
columns = {
|
||||
{ heading = 'Priority', key = 'priority', width = 5 },
|
||||
{ heading = 'Name', key = 'name' },
|
||||
{ heading = 'Avg', key = 'avg', width = 7, align = 'right' },
|
||||
{ heading = '%', key = 'perc', width = 7, align = 'right' },
|
||||
},
|
||||
sortColumn = 'priority',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -165,6 +187,7 @@ local function createPage(node)
|
||||
local usageTab = page.tabs[3]
|
||||
local stateTab = page.tabs[4]
|
||||
local activityTab = page.tabs[5]
|
||||
local taskTab = page.tabs[6]
|
||||
|
||||
local function getStorageStats()
|
||||
local stats = { }
|
||||
@@ -310,6 +333,34 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
UI.Tab.disable(self)
|
||||
end
|
||||
|
||||
function taskTab.grid:getDisplayValues(row)
|
||||
return {
|
||||
name = row.name,
|
||||
priority = row.priority,
|
||||
avg = Util.round(row.execTime / context.taskCounter * 1000) .. ' ms',
|
||||
perc = Util.round(row.execTime / context.taskTimer * 100) .. '%',
|
||||
}
|
||||
end
|
||||
|
||||
function taskTab:refresh()
|
||||
self.grid:update()
|
||||
end
|
||||
|
||||
function taskTab:enable()
|
||||
self:refresh()
|
||||
self.handle = Event.onInterval(5, function()
|
||||
self:refresh()
|
||||
self.grid:draw()
|
||||
self:sync()
|
||||
end)
|
||||
UI.Tab.enable(self)
|
||||
end
|
||||
|
||||
function taskTab:disable()
|
||||
Event.off(self.handle)
|
||||
UI.Tab.disable(self)
|
||||
end
|
||||
|
||||
function overviewTab:draw()
|
||||
local _, stats = getStorageStats()
|
||||
|
||||
@@ -317,6 +368,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
self.onlineText.value = context.storage:isOnline() and 'Online' or 'Offline'
|
||||
|
||||
self.tpsText.value = tostring(Util.round(self.tasks / (os.clock() - self.timer), 2))
|
||||
self.tasksText.value = tostring(Util.round(context.taskTimer / context.taskCounter, 2))
|
||||
|
||||
local total, crafted = 0, 0
|
||||
for _,v in pairs(context.craftingQueue) do
|
||||
|
||||
Reference in New Issue
Block a user