Skip to content

Commit a9246e6

Browse files
committed
Create function for constructing row elements
1 parent f816281 commit a9246e6

File tree

1 file changed

+34
-61
lines changed
  • site/frontend/src/pages/detailed-query

1 file changed

+34
-61
lines changed

site/frontend/src/pages/detailed-query/utils.ts

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -244,85 +244,58 @@ export function createTableData(
244244
// Add totals row first
245245
const totals = profile.totals;
246246
const totalsDelta = delta?.totals;
247-
result.push({
248-
isTotal: true,
249-
label: totals.label,
247+
result.push(createRowData(true, totals, totalsDelta));
248+
249+
// Add query data rows
250+
profile.query_data.forEach((query, idx) => {
251+
const queryDelta = delta?.query_data[idx];
252+
result.push(createRowData(false, query, queryDelta));
253+
});
254+
255+
return result;
256+
}
257+
258+
function createRowData(
259+
isTotal: boolean,
260+
value: ProfileElement,
261+
delta?: ProfileElement
262+
): TableRowData {
263+
return {
264+
isTotal,
265+
label: value.label,
250266
timePercent:
251-
totals.percent_total_time < 0
267+
value.percent_total_time < 0
252268
? {
253269
value: -1,
254270
formatted: "-",
255271
title: "No wall-time stat collected for this run",
256272
}
257273
: {
258-
value: totals.percent_total_time,
259-
formatted: totals.percent_total_time.toFixed(2) + "%*",
274+
value: value.percent_total_time,
275+
formatted: value.percent_total_time.toFixed(2) + "%",
260276
title: "% of cpu-time stat",
261277
},
262-
timeSeconds: toSeconds(totals.self_time),
263-
timeDelta: totalsDelta
278+
timeSeconds: toSeconds(value.self_time),
279+
timeDelta: delta
264280
? createDelta(
265-
toSeconds(totals.self_time),
266-
toSeconds(totalsDelta.self_time),
281+
toSeconds(value.self_time),
282+
toSeconds(delta.self_time),
267283
false
268284
)
269285
: null,
270-
executions: totals.invocation_count,
271-
executionsDelta: totalsDelta
272-
? createDelta(totals.invocation_count, totalsDelta.invocation_count, true)
286+
executions: value.invocation_count,
287+
executionsDelta: delta
288+
? createDelta(value.invocation_count, delta.invocation_count, true)
273289
: null,
274-
incrementalLoading: toSeconds(totals.incremental_load_time),
275-
incrementalLoadingDelta: totalsDelta
290+
incrementalLoading: toSeconds(value.incremental_load_time),
291+
incrementalLoadingDelta: delta
276292
? createDelta(
277-
toSeconds(totals.incremental_load_time),
278-
toSeconds(totalsDelta.incremental_load_time),
293+
toSeconds(value.incremental_load_time),
294+
toSeconds(delta.incremental_load_time),
279295
false
280296
)
281297
: null,
282-
});
283-
284-
// Add query data rows
285-
profile.query_data.forEach((query, idx) => {
286-
const queryDelta = delta?.query_data[idx];
287-
result.push({
288-
isTotal: false,
289-
label: query.label,
290-
timePercent:
291-
query.percent_total_time < 0
292-
? {
293-
value: -1,
294-
formatted: "-",
295-
title: "No wall-time stat collected for this run",
296-
}
297-
: {
298-
value: query.percent_total_time,
299-
formatted: query.percent_total_time.toFixed(2) + "%",
300-
title: "",
301-
},
302-
timeSeconds: toSeconds(query.self_time),
303-
timeDelta: queryDelta
304-
? createDelta(
305-
toSeconds(query.self_time),
306-
toSeconds(queryDelta.self_time),
307-
false
308-
)
309-
: null,
310-
executions: query.invocation_count,
311-
executionsDelta: queryDelta
312-
? createDelta(query.invocation_count, queryDelta.invocation_count, true)
313-
: null,
314-
incrementalLoading: toSeconds(query.incremental_load_time),
315-
incrementalLoadingDelta: queryDelta
316-
? createDelta(
317-
toSeconds(query.incremental_load_time),
318-
toSeconds(queryDelta.incremental_load_time),
319-
false
320-
)
321-
: null,
322-
});
323-
});
324-
325-
return result;
298+
};
326299
}
327300

328301
export function createArtifactData(data: SelfProfileResponse | null): {

0 commit comments

Comments
 (0)