Skip to content

Commit f4b4ec6

Browse files
authored
Merge pull request #163 from buggregator/feature/59
Refactors profiler module
2 parents a40b232 + 1f6be9d commit f4b4ec6

File tree

25 files changed

+491
-263
lines changed

25 files changed

+491
-263
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"d3-graphviz": "^5.0.2",
8585
"d3-selection": "^3.0.0",
8686
"downloadjs": "^1.4.7",
87-
"flame-chart-js": "^2.3.1",
87+
"flame-chart-js": "^3.0",
8888
"highlight.js": "^11.7.0",
8989
"html-to-image": "^1.11.4",
9090
"lodash.debounce": "^4.0.8",

pages/profiler/[id].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ onMounted(getEvent);
6363
</div>
6464

6565
<div class="profiler-event__body">
66-
<ProfilerPage v-if="event" :event="event" />
66+
<ProfilerPage v-if="event" :event="event" class="p-5"/>
6767
</div>
6868
</main>
6969
</template>
@@ -86,5 +86,6 @@ onMounted(getEvent);
8686
8787
.profiler-event__body {
8888
@include layout-body;
89+
@apply h-full;
8990
}
9091
</style>
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { defineProps } from "vue";
2+
import { computed, defineProps } from "vue";
33
import type { NormalizedEvent } from "~/src/shared/types";
44
import { PreviewCard } from "~/src/shared/ui";
55
import type { Inspector } from "../../types";
@@ -9,14 +9,16 @@ type Props = {
99
event: NormalizedEvent<Inspector>;
1010
};
1111
12-
defineProps<Props>();
12+
const props = defineProps<Props>();
13+
14+
const eventLink = computed(() => `/inspector/${props.event.id}`);
1315
</script>
1416

1517
<template>
1618
<PreviewCard class="preview-card" :event="event">
17-
<div class="preview-card__content">
18-
<InspectorStatBoard :transaction="event.payload[0]" />
19-
</div>
19+
<NuxtLink :to="eventLink" class="preview-card__link">
20+
<InspectorStatBoard :transaction="event.payload[0]"/>
21+
</NuxtLink>
2022
</PreviewCard>
2123
</template>
2224

@@ -27,7 +29,7 @@ defineProps<Props>();
2729
@apply flex flex-col;
2830
}
2931
30-
.preview-card__content {
31-
@apply pb-2 flex-grow;
32+
.preview-card__link {
33+
@apply flex-grow cursor-pointer rounded-md overflow-hidden mb-2 border dark:border-gray-500;
3234
}
3335
</style>

src/entities/profiler/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
export interface ProfilerCost {
22
[key: string]: number,
3+
34
"ct": number,
45
"wt": number,
56
"cpu": number,
67
"mu": number,
78
"pmu": number
89
}
10+
911
export interface ProfilerEdge {
12+
id: string,
13+
parent: string | null,
1014
caller: string | null,
1115
callee: string,
1216
cost: ProfilerCost
@@ -20,7 +24,8 @@ export interface Profiler {
2024
},
2125
app_name: string,
2226
hostname: string,
27+
profile_uuid: string,
2328
date: number,
2429
peaks: ProfilerCost,
25-
edges: ProfilerEdges
30+
// edges: ProfilerEdges
2631
}

src/entities/profiler/ui/preview-card/preview-card.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ type Props = {
77
event: NormalizedEvent<Profiler>;
88
};
99
10-
defineProps<Props>();
10+
const props = defineProps<Props>();
11+
const eventLink = computed(() => `/profiler/${props.event.id}`);
1112
</script>
1213

1314
<template>
1415
<PreviewCard class="profiler-preview" :event="event">
15-
<div class="profiler-preview__link">
16-
<StatBoard :cost="event.payload.peaks" />
17-
</div>
16+
<NuxtLink tag="div" :to="eventLink" class="profiler-preview__link">
17+
<StatBoard :cost="event.payload.peaks"/>
18+
</NuxtLink>
1819
</PreviewCard>
1920
</template>
2021

@@ -26,6 +27,6 @@ defineProps<Props>();
2627
}
2728
2829
.profiler-preview__link {
29-
@apply pb-2 flex-grow;
30+
@apply flex-grow rounded-md overflow-hidden mb-2 border dark:border-gray-500;
3031
}
3132
</style>

src/entities/sentry/ui/preview-card/preview-card.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const props = withDefaults(defineProps<Props>(), {
1515
maxFrames: 3,
1616
});
1717
18+
const eventLink = computed(() => `/sentry/${props.event.id}`);
19+
1820
const exceptionValues = computed(
1921
() => props.event?.payload?.exception?.values || []
2022
);
@@ -27,12 +29,12 @@ const exception: Ref<Exception> = computed(() =>
2729
exceptionValues.value.length > 0
2830
? exceptionValues.value[0]
2931
: {
30-
type: "Unknown",
31-
value: "Something went wrong",
32-
stacktrace: {
33-
frames: [],
34-
},
35-
}
32+
type: "Unknown",
33+
value: "Something went wrong",
34+
stacktrace: {
35+
frames: [],
36+
},
37+
}
3638
);
3739
</script>
3840

