@parca/profile 0.15.17 → 0.15.18

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.15.18](https://github.com/parca-dev/parca/compare/ui-v0.15.17...ui-v0.15.18) (2022-09-08)
7
+
8
+
9
+
10
+ ## [0.15.10](https://github.com/parca-dev/parca/compare/ui-v0.15.8...ui-v0.15.10) (2022-08-30)
11
+
12
+ **Note:** Version bump only for package @parca/profile
13
+
14
+
15
+
16
+
17
+
6
18
  ## [0.15.17](https://github.com/parca-dev/parca/compare/ui-v0.15.16...ui-v0.15.17) (2022-09-07)
7
19
 
8
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parca/profile",
3
- "version": "0.15.17",
3
+ "version": "0.15.18",
4
4
  "description": "Profile viewing libraries",
5
5
  "dependencies": {
6
6
  "@iconify/react": "^3.2.2",
@@ -23,5 +23,5 @@
23
23
  "access": "public",
24
24
  "registry": "https://registry.npmjs.org/"
25
25
  },
26
- "gitHead": "df4bacb55c1503822de9d3312ebe8b90ff17d55b"
26
+ "gitHead": "6af20931851774b1548661a5a47ccfd71b1a2c61"
27
27
  }
@@ -20,7 +20,6 @@ import {
20
20
  Button,
21
21
  Card,
22
22
  SearchNodes,
23
- useGrpcMetadata,
24
23
  useParcaTheme,
25
24
  Callgraph as CallgraphComponent,
26
25
  } from '@parca/components';
@@ -31,7 +30,6 @@ import ProfileIcicleGraph from './ProfileIcicleGraph';
31
30
  import {ProfileSource} from './ProfileSource';
32
31
  import TopTable from './TopTable';
33
32
  import useDelayedLoader from './useDelayedLoader';
34
- import {downloadPprof} from './utils';
35
33
 
36
34
  import './ProfileView.styles.css';
37
35
 
@@ -55,7 +53,7 @@ interface CallgraphData {
55
53
  error?: any;
56
54
  }
57
55
 
58
- type VisualizationType = 'icicle' | 'table' | 'callgraph' | 'both';
56
+ export type VisualizationType = 'icicle' | 'table' | 'callgraph' | 'both';
59
57
 
