Skip to content

Commit 6d31112

Browse files
committed
perforator: show correct format in TaskCard
commit_hash:45673a29704cd0130995e1e4fd222b98d30421e8
1 parent 858b381 commit 6d31112

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

perforator/ui/src/components/TaskCard/TaskCard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Button, Card, ClipboardButton, Link } from '@gravity-ui/uikit';
77
import { uiFactory } from 'src/factory';
88
import type { TaskResult } from 'src/models/Task';
99
import { TaskState } from 'src/models/Task';
10+
import { getFormat, isDiffTaskResult } from 'src/utils/renderingFormat';
1011
import { setPageTitle } from 'src/utils/title';
1112

1213
import type { DefinitionListItem } from '../DefinitionList/DefinitionList';
@@ -36,6 +37,10 @@ export const TaskCard: React.FC<TaskCardProps> = props => {
3637
const query = spec?.Query;
3738
const traceId = task?.Spec?.TraceBaggage?.Baggage?.traceparent?.match(/^[^-]{2}-([^-]*)-.*/)?.[1];
3839

40+
const isDiff = isDiffTaskResult(props.task);
41+
const isLegacyFormat = isDiff && 'FlamegraphOptions' in (props.task?.Spec?.DiffProfiles || {});
42+
const format = getFormat(spec?.Format) ?? getFormat(diffSpec?.RenderFormat) ?? (isLegacyFormat ? 'Flamegraph' : undefined);
43+
3944
React.useMemo(() => {
4045
if (query?.Selector) {
4146
setPageTitle(`Profile: ${query?.Selector}`);
@@ -91,7 +96,7 @@ export const TaskCard: React.FC<TaskCardProps> = props => {
9196
['Baseline sample count', diffSpec?.BaselineQuery?.MaxSamples],
9297
['Diff sample count', diffSpec?.DiffQuery?.MaxSamples],
9398
['Trace', renderTraceLink()],
94-
['Flamegraph format', 'JSONFlamegraph' in (spec?.Format || {}) ? undefined : 'HTML'],
99+
['Flamegraph format', format === 'Flamegraph' ? 'HTML' : undefined],
95100
];
96101

97102
return (

perforator/ui/src/components/TaskReport/TaskReport.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import React from 'react';
33
import { Alert, Button, Loader } from '@gravity-ui/uikit';
44

55
import { uiFactory } from 'src/factory';
6-
import type { RenderFormat } from 'src/generated/perforator/proto/perforator/perforator';
76
import type { TaskResult } from 'src/models/Task';
7+
import { getFormat, isDiffTaskResult } from 'src/utils/renderingFormat';
88

99
import { ErrorPanel } from '../ErrorPanel/ErrorPanel';
1010

@@ -17,16 +17,9 @@ export interface TaskReportProps {
1717
task: TaskResult | null;
1818
}
1919

20-
function getWellKnownKeysFromObject<O extends Record<string, any>, K extends keyof O>(o: O, keys: K[]): K[] {
21-
return keys.filter(k => k in o);
22-
}
23-
24-
const getFormatLike = (o: RenderFormat) => getWellKnownKeysFromObject(o, ['Flamegraph', 'JSONFlamegraph', 'RawProfile']);
25-
const getFormat = (o?: RenderFormat) => o ? getFormatLike(o)[0] : undefined;
26-
2720
export const TaskReport: React.FC<TaskReportProps> = props => {
2821
const url = props.task?.Result?.MergeProfiles?.ProfileURL || props.task?.Result?.DiffProfiles?.ProfileURL;
29-
const isDiff = 'DiffProfiles' in (props.task?.Result || {});
22+
const isDiff = isDiffTaskResult(props.task);
3023
const mergeRenderFormat = props.task?.Spec?.MergeProfiles?.Format;
3124
const diffRenderFormat = props.task?.Spec?.DiffProfiles?.RenderFormat;
3225
const isLegacyFormat = isDiff && 'FlamegraphOptions' in (props.task?.Spec?.DiffProfiles || {});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RenderFormat } from 'src/generated/perforator/proto/perforator/perforator';
2+
import type { TaskResult } from 'src/models/Task';
3+
4+
5+
function getWellKnownKeysFromObject<O extends Record<string, any>, K extends keyof O>(obj: O, keys: K[]): K[] {
6+
return keys.filter(k => k in obj);
7+
}
8+
9+
const getFormatLike = (o: RenderFormat) => getWellKnownKeysFromObject(o, ['Flamegraph', 'JSONFlamegraph', 'RawProfile']);
10+
export const getFormat = (o?: RenderFormat) => o ? getFormatLike(o)[0] : undefined;
11+
12+
export function isDiffTaskResult(task: TaskResult | null) {
13+
return 'DiffProfiles' in (task?.Result || {});
14+
}

0 commit comments

Comments
 (0)