@parca/profile 0.19.138 → 0.19.140

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.
Files changed (138) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.d.ts.map +1 -1
  3. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +11 -13
  4. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
  5. package/dist/ProfileExplorer/ProfileExplorerCompare.js +4 -9
  6. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
  7. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
  8. package/dist/ProfileFlameChart/index.d.ts.map +1 -1
  9. package/dist/ProfileFlameChart/index.js +13 -19
  10. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
  11. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +8 -8
  12. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  13. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +4 -3
  14. package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
  15. package/dist/ProfileFlameGraph/index.js +6 -4
  16. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  17. package/dist/ProfileMetricsGraph/index.js +4 -6
  18. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  19. package/dist/ProfileSelector/MetricsGraphSection.js +5 -10
  20. package/dist/ProfileSelector/index.d.ts.map +1 -1
  21. package/dist/ProfileSelector/index.js +27 -25
  22. package/dist/ProfileSelector/useAutoQuerySelector.d.ts.map +1 -1
  23. package/dist/ProfileSelector/useAutoQuerySelector.js +3 -0
  24. package/dist/ProfileTypeSelector/index.d.ts.map +1 -1
  25. package/dist/ProfileTypeSelector/index.js +4 -0
  26. package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
  27. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +5 -5
  28. package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
  29. package/dist/ProfileView/components/ColorStackLegend.js +2 -3
  30. package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
  31. package/dist/ProfileView/components/InvertCallStack/index.js +5 -4
  32. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +1 -2
  33. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
  34. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +14 -16
  35. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +84 -170
  36. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  37. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +16 -20
  38. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
  39. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +4 -5
  40. package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
  41. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  42. package/dist/ProfileView/components/Toolbars/index.js +1 -1
  43. package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
  44. package/dist/ProfileView/components/ViewSelector/index.js +8 -14
  45. package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
  46. package/dist/ProfileView/context/DashboardContext.js +6 -6
  47. package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
  48. package/dist/ProfileView/hooks/useResetFlameGraphState.js +5 -4
  49. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
  50. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +25 -26
  51. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
  52. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +13 -8
  53. package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
  54. package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
  55. package/dist/ProfileView/hooks/useVisualizationState.js +35 -51
  56. package/dist/ProfileViewWithData.d.ts.map +1 -1
  57. package/dist/ProfileViewWithData.js +19 -28
  58. package/dist/Sandwich/index.d.ts.map +1 -1
  59. package/dist/Sandwich/index.js +4 -3
  60. package/dist/SourceView/index.d.ts.map +1 -1
  61. package/dist/SourceView/index.js +4 -2
  62. package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
  63. package/dist/SourceView/useSelectedLineRange.js +21 -16
  64. package/dist/Table/MoreDropdown.d.ts.map +1 -1
  65. package/dist/Table/MoreDropdown.js +8 -11
  66. package/dist/Table/TableContextMenu.d.ts.map +1 -1
  67. package/dist/Table/TableContextMenu.js +10 -13
  68. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  69. package/dist/Table/hooks/useTableConfiguration.js +3 -4
  70. package/dist/Table/index.d.ts.map +1 -1
  71. package/dist/Table/index.js +11 -9
  72. package/dist/TopTable/index.d.ts.map +1 -1
  73. package/dist/TopTable/index.js +3 -4
  74. package/dist/hooks/urlParsers.d.ts +18 -0
  75. package/dist/hooks/urlParsers.d.ts.map +1 -0
  76. package/dist/hooks/urlParsers.js +32 -0
  77. package/dist/hooks/useColorBy.d.ts +5 -0
  78. package/dist/hooks/useColorBy.d.ts.map +1 -0
  79. package/dist/hooks/useColorBy.js +26 -0
  80. package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
  81. package/dist/hooks/useCompareModeMeta.js +55 -86
  82. package/dist/hooks/useDashboardItems.d.ts +5 -0
  83. package/dist/hooks/useDashboardItems.d.ts.map +1 -0
  84. package/dist/hooks/useDashboardItems.js +27 -0
  85. package/dist/hooks/useQueryState.d.ts +3 -3
  86. package/dist/hooks/useQueryState.d.ts.map +1 -1
  87. package/dist/hooks/useQueryState.js +105 -105
  88. package/dist/hooks/useQueryState.test.js +186 -302
  89. package/dist/index.d.ts +3 -2
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +3 -12
  92. package/dist/useSumBy.d.ts +1 -1
  93. package/dist/useSumBy.d.ts.map +1 -1
  94. package/dist/useSumBy.js +2 -2
  95. package/package.json +12 -11
  96. package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +11 -13
  97. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +4 -9
  98. package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
  99. package/src/ProfileFlameChart/index.tsx +21 -28
  100. package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +10 -9
  101. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +5 -3
  102. package/src/ProfileFlameGraph/index.tsx +6 -9
  103. package/src/ProfileMetricsGraph/index.tsx +6 -8
  104. package/src/ProfileSelector/MetricsGraphSection.tsx +5 -10
  105. package/src/ProfileSelector/index.tsx +32 -31
  106. package/src/ProfileSelector/useAutoQuerySelector.ts +5 -0
  107. package/src/ProfileTypeSelector/index.tsx +4 -0
  108. package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +10 -6
  109. package/src/ProfileView/components/ColorStackLegend.tsx +2 -4
  110. package/src/ProfileView/components/InvertCallStack/index.tsx +5 -4
  111. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +94 -192
  112. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
  113. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +24 -25
  114. package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +4 -5
  115. package/src/ProfileView/components/Toolbars/index.tsx +3 -3
  116. package/src/ProfileView/components/ViewSelector/index.tsx +9 -16
  117. package/src/ProfileView/context/DashboardContext.tsx +6 -6
  118. package/src/ProfileView/hooks/useResetFlameGraphState.ts +6 -4
  119. package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +24 -26
  120. package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +16 -8
  121. package/src/ProfileView/hooks/useVisualizationState.ts +61 -69
  122. package/src/ProfileViewWithData.tsx +29 -35
  123. package/src/Sandwich/index.tsx +4 -3
  124. package/src/SourceView/index.tsx +4 -2
  125. package/src/SourceView/useSelectedLineRange.ts +34 -19
  126. package/src/Table/MoreDropdown.tsx +9 -11
  127. package/src/Table/TableContextMenu.tsx +10 -13
  128. package/src/Table/hooks/useTableConfiguration.tsx +3 -4
  129. package/src/Table/index.tsx +12 -21
  130. package/src/TopTable/index.tsx +3 -4
  131. package/src/hooks/urlParsers.ts +38 -0
  132. package/src/hooks/useColorBy.ts +42 -0
  133. package/src/hooks/useCompareModeMeta.ts +61 -91
  134. package/src/hooks/useDashboardItems.ts +46 -0
  135. package/src/hooks/useQueryState.test.tsx +275 -345
  136. package/src/hooks/useQueryState.ts +136 -118
  137. package/src/index.tsx +16 -15
  138. package/src/useSumBy.ts +3 -3
