1 Star 0 Fork 0

lin2631/sc-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
event_table.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
lin2631 提交于 2022-11-02 10:24 . format
/* 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])
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lin2631/sc-go.git
git@gitee.com:lin2631/sc-go.git
lin2631
sc-go
sc-go
467849e1f467

搜索帮助