Skip to content

Commit b7c6dce

Browse files
committed
add trigger mode
1 parent 8ef250d commit b7c6dce

File tree

2 files changed

+320
-8
lines changed

2 files changed

+320
-8
lines changed

src/renderer/src/views/ostrace/dataHandler.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ class OfflineDataProvider {
4141
name: string
4242
buttons: Array<{ name: string; color: string; id: string; numberId: number }>
4343
}> = []
44+
private triggerConfig: {
45+
enabled: boolean
46+
type: TaskType | null
47+
coreId: number | null
48+
id: number | null
49+
status: number | null
50+
} = {
51+
enabled: false,
52+
type: null,
53+
coreId: null,
54+
id: null,
55+
status: null
56+
}
4457

4558
constructor() {}
4659

@@ -89,6 +102,19 @@ class OfflineDataProvider {
89102
e.ts = e.ts - this.absoluteStartNumber
90103
}
91104
this.events.push(e)
105+
106+
// 检查新事件是否有触发,找到后立即发送消息
107+
if (this.triggerConfig.enabled) {
108+
if (this.checkTrigger(e)) {
109+
// 计算绝对时间
110+
111+
// 立即发送触发时间消息
112+
respond({
113+
type: 'triggerTime',
114+
payload: { triggerTime: e.ts }
115+
})
116+
}
117+
}
92118
}
93119
// Since timestamps are always increasing, we can directly append without sorting
94120

@@ -212,6 +238,34 @@ class OfflineDataProvider {
212238
return result
213239
}
214240

241+
setTriggerConfig(config: {
242+
enabled: boolean
243+
type: TaskType | null
244+
coreId: number | null
245+
id: number | null
246+
status: number | null
247+
}) {
248+
this.triggerConfig = config
249+
}
250+
251+
checkTrigger(event: OsEvent): boolean {
252+
if (!this.triggerConfig.enabled) return false
253+
if (
254+
this.triggerConfig.type === null ||
255+
this.triggerConfig.coreId === null ||
256+
this.triggerConfig.id === null ||
257+
this.triggerConfig.status === null
258+
) {
259+
return false
260+
}
261+
return (
262+
event.type === this.triggerConfig.type &&
263+
event.coreId === this.triggerConfig.coreId &&
264+
event.id === this.triggerConfig.id &&
265+
event.status === this.triggerConfig.status
266+
)
267+
}
268+
215269
getData(opts: { range?: TimelineChart.TimeGraphRange; resolution?: number }): {
216270
rows: TimelineChart.TimeGraphRowModel[]
217271
range: TimelineChart.TimeGraphRange
@@ -396,6 +450,16 @@ type InMsg =
396450
events: OsEvent[]
397451
}
398452
}
453+
| {
454+
type: 'setTriggerConfig'
455+
payload: {
456+
enabled: boolean
457+
type: TaskType | null
458+
coreId: number | null
459+
id: number | null
460+
status: number | null
461+
}
462+
}
399463

400464
type OutMsg =
401465
| {
@@ -422,6 +486,10 @@ type OutMsg =
422486
}
423487
}
424488
| { type: 'error'; payload: { message: string } }
489+
| {
490+
type: 'triggerTime'
491+
payload: { triggerTime: number }
492+
}
425493
| {
426494
type: 'foundState'
427495
payload: { id?: string; start?: bigint; event?: OsEvent }
@@ -642,6 +710,10 @@ self.onmessage = async (e: MessageEvent<InMsg>) => {
642710
// })
643711
return
644712
}
713+
if (msg.type === 'setTriggerConfig') {
714+
provider.setTriggerConfig(msg.payload)
715+
return
716+
}
645717
} catch (err: any) {
646718
console.error('onmessage error', err)
647719
respond({ type: 'error', payload: { message: err?.message || String(err) } })

0 commit comments

Comments
 (0)