@parca/profile 0.16.402 → 0.16.403

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,10 @@
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.16.403](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.402...@parca/profile@0.16.403) (2024-07-05)
7
+
8
+ **Note:** Version bump only for package @parca/profile
9
+
6
10
  ## [0.16.402](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.401...@parca/profile@0.16.402) (2024-07-04)
7
11
 
8
12
  **Note:** Version bump only for package @parca/profile
@@ -11,10 +11,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { useEffect, useRef, useState } from 'react';
14
+ import { useEffect, useMemo, useRef, useState } from 'react';
15
15
  import { AnimatePresence, motion } from 'framer-motion';
16
16
  import { Duration, Timestamp } from '@parca/client';
17
- import { MetricsGraphSkeleton, useGrpcMetadata, useParcaContext, } from '@parca/components';
17
+ import { MetricsGraphSkeleton, useGrpcMetadata, useParcaContext, useURLState, } from '@parca/components';
18
18
  import { Query } from '@parca/parser';
19
19
  import { capitalizeOnlyFirstLetter, getStepDuration } from '@parca/utilities';
20
20
  import MetricsGraph from '../MetricsGraph';
@@ -25,6 +25,14 @@ const ErrorContent = ({ errorMessage }) => {
25
25
  export const ProfileMetricsEmptyState = ({ message }) => {
26
26
  return (_jsx("div", { className: "flex h-full w-full flex-col items-center justify-center", children: _jsx("p", { children: message }) }));
27
27
  };
28
+ const getStepCountFromScreenWidth = (pixelsPerPoint) => {
29
+ let width =
30
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
31
+ window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
32
+ // subtract the padding around the graph
33
+ width = width - (20 + 24 + 68) * 2;
34
+ return Math.round(width / pixelsPerPoint);
35
+ };
28
36
  const EMPTY_SUM_BY = [];
29
37
  export const useQueryRange = (client, queryExpression, start, end, timeRange, sumBy = EMPTY_SUM_BY, skip = false) => {
30
38
  const previousQueryParams = useRef({});
@@ -35,6 +43,22 @@ export const useQueryRange = (client, queryExpression, start, end, timeRange, su
35
43
  error: null,
36
44
  });
37
45
  const metadata = useGrpcMetadata();
46
+ const { navigateTo } = useParcaContext();
47
+ const [stepCountStr, setStepCount] = useURLState({ param: 'step_count', navigateTo });
48
+ const defaultStepCount = useMemo(() => {
49
+ return getStepCountFromScreenWidth(10);
50
+ }, []);
51
+ const stepCount = useMemo(() => {
52
+ if (stepCountStr != null) {
53
+ return parseInt(stepCountStr, 10);
54
+ }
55
+ return defaultStepCount;
56
+ }, [stepCountStr, defaultStepCount]);
57
+ useEffect(() => {
58
+ if (stepCountStr == null) {
59
+ setStepCount(defaultStepCount.toString());
60
+ }
61
+ }, [stepCountStr, defaultStepCount, setStepCount]);
38
62
  useEffect(() => {
39
63
  void (async () => {
40
64
  if (skip) {
@@ -50,7 +74,7 @@ export const useQueryRange = (client, queryExpression, start, end, timeRange, su
50
74
  previousQueryParams.current.isRefresh = true;
51
75
  }
52
76
  setLoading(true);
53
- const stepDuration = getStepDuration(start, end);
77
+ const stepDuration = getStepDuration(start, end, stepCount);
54
78
  const call = client.queryRange({
55
79
  query: queryExpression,
56
80
  start: Timestamp.fromDate(new Date(start)),
@@ -75,7 +99,7 @@ export const useQueryRange = (client, queryExpression, start, end, timeRange, su
75
99
  }
76
100
  });
77
101
  })();
78
- }, [client, queryExpression, start, end, metadata, timeRange, sumBy, skip]);
102
+ }, [client, queryExpression, start, end, metadata, timeRange, sumBy, skip, stepCount]);
79
103
  return { ...state, isLoading, isRefreshing: previousQueryParams.current.isRefresh };
