@parca/profile 0.19.80 → 0.19.82

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 (86) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/MatchersInput/index.d.ts +2 -34
  3. package/dist/MatchersInput/index.d.ts.map +1 -1
  4. package/dist/MatchersInput/index.js +14 -91
  5. package/dist/MetricsGraph/index.d.ts.map +1 -1
  6. package/dist/MetricsGraph/index.js +13 -1
  7. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  8. package/dist/ProfileMetricsGraph/index.js +24 -33
  9. package/dist/ProfileSelector/MetricsGraphSection.d.ts +2 -9
  10. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  11. package/dist/ProfileSelector/MetricsGraphSection.js +3 -38
  12. package/dist/ProfileSelector/index.d.ts +1 -29
  13. package/dist/ProfileSelector/index.d.ts.map +1 -1
  14. package/dist/ProfileSelector/index.js +12 -9
  15. package/dist/ProfileView/components/ProfileFilters/filterPresets.d.ts.map +1 -1
  16. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +15 -3
  17. package/dist/QueryControls/index.d.ts +42 -0
  18. package/dist/QueryControls/index.d.ts.map +1 -0
  19. package/dist/{ProfileSelector/QueryControls.js → QueryControls/index.js} +16 -13
  20. package/dist/SimpleMatchers/Select.js +1 -1
  21. package/dist/SimpleMatchers/index.d.ts +2 -11
  22. package/dist/SimpleMatchers/index.d.ts.map +1 -1
  23. package/dist/SimpleMatchers/index.js +34 -45
  24. package/dist/ViewMatchers/index.d.ts +0 -9
  25. package/dist/ViewMatchers/index.d.ts.map +1 -1
  26. package/dist/ViewMatchers/index.js +20 -12
  27. package/dist/contexts/LabelsQueryProvider.d.ts +35 -0
  28. package/dist/contexts/LabelsQueryProvider.d.ts.map +1 -0
  29. package/dist/contexts/LabelsQueryProvider.js +70 -0
  30. package/dist/contexts/UnifiedLabelsContext.d.ts +37 -0
  31. package/dist/contexts/UnifiedLabelsContext.d.ts.map +1 -0
  32. package/dist/contexts/UnifiedLabelsContext.js +88 -0
  33. package/dist/contexts/utils.d.ts +10 -0
  34. package/dist/contexts/utils.d.ts.map +1 -0
  35. package/dist/contexts/utils.js +31 -0
  36. package/dist/hooks/useLabels.d.ts +23 -0
  37. package/dist/hooks/useLabels.d.ts.map +1 -0
  38. package/dist/hooks/useLabels.js +75 -0
  39. package/dist/hooks/useQueryState.d.ts +2 -0
  40. package/dist/hooks/useQueryState.d.ts.map +1 -1
  41. package/dist/hooks/useQueryState.js +18 -0
  42. package/dist/index.d.ts +9 -3
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +9 -3
  45. package/dist/styles.css +1 -1
  46. package/dist/useSumBy.js +1 -1
  47. package/package.json +2 -2
  48. package/src/MatchersInput/index.tsx +17 -163
  49. package/src/MetricsGraph/index.tsx +17 -1
  50. package/src/ProfileMetricsGraph/index.tsx +37 -102
  51. package/src/ProfileSelector/MetricsGraphSection.tsx +14 -115
  52. package/src/ProfileSelector/index.tsx +106 -109
  53. package/src/ProfileView/components/ProfileFilters/filterPresets.ts +15 -3
  54. package/src/{ProfileSelector/QueryControls.tsx → QueryControls/index.tsx} +66 -84
  55. package/src/SimpleMatchers/Select.tsx +1 -1
  56. package/src/SimpleMatchers/index.tsx +46 -85
  57. package/src/ViewMatchers/index.tsx +22 -30
  58. package/src/contexts/LabelsQueryProvider.tsx +142 -0
  59. package/src/contexts/UnifiedLabelsContext.tsx +155 -0
  60. package/src/contexts/utils.ts +43 -0
  61. package/src/hooks/useLabels.ts +121 -0
  62. package/src/hooks/useQueryState.ts +25 -0
  63. package/src/index.tsx +29 -3
  64. package/src/useSumBy.ts +1 -1
  65. package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts +0 -29
  66. package/dist/MetricsGraph/UtilizationMetrics/Throughput.d.ts.map +0 -1
  67. package/dist/MetricsGraph/UtilizationMetrics/Throughput.js +0 -175
  68. package/dist/MetricsGraph/UtilizationMetrics/index.d.ts +0 -28
  69. package/dist/MetricsGraph/UtilizationMetrics/index.d.ts.map +0 -1
  70. package/dist/MetricsGraph/UtilizationMetrics/index.js +0 -186
  71. package/dist/ProfileSelector/QueryControls.d.ts +0 -43
  72. package/dist/ProfileSelector/QueryControls.d.ts.map +0 -1
  73. package/dist/contexts/MatchersInputLabelsContext.d.ts +0 -29
  74. package/dist/contexts/MatchersInputLabelsContext.d.ts.map +0 -1
  75. package/dist/contexts/MatchersInputLabelsContext.js +0 -79
  76. package/dist/contexts/SimpleMatchersLabelContext.d.ts +0 -25
  77. package/dist/contexts/SimpleMatchersLabelContext.d.ts.map +0 -1
  78. package/dist/contexts/SimpleMatchersLabelContext.js +0 -115
  79. package/dist/contexts/UtilizationLabelsContext.d.ts +0 -15
  80. package/dist/contexts/UtilizationLabelsContext.d.ts.map +0 -1
  81. package/dist/contexts/UtilizationLabelsContext.js +0 -25
  82. package/src/MetricsGraph/UtilizationMetrics/Throughput.tsx +0 -405
  83. package/src/MetricsGraph/UtilizationMetrics/index.tsx +0 -426
  84. package/src/contexts/MatchersInputLabelsContext.tsx +0 -141
  85. package/src/contexts/SimpleMatchersLabelContext.tsx +0 -189
  86. package/src/contexts/UtilizationLabelsContext.tsx +0 -45
