Skip to content

Commit 12a0567

Browse files
committed
[feat]:add trace overwrite mode
1 parent c524ea0 commit 12a0567

File tree

5 files changed

+94
-19
lines changed

5 files changed

+94
-19
lines changed

docs/um/trace/image-5.png

6.72 KB
Loading

docs/um/trace/ow.gif

1020 KB
Loading

docs/um/trace/trace.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ The Trace window provides an interface for viewing and exporting data. Users can
77
>[!INFO]
88
> Currently, Trace has a maximum storage capacity of 50,000 entries. When this limit is exceeded, the oldest data will be automatically deleted.
99
10+
## Overwrite Mode
11+
12+
Use below button to switch between overwrite mode and scroll mode.
13+
![alt text](image-5.png)
14+
15+
In overwrite mode, the Trace window will overwrite the oldest data when the maximum storage capacity is exceeded.
16+
![ow](ow.gif)
17+
18+
19+
20+
21+
1022
## Filter
1123

1224
### Filter By Device

src/renderer/src/views/uds/components/config/tester/service.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@
9393
v-for="(item, index) in reqArrayStr"
9494
:key="index"
9595
:style="{
96+
padding: '1px',
9697
backgroundColor:
9798
index % 2 == 0
98-
? 'var(--el-color-info-light-9)'
99-
: 'var(--el-color-primary-light-9)'
99+
? 'var(--el-color-info-light-7)'
100+
: 'var(--el-color-primary-light-7)'
100101
}"
101102
class="param"
102103
>{{ item }}</span
@@ -109,10 +110,11 @@
109110
v-for="(item, index) in respArrayStr"
110111
:key="index"
111112
:style="{
113+
padding: '1px',
112114
backgroundColor:
113115
index % 2 == 0
114-
? 'var(--el-color-info-light-9)'
115-
: 'var(--el-color-primary-light-9)'
116+
? 'var(--el-color-info-light-7)'
117+
: 'var(--el-color-primary-light-7)'
116118
}"
117119
class="param"
118120
>{{ item }}</span

src/renderer/src/views/uds/components/trace.vue

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
<Icon :icon="isPaused ? playIcon : pauseIcon" />
2727
</el-button>
2828
</el-tooltip>
29+
<el-tooltip effect="light" content="Swtich Overwrite/Scroll" placement="bottom">
30+
<el-button
31+
:type="isOverwrite ? 'success' : 'primary'"
32+
link
33+
:class="{ 'pause-active': isOverwrite }"
34+
@click="toggleOverwrite"
35+
>
36+
<Icon :icon="switchIcon" />
37+
</el-button>
38+
</el-tooltip>
2939
</el-button-group>
3040

