@parca/profile 0.16.73 → 0.16.74

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.74](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.73...@parca/profile@0.16.74) (2022-11-24)
7
+
8
+ **Note:** Version bump only for package @parca/profile
9
+
6
10
  ## [0.16.73](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.72...@parca/profile@0.16.73) (2022-11-22)
7
11
 
8
12
  **Note:** Version bump only for package @parca/profile
@@ -24,7 +24,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
24
24
  function verb(n) { return function (v) { return step([n, v]); }; }
25
25
  function step(op) {
26
26
  if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
28
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
29
  if (y = 0, t) op = [op[0] & 2, t.value];
30
30
  switch (op[0]) {
@@ -24,7 +24,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
24
24
  function verb(n) { return function (v) { return step([n, v]); }; }
25
25
  function step(op) {
26
26
  if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
28
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
29
  if (y = 0, t) op = [op[0] & 2, t.value];
30
30
  switch (op[0]) {
@@ -1,7 +1,7 @@
1
1
  import { QueryServiceClient, Flamegraph, Top, Callgraph as CallgraphType } from '@parca/client';
2
2
  import { ProfileSource } from '../ProfileSource';
3
3
  import '../ProfileView.styles.css';
4
- declare type NavigateFunction = (path: string, queryParams: any) => void;
4
+ type NavigateFunction = (path: string, queryParams: any) => void;
5
5
  export interface FlamegraphData {
6
6
  loading: boolean;
7
7
  data?: Flamegraph;
@@ -17,7 +17,7 @@ interface CallgraphData {
17
17
  data?: CallgraphType;
18
18
  error?: any;
19
19
  }
20
- export declare type VisualizationType = 'icicle' | 'table' | 'callgraph' | 'both';
20
+ export type VisualizationType = 'icicle' | 'table' | 'callgraph' | 'both';
21
21
  export interface ProfileVisState {
22
22
  currentView: VisualizationType;
23
23
  setCurrentView: (view: VisualizationType) => void;
@@ -1,6 +1,6 @@
1
1
  import { QueryServiceClient } from '@parca/client';
2
2
  import { ProfileSource } from './ProfileSource';
3
- export declare type NavigateFunction = (path: string, queryParams: any) => void;
3
+ export type NavigateFunction = (path: string, queryParams: any) => void;
4
4
  interface ProfileViewWithDataProps {
5
5
  queryClient: QueryServiceClient;
6
6
  profileSource: ProfileSource;
@@ -13,7 +13,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
13
13
  function verb(n) { return function (v) { return step([n, v]); }; }
14
14
  function step(op) {
15
15
  if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
17
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
18
  if (y = 0, t) op = [op[0] & 2, t.value];
19
19
  switch (op[0]) {
@@ -24,7 +24,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
24
24
  function verb(n) { return function (v) { return step([n, v]); }; }
25
25
  function step(op) {
26
26
  if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
28
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
29
  if (y = 0, t) op = [op[0] & 2, t.value];
30
30
  switch (op[0]) {
package/dist/index.d.ts CHANGED
@@ -26,4 +26,4 @@ interface GrafanaParcaDataPayload {
26
26
  interface GrafanaParcaErrorPayload {
27
27
  error: Error;
28
28
  }
29
- export declare type GrafanaParcaData = GrafanaParcaErrorPayload | GrafanaParcaDataPayload;
29
+ export type GrafanaParcaData = GrafanaParcaErrorPayload | GrafanaParcaDataPayload;
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
29
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
30
  if (y = 0, t) op = [op[0] & 2, t.value];
31
31
  switch (op[0]) {
@@ -0,0 +1,11 @@
1
+ import { UseQueryResult } from 'react-query';
2
+ interface Props<IRes> {
3
+ key: string | any[];
4
+ queryFn: () => Promise<IRes>;
5
+ options?: {
6
+ enabled?: boolean | undefined;
7
+ staleTime?: number | undefined;
8
+ };
9
+ }
10
+ declare const useGrpcQuery: <IRes>({ key, queryFn, options: { enabled, staleTime }, }: Props<IRes>) => UseQueryResult<IRes, unknown>;
11
+ export default useGrpcQuery;
@@ -0,0 +1,64 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ import { useQuery } from 'react-query';
50
+ var useGrpcQuery = function (_a) {
51
+ var key = _a.key, queryFn = _a.queryFn, _b = _a.options, _c = _b === void 0 ? {} : _b, _d = _c.enabled, enabled = _d === void 0 ? true : _d, staleTime = _c.staleTime;
52
+ return useQuery(key, function () { return __awaiter(void 0, void 0, void 0, function () {
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0: return [4 /*yield*/, queryFn()];
56
+ case 1: return [2 /*return*/, _a.sent()];
57
+ }
58
+ });
59
+ }); }, {
60
+ enabled: enabled,
61
+ staleTime: staleTime,
62
+ });
63
+ };
64
+ export default useGrpcQuery;
package/dist/useQuery.js CHANGED
@@ -10,31 +10,67 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { useEffect, useState } from 'react';
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
14
49
  import { useGrpcMetadata } from '@parca/components';
50
+ import useGrpcQuery from './useGrpcQuery';
15
51
  export var useQuery = function (client, profileSource, reportType, options) {
16
52
  var _a = (options !== null && options !== void 0 ? options : {}).skip, skip = _a === void 0 ? false : _a;
17
- var _b = useState({
18
- response: null,
19
- error: null,
20
- isLoading: false,
21
- }), result = _b[0], setResult = _b[1];
22
53
  var metadata = useGrpcMetadata();
23
- useEffect(function () {
24
- if (skip) {
25
- return;
26
- }
27
- setResult({
28
- response: null,
29
- error: null,
30
- isLoading: true,
31
- });
32
- var req = profileSource.QueryRequest();
33
- req.reportType = reportType;
34
- var call = client.query(req, { meta: metadata });
35
- call.response
36
- .then(function (response) { return setResult({ response: response, error: null, isLoading: false }); })
37
- .catch(function (error) { return setResult({ error: error, response: null, isLoading: false }); });
38
- }, [skip, client, profileSource, metadata, reportType]);
39
- return result;
54
+ var _b = useGrpcQuery({
55
+ key: ['query', profileSource, reportType],
56
+ queryFn: function () { return __awaiter(void 0, void 0, void 0, function () {
57
+ var req, response;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ req = profileSource.QueryRequest();
62
+ req.reportType = reportType;
63
+ return [4 /*yield*/, client.query(req, { meta: metadata })];
64
+ case 1:
65
+ response = (_a.sent()).response;
66
+ return [2 /*return*/, response];
67
+ }
68
+ });
69
+ }); },
70
+ options: {
71
+ enabled: !skip,
72
+ staleTime: 1000 * 60 * 5, // 5 minutes
73
+ },
74
+ }), data = _b.data, isLoading = _b.isLoading, error = _b.error;
75
+ return { isLoading: isLoading, error: error, response: data !== null && data !== void 0 ? data : null };
40
76
  };
package/dist/utils.js CHANGED
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  function verb(n) { return function (v) { return step([n, v]); }; }
37
37
  function step(op) {
38
38
  if (f) throw new TypeError("Generator is already executing.");
39
- while (_) try {
39
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
40
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
41
41
  if (y = 0, t) op = [op[0] & 2, t.value];
42
42
  switch (op[0]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parca/profile",
3
- "version": "0.16.73",
3
+ "version": "0.16.74",
4
4
  "description": "Profile viewing libraries",
5
5
  "dependencies": {
6
6
  "@parca/client": "^0.16.56",
@@ -16,7 +16,8 @@
16
16
  "konva": "8.3.14",
17
17
  "react-copy-to-clipboard": "^5.1.0",
18
18
  "react-cytoscapejs": "1.2.1",
19
- "react-konva": "18.2.3"
19
+ "react-konva": "18.2.3",
20
+ "react-query": "^3.39.2"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/d3": "7.4.0",
@@ -40,5 +41,5 @@
40
41
  "access": "public",
41
42
  "registry": "https://registry.npmjs.org/"
42
43
  },
43
- "gitHead": "b443ea976d1d539760bb4acee945cebf14c39263"
44
+ "gitHead": "221bef9954159edda686247e8c937939f8fc4360"
44
45
  }
@@ -0,0 +1,42 @@
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 {useQuery, UseQueryResult} from 'react-query';
15
+
16
+ interface Props<IRes> {
17
+ key: string | any[];
18
+ queryFn: () => Promise<IRes>;
19
+ options?: {
20
+ enabled?: boolean | undefined;
21
+ staleTime?: number | undefined;
22
+ };
23
+ }
24
+
25
+ const useGrpcQuery = <IRes>({
26
+ key,
27
+ queryFn,
28
+ options: {enabled = true, staleTime} = {},
29
+ }: Props<IRes>): UseQueryResult<IRes> => {
30
+ return useQuery<IRes>(
31
+ key,
32
+ async () => {
33
+ return await queryFn();
34
+ },
35
+ {
36
+ enabled,
37
+ staleTime,
38
+ }
39
+ );
40
+ };
41
+
42
+ export default useGrpcQuery;
package/src/useQuery.tsx CHANGED
@@ -11,13 +11,12 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
 
14
- import {useEffect, useState} from 'react';
15
-
16
14
  import {QueryServiceClient, QueryResponse, QueryRequest_ReportType} from '@parca/client';
17
15
  import {RpcError} from '@protobuf-ts/runtime-rpc';
18
16
  import {useGrpcMetadata} from '@parca/components';
19
17
 
20
18
  import {ProfileSource} from './ProfileSource';
19
+ import useGrpcQuery from './useGrpcQuery';
21
20
 
22
21
  export interface IQueryResult {
23
22
  response: QueryResponse | null;
@@ -36,31 +35,21 @@ export const useQuery = (
36
35
  options?: UseQueryOptions
37
36
  ): IQueryResult => {
38
37
  const {skip = false} = options ?? {};
39
- const [result, setResult] = useState<IQueryResult>({
40
- response: null,
41
- error: null,
42
- isLoading: false,
43
- });
44
38
  const metadata = useGrpcMetadata();
39
+ const {data, isLoading, error} = useGrpcQuery<QueryResponse | undefined>({
40
+ key: ['query', profileSource, reportType],
41
+ queryFn: async () => {
42
+ const req = profileSource.QueryRequest();
43
+ req.reportType = reportType;
44
+
45
+ const {response} = await client.query(req, {meta: metadata});
46
+ return response;
47
+ },
48
+ options: {
49
+ enabled: !skip,
50
+ staleTime: 1000 * 60 * 5, // 5 minutes
51
+ },
52
+ });
45
53
 
46
- useEffect(() => {
47
- if (skip) {
48
- return;
49
- }
50
- setResult({
51
- response: null,
52
- error: null,
53
- isLoading: true,
54
- });
55
- const req = profileSource.QueryRequest();
56
- req.reportType = reportType;
57
-
58
- const call = client.query(req, {meta: metadata});
59
-
60
- call.response
61
- .then(response => setResult({response, error: null, isLoading: false}))
62
- .catch(error => setResult({error, response: null, isLoading: false}));
63
- }, [skip, client, profileSource, metadata, reportType]);
64
-
65
- return result;
54
+ return {isLoading, error: error as RpcError | null, response: data ?? null};
66
55
  };