@@ -43,31 +45,32 @@ const exception: Ref<Exception> = computed(() =>
4345
:exception="exception"
4446
:max-frames="maxFrames"
4547
>
46-
<div class="preview-card__content">
48+
<NuxtLink :to="eventLink" class="preview-card__link">
4749
<h3 class="preview-card__title">
4850
{{ exception.type }}
4951
</h3>
5052

51-
<pre class="preview-card__text" v-html="exception.value" />
52-
</div>
53+
<pre class="preview-card__text" v-html="exception.value"/>
54+
</NuxtLink>
5355
</SentryException>
5456

5557
<div v-if="message">
5658
<div class="preview-card__content">
57-
<pre class="preview-card__text" v-html="message" />
59+
<pre class="preview-card__text" v-html="message"/>
5860
</div>
5961
</div>
6062
</PreviewCard>
6163
</template>
6264

6365
<style lang="scss" scoped>
6466
@import "src/assets/mixins";
67+
6568
.preview-card {
6669
@apply flex flex-col;
6770
}
6871
69-
.preview-card__content {
70-
@apply block dark:bg-gray-900 bg-gray-100 p-3 rounded-t-md border border-purple-300 dark:border-gray-400;
72+
.preview-card__link {
73+
@apply cursor-pointer block dark:bg-gray-800 bg-gray-100 p-3 rounded-t-md border border-purple-300 dark:border-gray-500;
7174
}
7275
7376
.preview-card__title {
@@ -76,10 +79,10 @@ const exception: Ref<Exception> = computed(() =>
7679
7780
.preview-card__text {
7881
@include code-example();
79-
@apply text-sm break-words whitespace-pre-wrap mb-3 overflow-auto text-opacity-60;
82+
@apply text-sm break-words whitespace-pre-wrap mb-3 overflow-auto text-opacity-60 dark:bg-gray-900 p-3;
8083
}
8184
8285
.preview-card__frames {
83-
@apply border border-purple-200 dark:border-gray-600 flex-col justify-center w-full;
86+
@apply border border-purple-200 dark:border-gray-500 flex-col justify-center w-full;
8487
}
8588
</style>

src/entities/sentry/ui/sentry-exception/sentry-exception.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const exceptionFrames = computed(() => {
5858
}
5959
6060
.sentry-exception__header {
61-
@apply dark:bg-gray-900 bg-gray-100 p-3 rounded-t-md border border-purple-300 dark:border-gray-400 border-b-0;
61+
@apply dark:bg-gray-900 bg-gray-100 p-3 rounded-t-md border border-purple-300 dark:border-gray-500 border-b-0;
6262
}
6363
6464
.sentry-exception__title {
@@ -71,6 +71,6 @@ const exceptionFrames = computed(() => {
7171
}
7272
7373
.sentry-exception__frames {
74-
@apply flex-col justify-center w-full border border-purple-300 dark:border-gray-400 border-t-0 rounded-b-md overflow-hidden;
74+
@apply flex-col justify-center w-full border border-purple-300 dark:border-gray-500 border-t-0 rounded-b-md overflow-hidden;
7575
}
7676
</style>

src/entities/smtp/ui/preview-card/preview-card.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Props = {
1010
};
1111
1212
const props = defineProps<Props>();
13+
const eventLink = computed(() => `/smtp/${props.event.id}`);
1314
1415
const dateFormat = computed(() => moment(props.event.date).fromNow());
1516
@@ -20,19 +21,19 @@ const emailRecipient = computed(
2021

2122
<template>
2223
<PreviewCard class="smtp-preview" :event="event">
23-
<div class="smtp-preview__link">
24+
<NuxtLink :to="eventLink" class="smtp-preview__link">
2425
<h3 class="smtp-preview__link-title">
2526
{{ event.payload.subject }}
2627
</h3>
2728

2829
<div class="smtp-preview__link-text">
29-
<span v-if="emailRecipient"
30-
><strong>To:</strong> {{ emailRecipient }}
30+
<span v-if="emailRecipient">
31+
<strong>To:</strong> {{ emailRecipient }}
3132
</span>
3233

3334
<span>{{ dateFormat }}</span>
3435
</div>
35-
</div>
36+
</NuxtLink>
3637
</PreviewCard>
3738
</template>
3839

@@ -46,7 +47,7 @@ const emailRecipient = computed(
4647
@apply block flex items-stretch;
4748
@apply p-2 md:p-4;
4849
@apply flex flex-col;
49-
@apply border dark:border-gray-600;
50+
@apply border dark:border-gray-500 rounded-md overflow-hidden;
5051
@apply dark:bg-gray-800 dark:hover:bg-gray-900 hover:bg-white;
5152
}
5253

src/features/lib/cytoscape/prepare-data.ts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { TEdge, TNode } from "./types";
55

66
const { formatDuration, formatFileSize } = useFormats();
77

8-
98
const getColorForCallCount = (callCount: number) => {
109
if (callCount <= 1) {
1110
return '#fff'; // Sky Blue for 1 call
@@ -91,7 +90,7 @@ const invertHexColor = (hexInput: string) => {
9190
return (yiq >= 128) ? '#000' : '#fff';
9291
}
9392
const formatValue = (value: number, metric: string): string | number => {
94-
const metricFormatMap: Record<string, (v: number) => string|number> = {
93+
const metricFormatMap: Record<string, (v: number) => string | number> = {
9594
p_mu: (a: number) => `${a}%`,
9695
p_pmu: (a: number) => `${a}%`,
9796
p_cpu: (a: number) => `${a}%`,
@@ -118,28 +117,22 @@ export const prepareData: (
118117
nodes: TNode[],
119118
edges: TEdge[]
120119
}) =
121-
(edges: ProfilerEdges, metric , threshold = 1, percent = 10) => Object.values(edges)
120+
(edges: ProfilerEdges, metric, threshold = 1, percent = 10) => Object.values(edges)
122121
.reduce((arr, edge: ProfilerEdge, index) => {
123-
let nodeColor = '#fff';
124-
let nodeTextColor = '#000';
125-
let edgeColor = '#fff';
122+
let nodeColor: string = '#fff';
123+
let nodeTextColor: string = '#000';
124+
let edgeColor: string = '#fff';
126125
let edgeLabel: string = edge.cost.ct > 1 ? `${edge.cost.ct}x` : '';
127126

128-
if (metric === GraphTypes.CALLS) {
129-
const metricKey = `ct`;
130-
const isImportantNode: boolean = edge.cost[metricKey] >= percent;
131-
if (!isImportantNode) {
132-
return arr
133-
}
127+
const metricKey: string = metric === GraphTypes.CALLS ? `ct` : `p_${metric}`;
128+
const isImportantNode: boolean = edge.cost[metricKey] >= percent;
129+
if (!isImportantNode && edge.cost[metricKey] <= threshold) {
130+
return arr
131+
}
134132

133+
if (metric === GraphTypes.CALLS) {
135134
nodeColor = getColorForCallCount(edge.cost[metricKey]);
136135
} else {
137-
const metricKey = `p_${metric}`;
138-
const isImportantNode: boolean = edge.cost[metricKey] >= percent;
139-
if (!isImportantNode && edge.cost[metricKey] <= threshold) {
140-
return arr
141-
}
142-
143136
nodeColor = isImportantNode ? getColorForPercentCount(edge.cost[metricKey]) : '#fff';
144137
nodeTextColor = isImportantNode ? invertHexColor(nodeColor) : '#000';
145138

@@ -149,31 +142,23 @@ export const prepareData: (
149142
edgeLabel = `${formatValue(edge.cost[metricKey], metricKey)}${postfix}`;
150143
}
151144

152-
const metricKey = `p_${metric}`;
153-
154-
const isImportantNode = edge.cost.p_pmu > 10;
155-
156-
if (!isImportantNode && edge.cost[metricKey] <= threshold) {
157-
return arr
158-
}
159-
160145
arr.nodes.push({
161146
data: {
162-
id: edge.callee,
147+
id: edge.id,
163148
name: edge.callee as string,
164149
cost: edge.cost,
165150
color: nodeColor,
166151
textColor: nodeTextColor
167152
}
168153
})
169154

170-
const hasNodeSource = arr.nodes.find(node => node.data.id === edge.caller);
155+
const hasNodeSource = arr.nodes.find(node => node.data.id === edge.parent);
171156

172157
if (index > 0 && hasNodeSource) {
173158
arr.edges.push({
174159
data: {
175-
source: edge.caller || '',
176-
target: edge.callee,
160+
source: edge.parent || '',
161+
target: edge.id,
177162
color: edgeColor,
178163
label: edgeLabel,
179164
weight: edge.cost.ct,

src/features/lib/cytoscape/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ProfilerCost } from "~/src/entities/profiler/types";
33
export type TNode = {
44
data: {
55
id: string,
6+
parent: string | null,
67
name: string,
78
cost?: ProfilerCost,
89
color?: string,

0 commit comments

Comments
 (0)