@@ -13,13 +13,8 @@
13
13
 
14
14
  import {useCallback, useMemo} from 'react';
15
15
 
16
- import {
17
- JSONParser,
18
- JSONSerializer,
19
- useURLState,
20
- useURLStateBatch,
21
- useURLStateCustom,
22
- } from '@parca/components';
16
+ import {useQueryState} from 'nuqs';
17
+
23
18
  import {USER_PREFERENCES, useUserPreference} from '@parca/hooks';
24
19
 
25
20
  import {
@@ -30,12 +25,19 @@ import {
30
25
  FIELD_MAPPING_FILE,
31
26
  } from '../../ProfileFlameGraph/FlameGraphArrow';
32
27
  import {CurrentPathFrame} from '../../ProfileFlameGraph/FlameGraphArrow/utils';
28
+ import {
29
+ flamechartDimensionParser,
30
+ groupByParser,
31
+ jsonParser,
32
+ stringParam,
33
+ } from '../../hooks/urlParsers';
34
+ import {useColorBy} from '../../hooks/useColorBy';
33
35
  import {useResetFlameGraphState} from './useResetFlameGraphState';
34
36
 
35
37
  export const useVisualizationState = (): {
36
38
  curPathArrow: CurrentPathFrame[];
37
39
  setCurPathArrow: (path: CurrentPathFrame[]) => void;
38
- colorStackLegend: string | undefined;
40
+ colorStackLegend: string | null;
39
41
  colorBy: string;
40
42
  setColorBy: (colorBy: string) => void;
41
43
  groupBy: string[];
@@ -44,46 +46,52 @@ export const useVisualizationState = (): {
44
46
  setGroupByLabels: (labels: string[]) => void;
45
47
  flamechartDimension: string[];
46
48
  setFlamechartDimension: (labels: string[]) => void;
47
- sandwichFunctionName: string | undefined;
48
- setSandwichFunctionName: (sandwichFunctionName: string | undefined) => void;
49
+ sandwichFunctionName: string | null;
50
+ setSandwichFunctionName: (sandwichFunctionName: string | null) => void;
49
51
  resetSandwichFunctionName: () => void;
50
52
  alignFunctionName: string;
51
53
  setAlignFunctionName: (align: string) => void;
52
54
  } => {
53
- const [colorByPreference, setColorByPreference] = useUserPreference<string>(
54
- USER_PREFERENCES.COLOR_BY.key
55
- );
56
55
  const [alignFunctionNamePreference, setAlignFunctionNamePreference] = useUserPreference<string>(
57
56
  USER_PREFERENCES.ALIGN_FUNCTION_NAME.key
58
57
  );
59
58
 
60
- const [curPathArrow, setCurPathArrow] = useURLStateCustom<CurrentPathFrame[]>('cur_path', {
61
- parse: JSONParser<CurrentPathFrame[]>,
62
- stringify: JSONSerializer,
63
- defaultValue: '[]',
64
- });
65
- const [colorStackLegend] = useURLState<string | undefined>('color_stack_legend');
66
- const [colorBy, setStoreColorBy] = useURLState('color_by', {
67
- defaultValue: colorByPreference,
68
- });
69
- const [alignFunctionName, setStoreAlignFunctionName] = useURLState('align_function_name', {
70
- defaultValue: alignFunctionNamePreference,
71
- });
72
- const [groupBy, setStoreGroupBy] = useURLState<string[]>('group_by', {
73
- defaultValue: [FIELD_FUNCTION_NAME],
74
- alwaysReturnArray: true,
75
- });
76
- const [sandwichFunctionName, setSandwichFunctionName] = useURLState<string | undefined>(
77
- 'sandwich_function_name'
59
+ const [curPathArrow, setRawCurPathArrow] = useQueryState(
60
+ 'cur_path',
61
+ jsonParser<CurrentPathFrame[]>().withDefault([])
62
+ );
63
+ const setCurPathArrow = useCallback(
64
+ (path: CurrentPathFrame[]) => {
65
+ void setRawCurPathArrow(path);
66
+ },
67
+ [setRawCurPathArrow]
68
+ );
69
+ const [colorStackLegend] = useQueryState('color_stack_legend', stringParam);
70
+ const {colorBy, setColorBy} = useColorBy();
71
+ const [alignFunctionNameRaw, setStoreAlignFunctionName] = useQueryState(
72
+ 'align_function_name',
73
+ stringParam
74
+ );
75
+ const alignFunctionName = alignFunctionNameRaw ?? alignFunctionNamePreference ?? 'left';
76
+ const [groupBy, setStoreGroupBy] = useQueryState(
77
+ 'group_by',
78
+ groupByParser.withDefault([FIELD_FUNCTION_NAME])
79
+ );
80
+ const [sandwichFunctionName, setRawSandwichFunctionName] = useQueryState(
81
+ 'sandwich_function_name',
82
+ stringParam
78
83
  );
79
- const [flamechartDimension, setStoreFlamechartDimension] = useURLState<string[]>(
84
+ const setSandwichFunctionName = useCallback(
85
+ (name: string | null) => {
86
+ void setRawSandwichFunctionName(name);
87
+ },
88
+ [setRawSandwichFunctionName]
89
+ );
90
+ const [flamechartDimension, setStoreFlamechartDimension] = useQueryState(
80
91
  'flamechart_dimension',
81
- {
82
- alwaysReturnArray: true,
83
- }
92
+ flamechartDimensionParser.withDefault([])
84
93
  );
85
94
  const resetFlameGraphState = useResetFlameGraphState();
86
- const batchUpdates = useURLStateBatch();
87
95
 
88
96
  const levelsOfProfiling = useMemo(
89
97
  () => [
@@ -97,62 +105,46 @@ export const useVisualizationState = (): {
97
105
 
98
106
  const setGroupBy = useCallback(
99
107
  (keys: string[]): void => {
100
- setStoreGroupBy(keys);
108
+ void setStoreGroupBy(keys);
101
109
  },
102
110
  [setStoreGroupBy]
103
111
  );
104
112
 
105
113
  const toggleGroupBy = useCallback(
106
114
  (key: string): void => {
107
- // Batch updates to combine setGroupBy + resetFlameGraphState into single URL navigation
108
- batchUpdates(() => {
109
- if (groupBy.includes(key)) {
110
- setGroupBy(groupBy.filter(v => v !== key)); // remove
111
- } else {
112
- const filteredGroupBy = groupBy.filter(item => !levelsOfProfiling.includes(item));
113
- setGroupBy([...filteredGroupBy, key]); // add
114
- }
115
-
116
- resetFlameGraphState();
117
- });
115
+ if (groupBy.includes(key)) {
116
+ setGroupBy(groupBy.filter(v => v !== key));
117
+ } else {
118
+ const filteredGroupBy = groupBy.filter(item => !levelsOfProfiling.includes(item));
119
+ setGroupBy([...filteredGroupBy, key]);
120
+ }
121
+ resetFlameGraphState();
118
122
  },
119
- [groupBy, setGroupBy, levelsOfProfiling, resetFlameGraphState, batchUpdates]
123
+ [groupBy, setGroupBy, levelsOfProfiling, resetFlameGraphState]
120
124
  );
121
125
 
122
126
  const setGroupByLabels = useCallback(
123
127
  (labels: string[]): void => {
124
- // Batch updates to combine setGroupBy + resetFlameGraphState into single URL navigation
125
- batchUpdates(() => {
126
- setGroupBy(groupBy.filter(l => !l.startsWith(`${FIELD_LABELS}.`)).concat(labels));
127
-
128
- resetFlameGraphState();
129
- });
128
+ setGroupBy(groupBy.filter(l => !l.startsWith(`${FIELD_LABELS}.`)).concat(labels));
129
+ resetFlameGraphState();
130
130
  },
131
- [groupBy, setGroupBy, resetFlameGraphState, batchUpdates]
131
+ [groupBy, setGroupBy, resetFlameGraphState]
132
132
  );
133
133
 
134
134
  const setFlamechartDimension = useCallback(
135
135
  (labels: string[]): void => {
136
- setStoreFlamechartDimension(labels.filter(l => l.startsWith(`${FIELD_LABELS}.`)));
136
+ void setStoreFlamechartDimension(labels.filter(l => l.startsWith(`${FIELD_LABELS}.`)));
137
137
  },
138
138
  [setStoreFlamechartDimension]
139
139
  );
140
140
 
141
141
  const resetSandwichFunctionName = useCallback((): void => {
142
- setSandwichFunctionName(undefined);
142
+ setSandwichFunctionName(null);
143
143
  }, [setSandwichFunctionName]);
144
144
 
145
- const setColorBy = useCallback(
146
- (value: string): void => {
147
- setStoreColorBy(value);
148
- setColorByPreference(value);
149
- },
150
- [setStoreColorBy, setColorByPreference]
151
- );
152
-
153
145
  const setAlignFunctionName = useCallback(
154
146
  (value: string): void => {
155
- setStoreAlignFunctionName(value);
147
+ void setStoreAlignFunctionName(value);
156
148
  setAlignFunctionNamePreference(value);
157
149
  },
158
150
  [setStoreAlignFunctionName, setAlignFunctionNamePreference]
@@ -162,7 +154,7 @@ export const useVisualizationState = (): {
162
154
  curPathArrow,
163
155
  setCurPathArrow,
164
156
  colorStackLegend,
165
- colorBy: (colorBy as string) ?? '',
157
+ colorBy,
166
158
  setColorBy,
167
159
  groupBy,
168
160
  setGroupBy,
@@ -173,7 +165,7 @@ export const useVisualizationState = (): {
173
165
  sandwichFunctionName,
174
166
  setSandwichFunctionName,
175
167
  resetSandwichFunctionName,
176
- alignFunctionName: (alignFunctionName as string) ?? 'left',
168
+ alignFunctionName,
177
169
  setAlignFunctionName,
178
170
  };
179
171
  };
@@ -13,15 +13,10 @@
13
13
 
14
14
  import {useEffect, useMemo, useState} from 'react';
15
15
 
16
+ import {useQueryState} from 'nuqs';
17
+
16
18
  import {QueryRequest_ReportType, QueryServiceClient} from '@parca/client';
17
- import {
18
- NumberParser,
19
- NumberSerializer,
20
- useGrpcMetadata,
21
- useParcaContext,
22
- useURLState,
23
- useURLStateCustom,
24
- } from '@parca/components';
19
+ import {useGrpcMetadata, useParcaContext} from '@parca/components';
25
20
  import {saveAsBlob} from '@parca/utilities';
26
21
 
27
22
  import {validateFlameChartQuery} from './ProfileFlameGraph';
@@ -35,6 +30,14 @@ import {MergedProfileSource, ProfileSource} from './ProfileSource';
35
30
  import {ProfileView} from './ProfileView';
36
31
  import {useProfileFilters} from './ProfileView/components/ProfileFilters/useProfileFilters';
37
32
  import type {SamplesSeries} from './ProfileView/types/visualization';
33
+ import {
34
+ flamechartDimensionParser,
35
+ groupByParser,
36
+ intParam,
37
+ invertCallStackParser,
38
+ stringParam,
39
+ } from './hooks/urlParsers';
40
+ import {useDashboardItems} from './hooks/useDashboardItems';
38
41
  import {useQuery} from './useQuery';
39
42
  import {downloadPprof} from './utils';
40
43
 
@@ -53,22 +56,14 @@ export const ProfileViewWithData = ({
53
56
  onSwitchToFifteenMinutes,
54
57
  }: ProfileViewWithDataProps): JSX.Element => {
55
58
  const metadata = useGrpcMetadata();
56
- const [dashboardItems, setDashboardItems] = useURLState<string[]>('dashboard_items', {
57
- alwaysReturnArray: true,
58
- });
59
- const [sourceBuildID] = useURLState<string>('source_buildid');
60
- const [sourceFilename] = useURLState<string>('source_filename');
61
- const [groupBy] = useURLState<string[]>('group_by', {
62
- defaultValue: [FIELD_FUNCTION_NAME],
63
- alwaysReturnArray: true,
64
- });
65
- const [sandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
66
- const [flamechartDimension] = useURLState<string[]>('flamechart_dimension', {
67
- alwaysReturnArray: true,
68
- });
59
+ const {dashboardItems, setDashboardItems} = useDashboardItems();
60
+ const [sourceBuildID] = useQueryState('source_buildid', stringParam);
61
+ const [sourceFilename] = useQueryState('source_filename', stringParam);
62
+ const [groupBy] = useQueryState('group_by', groupByParser.withDefault([FIELD_FUNCTION_NAME]));
63
+ const [sandwichFunctionName] = useQueryState('sandwich_function_name', stringParam);
64
+ const [flamechartDimension] = useQueryState('flamechart_dimension', flamechartDimensionParser);
69
65
 
70
- const [invertStack] = useURLState('invert_call_stack');
71
- const invertCallStack = invertStack === 'true';
66
+ const [invertCallStack] = useQueryState('invert_call_stack', invertCallStackParser);
72
67
 
73
68
  const [pprofDownloading, setPprofDownloading] = useState<boolean>(false);
74
69
 
@@ -110,7 +105,7 @@ export const ProfileViewWithData = ({
110
105
  skip: !dashboardItems.includes('flamegraph'),
111
106
  nodeTrimThreshold,
112
107
  groupBy,
113
- invertCallStack,
108
+ invertCallStack: invertCallStack ?? false,
114
109
  protoFilters,
115
110
  });
116
111
 
@@ -134,11 +129,10 @@ export const ProfileViewWithData = ({
134
129
  );
135
130
 
136
131
  // Samples step count: 2px per data point for finer granularity in strips
137
- const [samplesStepCount] = useURLStateCustom<number>('samples_step_count', {
138
- defaultValue: String(getStepCountFromScreenWidth(2)),
139
- parse: NumberParser,
140
- stringify: NumberSerializer,
141
- });
132
+ const [samplesStepCount] = useQueryState(
133
+ 'samples_step_count',
134
+ intParam.withDefault(getStepCountFromScreenWidth(2))
135
+ );
142
136
 
143
137
  const {
144
138
  isLoading: samplesLoading,
@@ -203,8 +197,8 @@ export const ProfileViewWithData = ({
203
197
  error: sourceError,
204
198
  } = useQuery(queryClient, profileSource, QueryRequest_ReportType.SOURCE, {
205
199
  skip: !dashboardItems.includes('source'),
206
- sourceBuildID,
207
- sourceFilename,
200
+ sourceBuildID: sourceBuildID ?? undefined,
201
+ sourceFilename: sourceFilename ?? undefined,
208
202
  protoFilters,
209
203
  });
210
204
 
@@ -216,8 +210,8 @@ export const ProfileViewWithData = ({
216
210
  nodeTrimThreshold,
217
211
  groupBy: [FIELD_FUNCTION_NAME],
218
212
  invertCallStack: true,
219
- sandwichByFunction: sandwichFunctionName,
220
- skip: sandwichFunctionName === undefined && !dashboardItems.includes('sandwich'),
213
+ sandwichByFunction: sandwichFunctionName ?? undefined,
214
+ skip: sandwichFunctionName == null && !dashboardItems.includes('sandwich'),
221
215
  protoFilters,
222
216
  });
223
217
 
@@ -229,8 +223,8 @@ export const ProfileViewWithData = ({
229
223
  nodeTrimThreshold,
230
224
  groupBy: [FIELD_FUNCTION_NAME],
231
225
  invertCallStack: false,
232
- sandwichByFunction: sandwichFunctionName,
233
- skip: sandwichFunctionName === undefined && !dashboardItems.includes('sandwich'),
226
+ sandwichByFunction: sandwichFunctionName ?? undefined,
227
+ skip: sandwichFunctionName == null && !dashboardItems.includes('sandwich'),
234
228
  protoFilters,
235
229
  });
236
230
 
@@ -14,14 +14,15 @@
14
14
  import React, {useRef, useState} from 'react';
15
15
 
16
16
  import {AnimatePresence, motion} from 'framer-motion';
17
+ import {useQueryState} from 'nuqs';
17
18
 
18
- import {useURLState} from '@parca/components';
19
19
  import {TEST_IDS, testId} from '@parca/test-utils';
20
20
 
21
21
  import {ProfileSource} from '../ProfileSource';
22
22
  import {useDashboard} from '../ProfileView/context/DashboardContext';
23
23
  import {useVisualizationState} from '../ProfileView/hooks/useVisualizationState';
24
24
  import {SandwichData} from '../ProfileView/types/visualization';
25
+ import {stringParam} from '../hooks/urlParsers';
25
26
  import {CalleesSection} from './components/CalleesSection';
26
27
  import {CallersSection} from './components/CallersSection';
27
28
 
@@ -35,7 +36,7 @@ const Sandwich = React.memo(function Sandwich({
35
36
  profileSource,
36
37
  }: Props): React.JSX.Element {
37
38
  const {dashboardItems} = useDashboard();
38
- const [sandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
39
+ const [sandwichFunctionName] = useQueryState('sandwich_function_name', stringParam);
39
40
 
40
41
  const callersRef = React.useRef<HTMLDivElement | null>(null);
41
42
  const calleesRef = React.useRef<HTMLDivElement | null>(null);
@@ -57,7 +58,7 @@ const Sandwich = React.memo(function Sandwich({
57
58
  transition={{duration: 0.5}}
58
59
  >
59
60
  <div className="relative flex flex-row">
60
- {sandwichFunctionName !== undefined ? (
61
+ {sandwichFunctionName != null ? (
61
62
  <div className="w-full flex flex-col" ref={callersCalleesContainerRef}>
62
63
  <CallersSection
63
64
  callersRef={callersRef}
@@ -15,12 +15,14 @@ import React, {useCallback, useEffect, useMemo} from 'react';
15
15
 
16
16
  import {tableFromIPC} from '@uwdata/flechette';
17
17
  import {AnimatePresence, motion} from 'framer-motion';
18
+ import {useQueryState} from 'nuqs';
18
19
  import {Item, Menu, useContextMenu} from 'react-contexify';
19
20
 
20
21
  import {Source} from '@parca/client';
21
- import {SourceSkeleton, useParcaContext, useURLState, type ProfileData} from '@parca/components';
22
+ import {SourceSkeleton, useParcaContext, type ProfileData} from '@parca/components';
22
23
 
23
24
  import {ExpandOnHover} from '../GraphTooltipArrow/ExpandOnHoverValue';
25
+ import {stringParam} from '../hooks/urlParsers';
24
26
  import {alignedUint8Array, truncateStringReverse} from '../utils';
25
27
  import {Highlighter, profileAwareRenderer, type LineDataLookup} from './Highlighter';
26
28
  import useLineRange from './useSelectedLineRange';
@@ -42,7 +44,7 @@ export const SourceView = React.memo(function SourceView({
42
44
  filtered,
43
45
  setActionButtons,
44
46
  }: SourceViewProps): JSX.Element {
45
- const [sourceFileName] = useURLState<string | undefined>('source_filename');
47
+ const [sourceFileName] = useQueryState('source_filename', stringParam);
46
48
  const {isDarkMode, sourceViewContextMenuItems = []} = useParcaContext();
47
49
 
48
50
  const sourceCode = useMemo(() => {
@@ -11,9 +11,25 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
 
14
- import {useMemo} from 'react';
14
+ import {useCallback} from 'react';
15
15
 
16
- import {useURLState} from '@parca/components';
16
+ import {createParser, useQueryState} from 'nuqs';
17
+
18
+ interface SelectedLineRange {
19
+ start: number;
20
+ end: number;
21
+ }
22
+
23
+ const lineRangeParser = createParser<SelectedLineRange>({
24
+ parse: (value: string) => {
25
+ const [start, end] = value.split('-');
26
+ const startNum = parseInt(start, 10);
27
+ if (isNaN(startNum)) return null;
28
+ const endNum = end !== undefined ? parseInt(end, 10) : startNum;
29
+ return {start: startNum, end: isNaN(endNum) ? startNum : endNum};
30
+ },
31
+ serialize: (value: SelectedLineRange) => `${value.start}-${value.end}`,
32
+ }).withOptions({history: 'replace'});
17
33
 
18
34
  interface LineRange {
19
35
  startLine: number;
@@ -22,24 +38,23 @@ interface LineRange {
22
38
  }
23
39
 
24
40
  const useLineRange = (): LineRange => {
25
- const [sourceLine, setSourceLine] = useURLState<string | undefined>('source_line');
26
- const [startLine, endLine] = useMemo(() => {
27
- if (sourceLine == null) {
28
- return [-1, -1];
29
- }
30
- const [start, end] = sourceLine.split('-');
31
-
32
- if (end === undefined) {
33
- return [parseInt(start, 10), parseInt(start, 10)];
34
- }
35
- return [parseInt(start, 10), parseInt(end, 10)];
36
- }, [sourceLine]);
37
-
38
- const setLineRange = (start: number, end: number): void => {
39
- setSourceLine(`${start}-${end}`);
41
+ const [lineRange, setRawLineRange] = useQueryState(
42
+ 'source_line',
43
+ lineRangeParser.withDefault({start: -1, end: -1})
44
+ );
45
+
46
+ const setLineRange = useCallback(
47
+ (start: number, end: number): void => {
48
+ void setRawLineRange({start, end});
49
+ },
50
+ [setRawLineRange]
51
+ );
52
+
53
+ return {
54
+ startLine: lineRange.start,
55
+ endLine: lineRange.end,
56
+ setLineRange,
40
57
  };
41
-
42
- return {startLine, endLine, setLineRange};
43
58
  };
44
59
 
45
60
  export default useLineRange;
@@ -13,23 +13,21 @@
13
13
 
14
14
  import {Menu} from '@headlessui/react';
15
15
  import {Icon} from '@iconify/react';
16
+ import {useQueryState} from 'nuqs';
16
17
 
17
- import {useParcaContext, useURLState, useURLStateBatch} from '@parca/components';
18
+ import {useParcaContext} from '@parca/components';
19
+
20
+ import {stringParam} from '../hooks/urlParsers';
21
+ import {useDashboardItems} from '../hooks/useDashboardItems';
18
22
 
19
23
  const MoreDropdown = ({functionName}: {functionName: string}): React.JSX.Element | null => {
20
- const [_, setSandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
21
- const [dashboardItems, setDashboardItems] = useURLState<string[]>('dashboard_items', {
22
- alwaysReturnArray: true,
23
- });
24
+ const [_, setSandwichFunctionName] = useQueryState('sandwich_function_name', stringParam);
25
+ const {dashboardItems, setDashboardItems} = useDashboardItems();
24
26
  const {enableSandwichView} = useParcaContext();
25
- const batchUpdates = useURLStateBatch();
26
27
 
27
28
  const onSandwichViewSelect = (): void => {
28
- // Batch updates to combine setSandwichFunctionName + setDashboardItems into single URL navigation
29
- batchUpdates(() => {
30
- setSandwichFunctionName(functionName.trim());
31
- setDashboardItems([...dashboardItems, 'sandwich']);
32
- });
29
+ void setSandwichFunctionName(functionName.trim());
30
+ setDashboardItems([...dashboardItems, 'sandwich']);
33
31
  };
34
32
 
35
33
  const menuItems: Array<{label: string; action: () => void}> = [];
@@ -13,15 +13,18 @@
13
13
 
14
14
  import {Icon} from '@iconify/react';
15
15
  import cx from 'classnames';
16
+ import {useQueryState} from 'nuqs';
16
17
  import {Item, Menu, Submenu} from 'react-contexify';
17
18
 
18
19
  import 'react-contexify/dist/ReactContexify.css';
19
20
 
20
- import {useParcaContext, useURLState, useURLStateBatch} from '@parca/components';
21
+ import {useParcaContext} from '@parca/components';
21
22
  import {valueFormatter} from '@parca/utilities';
22
23
 
23
24
  import {type Row} from '.';
24
25
  import {getTextForCumulative} from '../ProfileFlameGraph/FlameGraphArrow/utils';
26
+ import {stringParam} from '../hooks/urlParsers';
27
+ import {useDashboardItems} from '../hooks/useDashboardItems';
25
28
  import {truncateString} from '../utils';
26
29
  import {type ColumnName} from './utils/functions';
27
30
 
@@ -42,22 +45,16 @@ const TableContextMenu = ({
42
45
  totalUnfiltered,
43
46
  columnVisibility,
44
47
  }: TableContextMenuProps): React.JSX.Element => {
45
- const [_, setSandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
46
- const [dashboardItems, setDashboardItems] = useURLState<string[]>('dashboard_items', {
47
- alwaysReturnArray: true,
48
- });
48
+ const [_, setSandwichFunctionName] = useQueryState('sandwich_function_name', stringParam);
49
+ const {dashboardItems, setDashboardItems} = useDashboardItems();
49
50
  const {enableSandwichView, isDarkMode} = useParcaContext();
50
- const batchUpdates = useURLStateBatch();
51
51
 
52
52
  const onSandwichViewSelect = (): void => {
53
53
  if (row?.name != null && row.name.length > 0) {
54
- // Batch updates to combine setSandwichFunctionName + setDashboardItems into single URL navigation
55
- batchUpdates(() => {
56
- setSandwichFunctionName(row.name.trim());
57
- if (!dashboardItems.includes('sandwich')) {
58
- setDashboardItems([...dashboardItems, 'sandwich']);
59
- }
60
- });
54
+ void setSandwichFunctionName(row.name.trim());
55
+ if (!dashboardItems.includes('sandwich')) {
56
+ setDashboardItems([...dashboardItems, 'sandwich']);
57
+ }
61
58
  }
62
59
  };
63
60
 
@@ -14,11 +14,12 @@
14
14
  import {useEffect, useMemo, useState} from 'react';
15
15
 
16
16
  import {createColumnHelper, type ColumnDef} from '@tanstack/table-core';
17
+ import {useQueryState} from 'nuqs';
17
18
 
18
- import {useURLState} from '@parca/components';
19
19
  import {valueFormatter} from '@parca/utilities';
20
20
 
21
21
  import {type Row} from '..';
22
+ import {tableColumnsParser} from '../../hooks/urlParsers';
22
23
  import {ColorCell} from '../ColorCell';
23
24
  import {addPlusSign, ratioString, type ColumnName} from '../utils/functions';
24
25
 
@@ -43,9 +44,7 @@ export function useTableConfiguration({
43
44
  compareMode,
44
45
  }: UseTableConfigurationProps): TableConfiguration {
45
46
  const columnHelper = createColumnHelper<Row>();
46
- const [tableColumns] = useURLState<string[]>('table_columns', {
47
- alwaysReturnArray: true,
48
- });
47
+ const [tableColumns] = useQueryState('table_columns', tableColumnsParser);
49
48
 
50
49
  const [columnVisibility, setColumnVisibility] = useState(() => {
51
50
  return {
@@ -16,14 +16,10 @@ import React, {useCallback, useEffect, useMemo, useRef} from 'react';
16
16
  import {RpcError} from '@protobuf-ts/runtime-rpc';
17
17
  import {tableFromIPC} from '@uwdata/flechette';
18
18
  import {AnimatePresence, motion} from 'framer-motion';
19
+ import {useQueryState} from 'nuqs';
19
20
  import {useContextMenu} from 'react-contexify';
20
21
 
21
- import {
22
- Table as TableComponent,
23
- TableSkeleton,
24
- useParcaContext,
25
- useURLState,
26
- } from '@parca/components';
22
+ import {Table as TableComponent, TableSkeleton, useParcaContext} from '@parca/components';
27
23
  import {useCurrentColorProfile} from '@parca/hooks';
28
24
  import {ProfileType} from '@parca/parser';
29
25
 
@@ -31,6 +27,9 @@ import useMappingList, {
31
27
  useFilenamesList,
32
28
  } from '../ProfileFlameGraph/FlameGraphArrow/useMappingList';
33
29
  import {useProfileViewContext} from '../ProfileView/context/ProfileViewContext';
30
+ import {stringParam} from '../hooks/urlParsers';
31
+ import {useColorBy} from '../hooks/useColorBy';
32
+ import {useDashboardItems} from '../hooks/useDashboardItems';
34
33
  import {alignedUint8Array} from '../utils';
35
34
  import TableContextMenuWrapper, {TableContextMenuWrapperRef} from './TableContextMenuWrapper';
36
35
  import {useColorManagement} from './hooks/useColorManagement';
@@ -76,11 +75,9 @@ export const Table = React.memo(function Table({
76
75
  error,
77
76
  }: TableProps): React.JSX.Element {
78
77
  const currentColorProfile = useCurrentColorProfile();
79
- const [dashboardItems] = useURLState<string[]>('dashboard_items', {
80
- alwaysReturnArray: true,
81
- });
82
- const [_, setSandwichFunctionName] = useURLState<string | undefined>('sandwich_function_name');
83
- const [colorBy, setColorBy] = useURLState('color_by');
78
+ const {dashboardItems} = useDashboardItems();
79
+ const [_, setSandwichFunctionName] = useQueryState('sandwich_function_name', stringParam);
80
+ const {colorBy, setColorBy} = useColorBy();
84
81
  const {isDarkMode} = useParcaContext();
85
82
  const {compareMode} = useProfileViewContext();
86
83
 
@@ -108,7 +105,7 @@ export const Table = React.memo(function Table({
108
105
  // If there is only one mapping file, we want to color by filename by default.
109
106
  useEffect(() => {
110
107
  if (mappingsListCount === 1 && colorBy !== 'filename') {
111
- setColorBy('filename');
108
+ void setColorBy('filename');
112
109
  }
113
110
  // eslint-disable-next-line react-hooks/exhaustive-deps
114
111
  }, [mappingsListCount]);
@@ -118,7 +115,7 @@ export const Table = React.memo(function Table({
118
115
  currentColorProfile,
119
116
  mappingsList,
120
117
  filenamesList,
121
- colorBy: colorBy as string,
118
+ colorBy,
122
119
  });
123
120
 
124
121
  unit = useMemo(() => unit ?? profileType?.sampleUnit ?? '', [unit, profileType?.sampleUnit]);
@@ -135,7 +132,7 @@ export const Table = React.memo(function Table({
135
132
  const selectSpan = useCallback(
136
133
  (span: string): void => {
137
134
  if (!dashboardItems.includes('flamegraph')) {
138
- setSandwichFunctionName(span.trim());
135
+ void setSandwichFunctionName(span.trim());
139
136
  }
140
137
  },
141
138
  [setSandwichFunctionName, dashboardItems]
@@ -191,13 +188,7 @@ export const Table = React.memo(function Table({
191
188
  return {
192
189
  id: i,
193
190
  colorProperty: {
194
- color: getRowColor(
195
- colorByColors,
196
- mappingFileColumn,
197
- i,
198
- functionFileNameColumn,
199
- colorBy as string
200
- ),
191
+ color: getRowColor(colorByColors, mappingFileColumn, i, functionFileNameColumn, colorBy),
201
192
  mappingFile,
202
193
  },
203
194
  name: RowName(mappingFileColumn, locationAddressColumn, functionNameColumn, i),