代码拉取完成,页面将自动刷新
/* EventDB 的作用是存储模拟器模拟区间内所有的事件.
同时在使用外部调度器时,发生时间线变动时,方便修
改某个instance 在时间线中的所有的事件*/
package core
type EventTable struct {
ie map[InstanceKey]*eventTableRow // store all the instance event info
me []MachineEvent // store all the machines event info
}
func NewEventTable(i []InstanceEvent, m []MachineEvent) (table *EventTable) {
table = &EventTable{}
table.ie = make(map[InstanceKey]*eventTableRow)
table.me = m
for _, e := range i {
if e.AllocID != 0 {
continue
}
if _, ok := table.ie[e.InstanceId]; !ok {
table.ie[e.InstanceId] = &eventTableRow{curPeriod: 0, lifeEvents: []InstanceEvent{e}}
} else {
table.ie[e.InstanceId].lifeEvents = append(table.ie[e.InstanceId].lifeEvents, e)
}
}
for _, row := range table.ie {
row.sortPeriod()
}
return table
}
// one row in the EventTable.ie is the eventTableRow
// lifeEvents is the all instance events happend in the google trace data
// curPeriod is the events period the instance is experienced ,a period looks like : enable->schdule->finish
// periods is the result after sort the lifeEvents according to the period
type eventTableRow struct {
lifeEvents []InstanceEvent // the life events of the instance
curPeriod int // the periods is waitting for join in the timeline
periods [][]InstanceEvent
}
func (t *eventTableRow) sortPeriod() {
t.periods = make([][]InstanceEvent, 0)
periodStart := []int{}
if t.lifeEvents[0].Type != INSTANCEEnable {
periodStart = append(periodStart, 0)
}
for i, e := range t.lifeEvents {
if e.Type == INSTANCEEnable {
periodStart = append(periodStart, i)
}
}
periodStart = append(periodStart, len(t.lifeEvents))
for i := 0; i <= len(periodStart)-2; i++ {
start := periodStart[i]
end := periodStart[i+1]
t.periods = append(t.periods, t.lifeEvents[start:end])
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。