80
104
  };
81
105
  const ProfileMetricsGraph = ({ queryClient, queryExpression, profile, from, to, setTimeRange, addLabelMatcher, onPointClick, comparing = false, timeRange, }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parca/profile",
3
- "version": "0.16.402",
3
+ "version": "0.16.403",
4
4
  "description": "Profile viewing libraries",
5
5
  "dependencies": {
6
6
  "@headlessui/react": "^1.7.19",
@@ -73,5 +73,5 @@
73
73
  "access": "public",
74
74
  "registry": "https://registry.npmjs.org/"
75
75
  },
76
- "gitHead": "25851d40d2630dbb542747d3a09718363212ad0e"
76
+ "gitHead": "a29408aa67b9e9791fd62789420cbfc7503adb46"
77
77
  }
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
 
14
- import {useEffect, useRef, useState} from 'react';
14
+ import {useEffect, useMemo, useRef, useState} from 'react';
15
15
 
16
16
  import {RpcError} from '@protobuf-ts/runtime-rpc';
17
17
  import {AnimatePresence, motion} from 'framer-motion';
@@ -22,6 +22,7 @@ import {
22
22
  MetricsGraphSkeleton,
23
23
  useGrpcMetadata,
24
24
  useParcaContext,
25
+ useURLState,
25
26
  } from '@parca/components';
26
27
  import {Query} from '@parca/parser';
27
28
  import {capitalizeOnlyFirstLetter, getStepDuration} from '@parca/utilities';
@@ -80,6 +81,16 @@ export interface IQueryRangeState {
80
81
  error: RpcError | null;
81
82
  }
82
83
 
84
+ const getStepCountFromScreenWidth = (pixelsPerPoint: number): number => {
85
+ let width =
86
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
87
+ window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
88
+
89
+ // subtract the padding around the graph
90
+ width = width - (20 + 24 + 68) * 2;
91
+ return Math.round(width / pixelsPerPoint);
92
+ };
93
+
83
94
  const EMPTY_SUM_BY: string[] = [];
84
95
 
85
96
  export const useQueryRange = (
@@ -103,6 +114,26 @@ export const useQueryRange = (
103
114
  error: null,
104
115
  });
105
116
  const metadata = useGrpcMetadata();
117
+ const {navigateTo} = useParcaContext();
118
+ const [stepCountStr, setStepCount] = useURLState({param: 'step_count', navigateTo});
119
+
120
+ const defaultStepCount = useMemo(() => {
121
+ return getStepCountFromScreenWidth(10);
122
+ }, []);
123
+
124
+ const stepCount = useMemo(() => {
125
+ if (stepCountStr != null) {
126
+ return parseInt(stepCountStr as string, 10);
127
+ }
128
+
129
+ return defaultStepCount;
130
+ }, [stepCountStr, defaultStepCount]);
131
+
132
+ useEffect(() => {
133
+ if (stepCountStr == null) {
134
+ setStepCount(defaultStepCount.toString());
135
+ }
136
+ }, [stepCountStr, defaultStepCount, setStepCount]);
106
137
 
107
138
  useEffect(() => {
108
139
  void (async () => {
@@ -123,7 +154,7 @@ export const useQueryRange = (
123
154
 
124
155
  setLoading(true);
125
156
 
126
- const stepDuration = getStepDuration(start, end);
157
+ const stepDuration = getStepDuration(start, end, stepCount);
127
158
  const call = client.queryRange(
128
159
  {
129
160
  query: queryExpression,
@@ -152,7 +183,7 @@ export const useQueryRange = (
152
183
  }
153
184
  });
154
185
  })();
155
- }, [client, queryExpression, start, end, metadata, timeRange, sumBy, skip]);
186
+ }, [client, queryExpression, start, end, metadata, timeRange, sumBy, skip, stepCount]);
156
187
 
157
188
  return {...state, isLoading, isRefreshing: previousQueryParams.current.isRefresh};
158
189
  };