Fix Async Profiling widget (#438)

This commit is contained in:
Fine0830 2024-12-03 19:16:51 +08:00 committed by GitHub
parent ea0f5e5f62
commit fbeeca8d9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 26 deletions

View File

@ -43,14 +43,25 @@ limitations under the License. -->
import { useAsyncProfilingStore } from "@/store/modules/async-profiling"; import { useAsyncProfilingStore } from "@/store/modules/async-profiling";
import type { Instance } from "@/types/selector"; import type { Instance } from "@/types/selector";
import type { Option } from "@/types/app"; import type { Option } from "@/types/app";
import { EventsMap } from "./data"; import { EventsMap, ProfilingEvents, JFREventType } from "./data";
const { t } = useI18n(); const { t } = useI18n();
const asyncProfilingStore = useAsyncProfilingStore(); const asyncProfilingStore = useAsyncProfilingStore();
const serviceInstanceIds = ref<string[]>([]); const serviceInstanceIds = ref<string[]>([]);
const selectedEventType = ref<string>(""); const selectedEventType = ref<string>("");
const eventTypes = computed(() => const eventTypes = computed(() =>
(asyncProfilingStore.selectedTask.events ?? []).map((d: string) => ({ label: d, value: d })), (asyncProfilingStore.selectedTask.events ?? [])
.map((d: string) => {
if (d === ProfilingEvents[1]) {
return [
{ label: JFREventType.OBJECT_ALLOCATION_IN_NEW_TLAB, value: JFREventType.OBJECT_ALLOCATION_IN_NEW_TLAB },
{ label: JFREventType.OBJECT_ALLOCATION_OUTSIDE_TLAB, value: JFREventType.OBJECT_ALLOCATION_OUTSIDE_TLAB },
];
}
return { label: d, value: d };
})
.flat(),
); );
const instances = computed(() => const instances = computed(() =>
asyncProfilingStore.instances.filter((d: Instance) => asyncProfilingStore.instances.filter((d: Instance) =>
@ -98,7 +109,7 @@ limitations under the License. -->
} }
.filter-events { .filter-events {
width: 200px; width: 300px;
margin-right: 10px; margin-right: 10px;
} }
</style> </style>

View File

@ -119,8 +119,8 @@ limitations under the License. -->
duration.value = val; duration.value = val;
} }
function changeInstances(options: Option[]) { function changeInstances(options: { id: string }[]) {
serviceInstanceIds.value = options.map((d: Option) => d.value); serviceInstanceIds.value = options.map((d: { id: string }) => d.id);
} }
function disableEvents(item: string) { function disableEvents(item: string) {

View File

@ -54,7 +54,7 @@ limitations under the License. -->
<div> <div>
<h5 class="mb-10">{{ t("task") }}.</h5> <h5 class="mb-10">{{ t("task") }}.</h5>
<div class="mb-10 clear item"> <div class="mb-10 clear item">
<span class="g-sm-4 grey">{{ t("id") }}:</span> <span class="g-sm-4 grey">ID:</span>
<span class="g-sm-8 wba">{{ asyncProfilingStore.selectedTask.id }}</span> <span class="g-sm-8 wba">{{ asyncProfilingStore.selectedTask.id }}</span>
</div> </div>
<div class="mb-10 clear item"> <div class="mb-10 clear item">
@ -157,8 +157,10 @@ limitations under the License. -->
} }
async function changeTask(item: TaskListItem) { async function changeTask(item: TaskListItem) {
asyncProfilingStore.setSelectedTask(item); if (item.id !== asyncProfilingStore.selectedTask.id) {
asyncProfilingStore.setAnalyzeTrees([]); asyncProfilingStore.setAnalyzeTrees([]);
asyncProfilingStore.setSelectedTask(item);
}
service.value = (selectorStore.services.filter((s: Service) => s.id === item.serviceId)[0] ?? {}).label; service.value = (selectorStore.services.filter((s: Service) => s.id === item.serviceId)[0] ?? {}).label;
const res = await asyncProfilingStore.getTaskLogs({ taskId: item.id }); const res = await asyncProfilingStore.getTaskLogs({ taskId: item.id });

View File

@ -29,7 +29,8 @@ export enum EventsMap {
CTIMER = "EXECUTION_SAMPLE", CTIMER = "EXECUTION_SAMPLE",
ITIMER = "EXECUTION_SAMPLE", ITIMER = "EXECUTION_SAMPLE",
LOCK = "LOCK", LOCK = "LOCK",
ALLOC = "OBJECT_ALLOCATION_OUTSIDE_TLAB", OBJECT_ALLOCATION_IN_NEW_TLAB = "OBJECT_ALLOCATION_IN_NEW_TLAB",
OBJECT_ALLOCATION_OUTSIDE_TLAB = "OBJECT_ALLOCATION_OUTSIDE_TLAB",
} }
export enum JFREventType { export enum JFREventType {

View File

@ -52,7 +52,7 @@ limitations under the License. -->
if (!ebpfStore.analyzeTrees.length) { if (!ebpfStore.analyzeTrees.length) {
return (stackTree.value = null); return (stackTree.value = null);
} }
const root: StackElement = { let root: StackElement = {
parentId: "0", parentId: "0",
originId: "1", originId: "1",
name: "Virtual Root", name: "Virtual Root",
@ -66,21 +66,28 @@ limitations under the License. -->
rateOfParent: "", rateOfParent: "",
}; };
countRange(); countRange();
for (const tree of ebpfStore.analyzeTrees) { if (props.type === ComponentType) {
const ele = processTree(tree.elements); const elements = processTree(ebpfStore.analyzeTrees[0].elements);
root.children && root.children.push(ele); stackTree.value = elements;
root = { ...root, ...elements };
} else {
for (const tree of ebpfStore.analyzeTrees) {
const ele = processTree(tree.elements);
root.children && root.children.push(ele);
}
const param = (root.children || []).reduce(
(prev: number[], curr: StackElement) => {
prev[0] += curr.value;
prev[1] += curr.dumpCount;
return prev;
},
[0, 0],
);
root.value = param[0];
root.dumpCount = param[1];
stackTree.value = root;
} }
const param = (root.children || []).reduce(
(prev: number[], curr: StackElement) => {
prev[0] += curr.value;
prev[1] += curr.dumpCount;
return prev;
},
[0, 0],
);
root.value = param[0];
root.dumpCount = param[1];
stackTree.value = root;
const width = (graph.value && graph.value.getBoundingClientRect().width) || 0; const width = (graph.value && graph.value.getBoundingClientRect().width) || 0;
const w = width < 800 ? 802 : width; const w = width < 800 ? 802 : width;
flameChart.value = flamegraph() flameChart.value = flamegraph()
@ -165,9 +172,9 @@ limitations under the License. -->
obj[item.originId] = item; obj[item.originId] = item;
} }
const scale = d3.scaleLinear().domain([min.value, max.value]).range([1, 200]); const scale = d3.scaleLinear().domain([min.value, max.value]).range([1, 200]);
const condition = props.type === ComponentType ? "0" : "1";
for (const item of copyArr) { for (const item of copyArr) {
if (item.parentId === "1") { if (item.parentId === condition) {
const val = Number(scale(item.dumpCount).toFixed(4)); const val = Number(scale(item.dumpCount).toFixed(4));
res = item; res = item;
res.value = val; res.value = val;