@@ -1,189 +0,0 @@
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 {createContext, useCallback, useContext, useMemo} from 'react';
15
-
16
- import {useQueryClient} from '@tanstack/react-query';
17
-
18
- import {QueryServiceClient} from '@parca/client';
19
-
20
- import {useLabelNames} from '../MatchersInput';
21
- import {transformLabelsForSelect} from '../SimpleMatchers';
22
- import type {SelectItem} from '../SimpleMatchers/Select';
23
- import {useUtilizationLabels} from './UtilizationLabelsContext';
24
-
25
- interface LabelNameSection {
26
- type: string;
27
- values: SelectItem[];
28
- }
29
-
30
- interface LabelContextValue {
31
- labelNameOptions: LabelNameSection[];
32
- isLoading: boolean;
33
- error: Error | null;
34
- refetchLabelValues: (labelName?: string) => Promise<void>;
35
- refetchLabelNames: () => Promise<void>;
36
- }
37
-
38
- const LabelContext = createContext<LabelContextValue | null>(null);
39
-
40
- interface LabelProviderProps {
41
- children: React.ReactNode;
42
- queryClient: QueryServiceClient;
43
- profileType: string;
44
- labelNameFromMatchers: string[];
45
- start?: number;
46
- end?: number;
47
- }
48
-
49
- // With there being the possibility of having utilization labels, we need to be able to determine whether the labels to be used are utilization labels or profiling data labels.
50
- // This context is used to determine this.
51
-
52
- export function LabelProvider({
53
- children,
54
- queryClient,
55
- profileType,
56
- labelNameFromMatchers,
57
- start,
58
- end,
59
- }: LabelProviderProps): JSX.Element {
60
- const reactQueryClient = useQueryClient();
61
- const utilizationLabelResponse = useUtilizationLabels();
62
- const {
63
- loading,
64
- result,
65
- refetch: refetchLabelNamesQuery,
66
- } = useLabelNames(queryClient, profileType, start, end);
67
-
68
- const profileValues = useMemo(() => {
69
- const profileLabelNames =
70
- result.error != null ? [] : result.response?.labelNames.filter(e => e !== '__name__') ?? [];
71
- const uniqueProfileLabelNames = Array.from(new Set(profileLabelNames));
72
-
73
- return {
74
- labelNameOptions: uniqueProfileLabelNames,
75
- isLoading: loading,
76
- error: result.error ?? null,
77
- };
78
- }, [result, loading]);
79
-
80
- const utilizationValues = useMemo(() => {
81
- if (utilizationLabelResponse?.utilizationLabelNamesLoading === true) {
82
- return {labelNameOptions: [] as string[], isLoading: true};
83
- }
84
- if (
85
- utilizationLabelResponse == null ||
86
- utilizationLabelResponse.utilizationLabelNames == null
87
- ) {
88
- return {labelNameOptions: [] as string[], isLoading: false};
89
- }
90
-
91
- const uniqueUtilizationLabelNames = Array.from(
92
- new Set(utilizationLabelResponse.utilizationLabelNames)
93
- );
94
- return {
95
- labelNameOptions: uniqueUtilizationLabelNames,
96
- isLoading: utilizationLabelResponse.utilizationLabelNamesLoading,
97
- };
98
- }, [utilizationLabelResponse]);
99
-
100
- const value = useMemo(() => {
101
- if (
102
- profileValues.error != null ||
103
- profileValues.isLoading ||
104
- utilizationValues.isLoading === true
105
- ) {
106
- return {
107
- labelNameOptions: [],
108
- isLoading: (profileValues.isLoading || utilizationValues.isLoading) ?? false,
109
- error: profileValues.error,
110
- };
111
- }
112
-
113
- let nonMatchingLabels = labelNameFromMatchers.filter(
114
- label => !utilizationValues.labelNameOptions.includes(label)
115
- );
116
- nonMatchingLabels = nonMatchingLabels.filter(
117
- label => !profileValues.labelNameOptions.includes(label)
118
- );
119
-
120
- const nonMatchingLabelsSet = Array.from(new Set(nonMatchingLabels));
121
- const options = [
122
- {
123
- type: 'cpu',
124
- values: transformLabelsForSelect(profileValues.labelNameOptions),
125
- },
126
- {
127
- type: 'gpu',
128
- values: transformLabelsForSelect(utilizationValues.labelNameOptions),
129
- },
130
- {
131
- type: '',
132
- values: transformLabelsForSelect(nonMatchingLabelsSet),
133
- },
134
- ];
135
-
136
- return {
137
- labelNameOptions: options.filter(e => e.values.length > 0),
138
- isLoading: false,
139
- error: null,
140
- };
141
- }, [profileValues, utilizationValues, labelNameFromMatchers]);
142
-
143
- const refetchLabelValues = useCallback(
144
- async (labelName?: string) => {
145
- await reactQueryClient.refetchQueries({
146
- predicate: query => {
147
- const key = query.queryKey;
148
- const matchesStructure =
149
- Array.isArray(key) &&
150
- key.length === 4 &&
151
- typeof key[0] === 'string' &&
152
- key[1] === profileType;
153
-
154
- if (!matchesStructure) return false;
155
-
156
- if (labelName !== undefined && labelName !== '') {
157
- return key[0] === labelName;
158
- }
159
-
160
- return true;
161
- },
162
- });
163
- },
164
- [reactQueryClient, profileType]
165
- );
166
-
167
- const refetchLabelNames = useCallback(async () => {
168
- await refetchLabelNamesQuery();
169
- }, [refetchLabelNamesQuery]);
170
-
171
- const contextValue = useMemo(
172
- () => ({
173
- ...value,
174
- refetchLabelValues,
175
- refetchLabelNames,
176
- }),
177
- [value, refetchLabelValues, refetchLabelNames]
178
- );
179
-
180
- return <LabelContext.Provider value={contextValue}>{children}</LabelContext.Provider>;
181
- }
182
-
183
- export function useLabels(): LabelContextValue {
184
- const context = useContext(LabelContext);
185
- if (context === null) {
186
- throw new Error('useLabels must be used within a LabelProvider');
187
- }
188
- return context;
189
- }
@@ -1,45 +0,0 @@
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 {ReactNode, createContext, useContext} from 'react';
15
-
16
- export interface UtilizationLabels {
17
- utilizationLabelNames?: string[];
18
- utilizationFetchLabelValues?: (key: string) => Promise<string[]>;
19
- utilizationLabelValues?: string[];
20
- utilizationLabelNamesLoading?: boolean;
21
- }
22
-
23
- interface UtilizationLabelsProviderProps {
24
- children: ReactNode;
25
- value: UtilizationLabels | undefined;
26
- }
27
-
28
- // The UtilizationLabelsContext is used to store the utilization label names and values. It also
29
- // contains the function utilizationFetchLabelValues to fetch the utilization label values.
30
- // This context was created so as to avoid props drilling.
31
- const UtilizationLabelsContext = createContext<UtilizationLabels | undefined>(undefined);
32
-
33
- export function UtilizationLabelsProvider({
34
- children,
35
- value,
36
- }: UtilizationLabelsProviderProps): JSX.Element {
37
- return (
38
- <UtilizationLabelsContext.Provider value={value}>{children}</UtilizationLabelsContext.Provider>
39
- );
40
- }
41
-
42
- export function useUtilizationLabels(): UtilizationLabels | undefined {
43
- const context = useContext(UtilizationLabelsContext);
44
- return context;
45
- }