-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
1. Moves calculations on a backend side. 2. Fixes Flame chart rendering. 3. Add top functions with sorting 4. Fixes styles on dark and light theme
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,5 +86,6 @@ onMounted(getEvent); | |
.profiler-event__body { | ||
@include layout-body; | ||
@apply h-full; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,93 @@ | ||
import type { FlameChartNode } from "flame-chart-js/dist/types"; | ||
import type { ProfilerCost, ProfilerEdge, ProfilerEdges } from "~/src/entities/profiler/types"; | ||
import type { ProfilerCost, ProfilerEdges } from "~/src/entities/profiler/types"; | ||
import { GraphTypes } from "~/src/shared/types"; | ||
|
||
type FlameChartData = FlameChartNode & { | ||
cost: ProfilerCost | ||
} | ||
export const build = (edges: ProfilerEdges, field: GraphTypes): FlameChartData => { | ||
Check warning on line 8 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
Check failure on line 8 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
Check warning on line 8 in src/features/lib/flame-chart/build.ts GitHub Actions / build (20.x)
|
||
let walked = [] as ProfilerEdge['callee'][] | ||
return buildWaterfall(edges)[0] | ||
} | ||
|
||
const datum: Record<string, FlameChartData> = {} | ||
// TODO: add types | ||
function buildWaterfall(events) { | ||
const waterfall = []; | ||
const eventCache = {}; | ||
|
||
Check failure on line 16 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
Check failure on line 16 in src/features/lib/flame-chart/build.ts GitHub Actions / build (20.x)
|
||
Object.values(edges).forEach((edge) => { | ||
const parent = edge.caller | ||
const target = edge.callee | ||
// First pass to create each event and find its parent. | ||
for (const key of Object.keys(events)) { | ||
const event = events[key]; | ||
const duration = event.cost.wt || 0; | ||
const eventData = { | ||
name: event.callee, | ||
cost: event.cost, | ||
start: 0, // Temporarily zero, will adjust based on the parent later | ||
duration: duration, | ||
type: 'task', | ||
Check failure on line 26 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
|
||
children: [], | ||
color: getColorForPercentCount(event.cost.p_wt), | ||
}; | ||
|
||
const duration = (edge.cost[String(field)] || 0) > 0 ? edge.cost[String(field)] / 1_000 : 0 | ||
const start = 0 | ||
eventCache[event.id] = eventData; | ||
|
||
if (target && !datum[target]) { | ||
datum[target] = { | ||
name: target, | ||
start, | ||
duration, | ||
cost: edge.cost, | ||
children: [] | ||
if (event.parent) { | ||
// If there's a parent, add to its children list. | ||
const parentEventData = eventCache[event.parent]; | ||
if (parentEventData) { | ||
parentEventData.children.push(eventData); | ||
} | ||
} else { | ||
// No parent implies it is a top-level event. | ||
waterfall.push(eventData); | ||
} | ||
} | ||
|
||
if (parent && !datum[parent]) { | ||
datum[parent] = { | ||
name: parent, | ||
start, | ||
duration, | ||
cost: edge.cost, | ||
children: [] | ||
} | ||
} | ||
// Second pass to adjust start times based on the order in the children array. | ||
Check failure on line 45 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
|
||
function adjustStartTimes(eventList, startTime) { | ||
for (let i = 0; i < eventList.length; i++) { | ||
const event = eventList[i]; | ||
Check failure on line 48 in src/features/lib/flame-chart/build.ts GitHub Actions / build (18.x)
|
||
event.start = startTime; | ||
startTime += event.duration; // Next event starts after the current event ends. | ||
|
||
// NOTE: walked skips several targettions (recursion detected), should be fixed | ||
if (!parent || walked.includes(target)) { | ||
// console.log(node, target) | ||
return | ||
// Recursively adjust times for children. | ||
adjustStartTimes(event.children, event.start); | ||
} | ||
} | ||
|
||
if (datum[parent] && datum[parent].children) { | ||
const parentChildren = datum[parent].children || [] | ||
// Start the adjustment from the root events. | ||
adjustStartTimes(waterfall, 0); | ||
|
||
const lastChild = parentChildren ? parentChildren[parentChildren.length - 1]: null | ||
datum[target].start = lastChild ? lastChild.start + lastChild.duration : datum[target].start | ||
} else { | ||
datum[target].start += datum[parent].start | ||
} | ||
|
||
datum[parent].children?.push(datum[target]) | ||
walked.push(target) | ||
}) | ||
return waterfall; | ||
} | ||
|
||
walked = [] | ||
const getColorForPercentCount = (percent: number): string => { | ||
if (percent <= 10) { | ||
return '#B3E5FC'; // Light Blue | ||
} | ||
if (percent <= 20) { | ||
return '#81D4FA'; // Light Sky Blue | ||
} | ||
if (percent <= 30) { | ||
return '#4FC3F7'; // Vivid Light Blue | ||
} | ||
if (percent <= 40) { | ||
return '#29B6F6'; // Bright Light Blue | ||
} | ||
if (percent <= 50) { | ||
return '#FFCDD2'; // Pink (Light Red) | ||
} | ||
if (percent <= 60) { | ||
return '#FFB2B2'; // Lighter Red | ||
} | ||
if (percent <= 70) { | ||
return '#FF9E9E'; // Soft Red | ||
} | ||
if (percent <= 80) { | ||
return '#FF8989'; // Soft Coral | ||
} | ||
if (percent <= 90) { | ||
return '#FF7474'; // Soft Tomato | ||
} | ||
|
||
return datum['main()'] | ||
} | ||
return '#FF5F5F'; // Light Coral | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// TODO: no need anymore | ||
export * from './use-flame-chart'; |