3141
<el-divider v-if="showFilter" direction="vertical" />
@@ -105,6 +115,7 @@ import filterIcon from '@iconify/icons-material-symbols/filter-alt-off-outline'
105115
import saveIcon from '@iconify/icons-material-symbols/save'
106116
import pauseIcon from '@iconify/icons-material-symbols/pause-circle-outline'
107117
import playIcon from '@iconify/icons-material-symbols/play-circle-outline'
118+
import switchIcon from '@iconify/icons-material-symbols/cameraswitch-outline-rounded'
108119
import scrollIcon1 from '@iconify/icons-material-symbols/autoplay'
109120
import scrollIcon2 from '@iconify/icons-material-symbols/autopause'
110121
import ExcelJS from 'exceljs'
@@ -121,7 +132,8 @@ interface LogData {
121132
dir?: 'Tx' | 'Rx' | '--'
122133
data: string
123134
ts: string
124-
id?: string
135+
id: string
136+
key?: string
125137
dlc?: number
126138
len?: number
127139
device: string
@@ -132,7 +144,19 @@ interface LogData {
132144
seqIndex?: number
133145
children?: LogData[] | { name: string; data: string }[]
134146
}
135-
147+
const isOverwrite = ref(false)
148+
function toggleOverwrite() {
149+
isOverwrite.value = !isOverwrite.value
150+
if (isOverwrite.value) {
151+
// clearLog('Switch Overwrite Mode')
152+
// remove duplicate data
153+
const uniqueData = allLogData.filter(
154+
(item, index, self) => index === self.findIndex((t) => t.key === item.key)
155+
)
156+
allLogData = uniqueData
157+
grid.loadData(allLogData)
158+
}
159+
}
136160
const database = useDataStore()
137161
const instanceList = ref<string[]>([])
138162
const allInstanceList = computed(() => {
@@ -199,10 +223,12 @@ watch(globalStart, (val) => {
199223
}
200224
})
201225
226+
let expandskey: string[] = []
202227
function clearLog(msg = 'Clear Trace') {
203228
allLogData = []
204229
205230
scrollY = -1
231+
expandskey = []
206232
//TODO:
207233
grid.loadData([])
208234
grid.scrollYTo(0)
@@ -233,15 +259,36 @@ const maxLogCount = 50000
233259
const showLogCount = 500
234260
235261
function insertData2(data: LogData[]) {
236-
allLogData.push(...data)
262+
if (isOverwrite.value) {
263+
for (const item of data) {
264+
if (item.id) {
265+
// Find index of existing log with same id
266+
const idx = allLogData.findIndex((log) => log.key === item.key)
267+
if (idx !== -1) {
268+
// Overwrite the existing log entry
269+
allLogData[idx] = item
270+
} else {
271+
allLogData.push(item)
272+
}
273+
} else {
274+
allLogData.push(item)
275+
}
276+
}
277+
} else {
278+
allLogData.push(...data)
279+
}
237280
if (allLogData.length > maxLogCount) {
238281
const excessRows = allLogData.length - maxLogCount
239282
allLogData.splice(0, excessRows)
240283
}
241284
242285
// 根据暂停状态决定加载多少数据
243286
const displayData = isPaused.value ? allLogData : allLogData.slice(-showLogCount)
287+
244288
grid.loadData(displayData)
289+
if (isOverwrite.value) {
290+
grid.setExpandRowKeys(expandskey)
291+
}
245292
grid.scrollYTo(99999999999)
246293
}
247294
function logDisplay(method: string, vals: LogItem[]) {
@@ -250,6 +297,7 @@ function logDisplay(method: string, vals: LogItem[]) {
250297
251298
const logData: LogData[] = []
252299
const insertData = (data: LogData) => {
300+
data.key = `${data.channel}-${data.device}-${data.id}`
253301
logData.push(data)
254302
}
255303
for (const val of vals) {
@@ -268,7 +316,8 @@ function logDisplay(method: string, vals: LogItem[]) {
268316
channel: val.instance,
269317
msgType: CanMsgType2Str(val.message.data.msgType),
270318
name: val.message.data.name,
271-
children: val.message.data.children
319+
children: val.message.data.children,
320+
key: `${val.instance}-${val.message.data.id}`
272321
})
273322
} else if (val.message.method == 'ipBase') {
274323
insertData({
@@ -311,7 +360,7 @@ function logDisplay(method: string, vals: LogItem[]) {
311360
name: testerName,
312361
data: `${data2str(val.message.data.recvData ? val.message.data.recvData : new Uint8Array(0))}`.trim(),
313362
ts: (val.message.data.ts / 1000000).toFixed(3),
314-
id: '',
363+
id: testerName,
315364
len: val.message.data.recvData ? val.message.data.recvData.length : 0,
316365
device: val.label,
317366
channel: val.instance,
@@ -337,7 +386,7 @@ function logDisplay(method: string, vals: LogItem[]) {
337386
name: testerName,
338387
data: `${data2str(val.message.data.recvData ? val.message.data.recvData : new Uint8Array(0))}`.trim(),
339388
ts: (val.message.data.ts / 1000000).toFixed(3),
340-
id: '',
389+
id: testerName,
341390
len: val.message.data.recvData ? val.message.data.recvData.length : 0,
342391
device: val.label,
343392
channel: val.instance,
@@ -352,7 +401,7 @@ function logDisplay(method: string, vals: LogItem[]) {
352401
name: '',
353402
data: val.message.data.msg,
354403
ts: (val.message.data.ts / 1000000).toFixed(3),
355-
id: '',
404+
id: 'canError',
356405
len: 0,
357406
device: val.label,
358407
channel: val.instance,
@@ -383,7 +432,7 @@ function logDisplay(method: string, vals: LogItem[]) {
383432
name: '',
384433
data: val.message.data.msg,
385434
ts: (val.message.data.ts / 1000000).toFixed(3),
386-
id: '',
435+
id: 'linError',
387436
len: 0,
388437
device: val.label,
389438
channel: val.instance,
@@ -396,7 +445,7 @@ function logDisplay(method: string, vals: LogItem[]) {
396445
name: '',
397446
data: val.message.data.msg,
398447
ts: (val.message.data.ts / 1000000).toFixed(3),
399-
id: '',
448+
id: 'linEvent',
400449
len: 0,
401450
device: val.label,
402451
channel: val.instance,
@@ -408,7 +457,7 @@ function logDisplay(method: string, vals: LogItem[]) {
408457
name: '',
409458
data: val.message.data.msg,
410459
ts: (val.message.data.ts / 1000000).toFixed(3),
411-
id: '',
460+
id: 'udsScript',
412461
len: 0,
413462
device: val.label,
414463
channel: val.instance,
@@ -420,7 +469,7 @@ function logDisplay(method: string, vals: LogItem[]) {
420469
name: '',
421470
data: val.message.data.msg,
422471
ts: (val.message.data.ts / 1000000).toFixed(3),
423-
id: '',
472+
id: 'udsSystem',
424473
len: 0,
425474
device: val.label,
426475
channel: val.instance,
@@ -721,11 +770,16 @@ watch(
721770
},
722771
{ deep: true }
723772
)
724-
watch(isPaused, (v) => {
725-
if (v) {
773+
watch([isPaused, isOverwrite], (v) => {
774+
if (v[1]) {
726775
columes.value[0].type = 'tree'
727776
} else {
728-
columes.value[0].type = undefined
777+
if (v[0]) {
778+
columes.value[0].type = 'tree'
779+
} else {
780+
columes.value[0].type = undefined
781+
scrollY = -1
782+
}
729783
}
730784
})
731785
@@ -749,6 +803,7 @@ onMounted(() => {
749803
DISABLED: true,
750804
HEADER_HEIGHT: 28,
751805
CELL_HEIGHT: 28,
806+
ROW_KEY: 'key',
752807
ENABLE_SELECTOR: false,
753808
ENABLE_HISTORY: false,
754809
ENABLE_COPY: false,
@@ -813,17 +868,23 @@ onMounted(() => {
813868
814869
grid.on('onScrollY', (v) => {
815870
if (!isPaused.value && scrollY !== -1 && v < scrollY) {
816-
isPaused.value = true
871+
if (!isOverwrite.value) {
872+
isPaused.value = true
873+
}
817874
} else {
818875
scrollY = v
819876
}
820877
})
878+
grid.on('expandChange', (v) => {
879+
expandskey = v
880+
})
821881
})
822882
watch([tableWidth, tableHeight], () => {
823883
grid.loadConfig({
824884
WIDTH: tableWidth.value,
825885
HEIGHT: tableHeight.value
826886
})
887+
grid.setExpandRowKeys(expandskey)
827888
})
828889
829890
onUnmounted(() => {

0 commit comments

Comments
 (0)