Skip to content

Commit b64c76c

Browse files
committed
optimise trace
+ strip /^<anonymous>/ from trace + strip name if same as link
1 parent c3d2ffd commit b64c76c

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/api-monitor-cs-main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const tick = new Timer(
5050
function apiMonitorPostMetric() {
5151
meanExecutionTime.add(tick.executionTime);
5252
// adaptive update-frequency
53-
if (tick.executionTime < 3) {
53+
if (0 < tick.executionTime && tick.executionTime < 3) {
5454
tick.options.animation = true;
5555
} else {
5656
tick.options.animation = false;

src/api/wrappers.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { TPanelVisibilityMap } from '@/api/settings.ts';
1616
import { sha256 } from 'js-sha256';
1717

1818
export type TCallstack = {
19-
name: string;
19+
name: string | 0;
2020
link: string;
2121
}[];
2222
export enum ETimeType {
@@ -78,17 +78,25 @@ function createCallstack(e: Error): TCallstack {
7878
// loop from the end, excluding error name and self trace
7979
for (let n = arr.length - 1; n > 1; n--) {
8080
let v = arr[n];
81+
82+
if (v.indexOf(selfCallLink) >= 0) {
83+
continue;
84+
}
85+
8186
v = v.replace(REGEX_STACKTRACE_PREFIX, '');
8287
const link = v.replace(REGEX_STACKTRACE_LINK, '$1').trim();
8388

84-
if (link.indexOf(selfCallLink) >= 0) {
89+
if (link.startsWith('<anonymous>')) {
8590
continue;
8691
}
8792

88-
rv.push({
89-
name: v.replace(REGEX_STACKTRACE_NAME, '$1').trim(),
90-
link,
91-
});
93+
let name: string | 0 = v.replace(REGEX_STACKTRACE_NAME, '$1').trim();
94+
95+
if (name === link) {
96+
name = 0;
97+
}
98+
99+
rv.push({ name, link });
92100
}
93101

94102
if (!rv.length) {

src/view/components/CallstackLink.svelte

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
} from '@/api/const.ts';
88
99
export let href: string = '';
10-
export let name: string = '';
11-
let beenClicked = false;
10+
export let name: string | 0 = 0;
11+
let isSeen = false;
1212
1313
$: lineNumber = parseInt(
1414
href?.replace(REGEX_STACKTRACE_LINE_NUMBER, '$1'),
@@ -18,10 +18,7 @@
1818
href.replace(REGEX_STACKTRACE_COLUMN_NUMBER, '$1'),
1919
10
2020
);
21-
$: isSourceLess =
22-
!isFinite(lineNumber) ||
23-
href.startsWith('<anonymous>') ||
24-
TAG_INVALID_CALLSTACK === href;
21+
$: isSourceLess = !isFinite(lineNumber) || TAG_INVALID_CALLSTACK === href;
2522
2623
function showStackTraceResource(e: MouseEvent) {
2724
e.preventDefault();
@@ -34,18 +31,18 @@
3431
columnNumber - 1
3532
);
3633
37-
beenClicked = true;
34+
isSeen = true;
3835
}
3936
</script>
4037

4138
{#if isSourceLess}
42-
<i class="no-link">{`${name} ${href === name ? '' : href}`}</i>
39+
<i class="no-link">{`${name ? name : ''} ${href}`}</i>
4340
{:else}
4441
<a
4542
{href}
4643
title={`${lineNumber}:${columnNumber}`}
47-
class:beenClicked
48-
on:click={showStackTraceResource}>{name}</a
44+
class:isSeen
45+
on:click={showStackTraceResource}>{name || href}</a
4946
>
5047
{/if}
5148

@@ -64,7 +61,7 @@
6461
text-overflow: ellipsis;
6562
max-width: 25rem;
6663
67-
&.beenClicked {
64+
&.isSeen {
6865
color: var(--link-visited-text);
6966
background-color: var(--link-visited-bg);
7067
}

0 commit comments

Comments
 (0)