60
58
  interface ProfileVisState {
61
59
  currentView: VisualizationType;
@@ -72,6 +70,7 @@ interface ProfileViewProps {
72
70
  queryClient?: QueryServiceClient;
73
71
  navigateTo?: NavigateFunction;
74
72
  compare?: boolean;
73
+ onDownloadPProf: () => void;
75
74
  }
76
75
 
77
76
  function arrayEquals<T>(a: T[], b: T[]): boolean {
@@ -83,11 +82,18 @@ function arrayEquals<T>(a: T[], b: T[]): boolean {
83
82
  );
84
83
  }
85
84
  export const useProfileVisState = (): ProfileVisState => {
86
- const router = parseParams(window.location.search);
87
- const currentViewFromURL = router.currentProfileView as string;
88
- const [currentView, setCurrentView] = useState<VisualizationType>(
89
- (currentViewFromURL as VisualizationType) ?? 'icicle'
90
- );
85
+ const [currentView, setCurrentView] = useState<VisualizationType>(() => {
86
+ if (typeof window === 'undefined') {
87
+ return 'icicle';
88
+ }
89
+ const router = parseParams(window.location.search);
90
+ const currentViewFromURL = router.currentProfileView as string;
91
+
92
+ if (currentViewFromURL != null) {
93
+ return currentViewFromURL as VisualizationType;
94
+ }
95
+ return 'icicle';
96
+ });
91
97
 
92
98
  return {currentView, setCurrentView};
93
99
  };
@@ -101,6 +107,7 @@ export const ProfileView = ({
101
107
  queryClient,
102
108
  navigateTo,
103
109
  profileVisState,
110
+ onDownloadPProf,
104
111
  }: ProfileViewProps): JSX.Element => {
105
112
  const {ref, dimensions} = useContainerDimensions();
106
113
  const [curPath, setCurPath] = useState<string[]>([]);
@@ -108,7 +115,6 @@ export const ProfileView = ({
108
115
 
109
116
  const [callgraphEnabled] = useUIFeatureFlag('callgraph');
110
117
 
111
- const metadata = useGrpcMetadata();
112
118
  const {loader} = useParcaTheme();
113
119
 
114
120
  useEffect(() => {
@@ -147,23 +153,6 @@ export const ProfileView = ({
147
153
  );
148
154
  }
149
155
 
150
- const downloadPProf = async (e: React.MouseEvent<HTMLElement>): Promise<void> => {
151
- e.preventDefault();
152
- if (profileSource == null || queryClient == null) {
153
- return;
154
- }
155
-
156
- try {
157
- const blob = await downloadPprof(profileSource.QueryRequest(), queryClient, metadata);
158
- const link = document.createElement('a');
159
- link.href = window.URL.createObjectURL(blob);
160
- link.download = 'profile.pb.gz';
161
- link.click();
162
- } catch (error) {
163
- console.error('Error while querying', error);
164
- }
165
- };
166
-
167
156
  const resetIcicleGraph = (): void => setCurPath([]);
168
157
 
169
158
  const setNewCurPath = (path: string[]): void => {
@@ -176,11 +165,12 @@ export const ProfileView = ({
176
165
  if (view == null) {
177
166
  return;
178
167
  }
179
- if (navigateTo === undefined) return;
180
-
181
168
  setCurrentView(view);
182
- const router = parseParams(window.location.search);
183
169
 
170
+ if (navigateTo === undefined) {
171
+ return;
172
+ }
173
+ const router = parseParams(window.location.search);
184
174
  navigateTo('/', {...router, ...{currentProfileView: view}});
185
175
  };
186
176
 
@@ -199,7 +189,13 @@ export const ProfileView = ({
199
189
  />
200
190
  ) : null}
201
191
 
202
- <Button color="neutral" onClick={void downloadPProf}>
192
+ <Button
193
+ color="neutral"
194
+ onClick={e => {
195
+ e.preventDefault();
196
+ onDownloadPProf();
197
+ }}
198
+ >
203
199
  Download pprof
204
200
  </Button>
205
201
  </div>
@@ -16,6 +16,8 @@ import {QueryServiceClient, QueryRequest_ReportType} from '@parca/client';
16
16
  import {useQuery} from './useQuery';
17
17
  import {ProfileView, useProfileVisState} from './ProfileView';
18
18
  import {ProfileSource} from './ProfileSource';
19
+ import {downloadPprof} from './utils';
20
+ import {useGrpcMetadata} from '@parca/components';
19
21
 
20
22
  type NavigateFunction = (path: string, queryParams: any) => void;
21
23
 
@@ -32,6 +34,7 @@ export const ProfileViewWithData = ({
32
34
  navigateTo,
33
35
  }: ProfileViewWithDataProps): JSX.Element => {
34
36
  const profileVisState = useProfileVisState();
37
+ const metadata = useGrpcMetadata();
35
38
  const {currentView} = profileVisState;
36
39
  const {
37
40
  isLoading: flamegraphLoading,
@@ -59,6 +62,22 @@ export const ProfileViewWithData = ({
59
62
 
60
63
  const sampleUnit = profileSource.ProfileType().sampleUnit;
61
64
 
65
+ const downloadPProfClick = async (): Promise<void> => {
66
+ if (profileSource == null || queryClient == null) {
67
+ return;
68
+ }
69
+
70
+ try {
71
+ const blob = await downloadPprof(profileSource.QueryRequest(), queryClient, metadata);
72
+ const link = document.createElement('a');
73
+ link.href = window.URL.createObjectURL(blob);
74
+ link.download = 'profile.pb.gz';
75
+ link.click();
76
+ } catch (error) {
77
+ console.error('Error while querying', error);
78
+ }
79
+ };
80
+
62
81
  return (
63
82
  <ProfileView
64
83
  flamegraphData={{
@@ -88,6 +107,7 @@ export const ProfileViewWithData = ({
88
107
  profileSource={profileSource}
89
108
  queryClient={queryClient}
90
109
  navigateTo={navigateTo}
110
+ onDownloadPProf={() => void downloadPProfClick()}
91
111
  />
92
112
  );
93
113
  };