@parca/profile 0.16.91 → 0.16.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,22 +12,14 @@
12
12
  // limitations under the License.
13
13
 
14
14
  import {QuerySelection} from '../ProfileSelector';
15
- import {ProfileSelection, ProfileSelectionFromParams, SuffixParams, NavigateFunction} from '..';
15
+ import {ProfileSelection, ProfileSelectionFromParams, SuffixParams} from '..';
16
16
  import ProfileExplorerSingle from './ProfileExplorerSingle';
17
17
  import ProfileExplorerCompare from './ProfileExplorerCompare';
18
18
  import {QueryServiceClient} from '@parca/client';
19
- import {
20
- useAppSelector,
21
- useAppDispatch,
22
- setCompare,
23
- selectCompareMode,
24
- setSearchNodeString,
25
- store,
26
- selectFilterByFunction,
27
- } from '@parca/store';
28
- import {Provider, batch} from 'react-redux';
19
+ import {store} from '@parca/store';
20
+ import {Provider} from 'react-redux';
29
21
  import {DateTimeRange} from '@parca/components';
30
- import {useEffect} from 'react';
22
+ import {NavigateFunction} from '@parca/functions';
31
23
 
32
24
  interface ProfileExplorerProps {
33
25
  queryClient: QueryServiceClient;
@@ -40,6 +32,8 @@ const getExpressionAsAString = (expression: string | []): string => {
40
32
  return x;
41
33
  };
42
34
 
35
+ const DEFAULT_DASHBOARD_ITEMS = ['icicle'];
36
+
43
37
  /* eslint-disable @typescript-eslint/naming-convention */
44
38
  const sanitizeDateRange = (
45
39
  time_selection_a: string,
@@ -77,9 +71,6 @@ const ProfileExplorerApp = ({
77
71
  queryParams,
78
72
  navigateTo,
79
73
  }: ProfileExplorerProps): JSX.Element => {
80
- const dispatch = useAppDispatch();
81
- const compareMode = useAppSelector(selectCompareMode);
82
-
83
74
  /* eslint-disable @typescript-eslint/naming-convention */
84
75
  let {
85
76
  from_a,
@@ -98,9 +89,10 @@ const ProfileExplorerApp = ({
98
89
  time_b,
99
90
  time_selection_b,
100
91
  compare_b,
92
+ filter_by_function,
93
+ dashboard_items,
101
94
  } = queryParams;
102
95
  /* eslint-enable @typescript-eslint/naming-convention */
103
- const filterByFunction = useAppSelector(selectFilterByFunction);
104
96
 
105
97
  const sanitizedRange = sanitizeDateRange(time_selection_a, from_a, to_a);
106
98
  time_selection_a = sanitizedRange.time_selection_a;
@@ -116,20 +108,13 @@ const ProfileExplorerApp = ({
116
108
  if ((queryParams?.expression_a ?? '') !== '') queryParams.expression_a = expression_a;
117
109
  if ((queryParams?.expression_b ?? '') !== '') queryParams.expression_b = expression_b;
118
110
 
119
- useEffect(() => {
120
- if (compare_a === 'true' && compare_b === 'true') {
121
- dispatch(setCompare(true));
122
- } else {
123
- dispatch(setCompare(false));
124
- }
125
- }, [dispatch, compare_a, compare_b]);
126
-
127
111
  const selectProfile = (p: ProfileSelection, suffix: string): void => {
128
112
  queryParams.expression_a = encodeURIComponent(queryParams.expression_a);
129
113
  queryParams.expression_b = encodeURIComponent(queryParams.expression_b);
130
114
  return navigateTo('/', {
131
115
  ...queryParams,
132
116
  ...SuffixParams(p.HistoryParams(), suffix),
117
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
133
118
  });
134
119
  };
135
120
 
@@ -160,7 +145,7 @@ const ProfileExplorerApp = ({
160
145
  labels_a as string[],
161
146
  profile_name_a as string,
162
147
  time_a as string,
163
- filterByFunction
148
+ filter_by_function
164
149
  );
165
150
 
166
151
  const selectQuery = (q: QuerySelection): void => {
@@ -176,7 +161,7 @@ const ProfileExplorerApp = ({
176
161
  to_a: q.to.toString(),
177
162
  merge_a: q.merge,
178
163
  time_selection_a: q.timeSelection,
179
- currentProfileView: 'icicle',
164
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
180
165
  },
181
166
  }
182
167
  );
@@ -187,6 +172,7 @@ const ProfileExplorerApp = ({
187
172
  return navigateTo('/', {
188
173
  ...queryParams,
189
174
  ...SuffixParams(p.HistoryParams(), '_a'),
175
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
190
176
  });
191
177
  };
192
178
 
@@ -216,19 +202,11 @@ const ProfileExplorerApp = ({
216
202
  };
217
203
  }
218
204
 
219
- compareQuery = {
205
+ void navigateTo('/', {
220
206
  ...compareQuery,
221
- ...{
222
- currentProfileView: 'icicle',
223
- },
224
- };
225
-
226
- batch(() => {
227
- dispatch(setCompare(!compareMode));
228
- dispatch(setSearchNodeString(undefined));
207
+ search_string: '',
208
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
229
209
  });
230
-
231
- void navigateTo('/', compareQuery);
232
210
  };
233
211
 
234
212
  return (
@@ -295,7 +273,8 @@ const ProfileExplorerApp = ({
295
273
  to_a: q.to.toString(),
296
274
  merge_a: q.merge,
297
275
  time_selection_a: q.timeSelection,
298
- filterByFunction,
276
+ filter_by_function: filter_by_function ?? '',
277
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
299
278
  },
300
279
  }
301
280
  );
@@ -316,7 +295,8 @@ const ProfileExplorerApp = ({
316
295
  to_b: q.to.toString(),
317
296
  merge_b: q.merge,
318
297
  time_selection_b: q.timeSelection,
319
- filterByFunction,
298
+ filter_by_function: filter_by_function ?? '',
299
+ dashboard_items: dashboard_items ?? DEFAULT_DASHBOARD_ITEMS,
320
300
  },
321
301
  }
322
302
  );
@@ -328,15 +308,12 @@ const ProfileExplorerApp = ({
328
308
  newQueryParameters = swapQueryParameters(queryParams);
329
309
  }
330
310
 
331
- batch(() => {
332
- dispatch(setCompare(!compareMode));
333
- dispatch(setSearchNodeString(undefined));
334
- });
335
-
336
311
  return navigateTo('/', {
337
312
  ...filterSuffix(newQueryParameters, '_b'),
338
313
  ...{
339
314
  compare_a: 'false',
315
+ compare_b: 'false',
316
+ search_string: '',
340
317
  },
341
318
  });
342
319
  };
@@ -12,11 +12,11 @@
12
12
  // limitations under the License.
13
13
 
14
14
  import {Flamegraph} from '@parca/client';
15
- import {useAppSelector, selectCompareMode} from '@parca/store';
16
15
  import {useContainerDimensions} from '@parca/dynamicsize';
17
16
 
18
17
  import DiffLegend from '../components/DiffLegend';
19
18
  import IcicleGraph from '../IcicleGraph';
19
+ import {selectQueryParam} from '@parca/functions';
20
20
  import {useEffect, useMemo} from 'react';
21
21
 
22
22
  const numberFormatter = new Intl.NumberFormat('en-US');
@@ -39,7 +39,8 @@ const ProfileIcicleGraph = ({
39
39
  sampleUnit,
40
40
  onContainerResize,
41
41
  }: ProfileIcicleGraphProps): JSX.Element => {
42
- const compareMode = useAppSelector(selectCompareMode);
42
+ const compareMode: boolean =
43
+ Boolean(selectQueryParam('compare_a')) && Boolean(selectQueryParam('compare_b'));
43
44
  const {ref, dimensions} = useContainerDimensions();
44
45
 
45
46
  useEffect(() => {
@@ -12,39 +12,39 @@
12
12
  // limitations under the License.
13
13
 
14
14
  import {Input} from '@parca/components';
15
- import {
16
- selectFilterByFunction,
17
- setFilterByFunction,
18
- useAppDispatch,
19
- useAppSelector,
20
- } from '@parca/store';
15
+ import {useURLState, NavigateFunction} from '@parca/functions';
21
16
  import {Icon} from '@iconify/react';
22
17
  import {useCallback, useMemo, useState} from 'react';
23
18
 
24
- const FilterByFunctionButton = (): JSX.Element => {
25
- const dispatch = useAppDispatch();
26
- const storeVal = useAppSelector(selectFilterByFunction);
27
- const [value, setValue] = useState<string>(storeVal ?? '');
19
+ const FilterByFunctionButton = ({
20
+ navigateTo,
21
+ }: {
22
+ navigateTo: NavigateFunction | undefined;
23
+ }): JSX.Element => {
24
+ const [storeValue, setStoreValue] = useURLState({param: 'filter_by_function', navigateTo});
25
+ const [localValue, setLocalValue] = useState(storeValue as string);
28
26
 
29
27
  const isClearAction = useMemo(() => {
30
- return value === storeVal && value != null;
31
- }, [value, storeVal]);
28
+ return localValue === storeValue && localValue != null && localValue !== '';
29
+ }, [localValue, storeValue]);
32
30
 
33
31
  const onAction = useCallback((): void => {
34
- dispatch(setFilterByFunction(isClearAction ? undefined : value));
35
32
  if (isClearAction) {
36
- setValue('');
33
+ setLocalValue('');
34
+ setStoreValue('');
35
+ } else {
36
+ setStoreValue(localValue);
37
37
  }
38
- }, [dispatch, isClearAction, value]);
38
+ }, [localValue, isClearAction, setStoreValue]);
39
39
 
40
40
  return (
41
41
  <Input
42
42
  placeholder="Filter by function"
43
43
  className="text-sm"
44
44
  onAction={onAction}
45
- onChange={e => setValue(e.target.value)}
46
- value={value}
47
- onBlur={() => setValue(storeVal ?? '')}
45
+ onChange={e => setLocalValue(e.target.value)}
46
+ value={localValue ?? ''}
47
+ onBlur={() => setLocalValue(storeValue as string)}
48
48
  actionIcon={isClearAction ? <Icon icon="ep:circle-close" /> : <Icon icon="ep:arrow-right" />}
49
49
  />
50
50
  );
@@ -0,0 +1,117 @@
1
+ // Copyright 2022 The Parca Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+
14
+ import {Select, SelectElement} from '@parca/components';
15
+ import {useURLState, NavigateFunction} from '@parca/functions';
16
+ import useUIFeatureFlag from '@parca/functions/useUIFeatureFlag';
17
+
18
+ interface Props {
19
+ position: number;
20
+ defaultValue: string;
21
+ navigateTo?: NavigateFunction;
22
+ placeholderText?: string;
23
+ primary?: boolean;
24
+ addView?: boolean;
25
+ disabled?: boolean;
26
+ }
27
+
28
+ const ViewSelector = ({
29
+ defaultValue,
30
+ navigateTo,
31
+ position,
32
+ placeholderText,
33
+ primary = false,
34
+ addView = false,
35
+ disabled = false,
36
+ }: Props): JSX.Element => {
37
+ const [callgraphEnabled] = useUIFeatureFlag('callgraph');
38
+ const [dashboardItems, setDashboardItems] = useURLState({
39
+ param: 'dashboard_items',
40
+ navigateTo,
41
+ });
42
+
43
+ const allItems: Array<{key: string; canBeSelected: boolean; supportingText?: string}> = [
44
+ {key: 'table', canBeSelected: !dashboardItems.includes('table')},
45
+ {key: 'icicle', canBeSelected: !dashboardItems.includes('icicle')},
46
+ ];
47
+ if (callgraphEnabled) {
48
+ allItems.push({
49
+ key: 'callgraph',
50
+ canBeSelected: !dashboardItems.includes('callgraph'),
51
+ });
52
+ }
53
+
54
+ const getOption = ({
55
+ key,
56
+ supportingText,
57
+ }: {
58
+ key: string;
59
+ supportingText?: string;
60
+ }): SelectElement => {
61
+ const capitalizeFirstLetter = (string: string): string => {
62
+ return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
63
+ };
64
+
65
+ const title = capitalizeFirstLetter(key);
66
+
67
+ return {
68
+ active: <>{title}</>,
69
+ expanded: (
70
+ <>
71
+ <span>{title}</span>
72
+ {supportingText !== null && <span className="text-xs">{supportingText}</span>}
73
+ </>
74
+ ),
75
+ };
76
+ };
77
+
78
+ const items = allItems.map(item => ({
79
+ key: item.key,
80
+ disabled: !item.canBeSelected,
81
+ element: getOption(item),
82
+ }));
83
+
84
+ const onSelection = (value: string): void => {
85
+ if (addView) {
86
+ setDashboardItems([dashboardItems[0], value]);
87
+ return;
88
+ }
89
+
90
+ const isOnlyChart = dashboardItems.length === 1;
91
+ if (isOnlyChart) {
92
+ setDashboardItems([value]);
93
+ return;
94
+ }
95
+
96
+ // Note: this will need to be updated if we ever have more more than 2 panels
97
+ const isFirstChart = position === 0;
98
+ const newDashboardItems = isFirstChart
99
+ ? [value, dashboardItems[1]]
100
+ : [dashboardItems[0], value];
101
+
102
+ setDashboardItems(newDashboardItems);
103
+ };
104
+
105
+ return (
106
+ <Select
107
+ items={items}
108
+ selectedKey={defaultValue}
109
+ onSelection={onSelection}
110
+ placeholder={placeholderText ?? 'Select view type...'}
111
+ primary={primary}
112
+ disabled={disabled}
113
+ />
114
+ );
115
+ };
116
+
117
+ export default ViewSelector;