@parca/profile 0.16.82 → 0.16.84

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.
@@ -0,0 +1,91 @@
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
+ const {GrpcWebFetchTransport} = require('@protobuf-ts/grpcweb-transport');
15
+ const client = require('@parca/client');
16
+ const fs = require('fs-extra');
17
+ const path = require('path');
18
+ // const {fileURLToPath} = require('url');
19
+ const fetch = require('node-fetch');
20
+
21
+ globalThis.fetch = fetch;
22
+ globalThis.Headers = fetch.Headers;
23
+ const DIR_NAME = __dirname; // path.dirname(fileURLToPath(import.meta.url));
24
+
25
+ const apiEndpoint = 'https://demo.parca.dev';
26
+
27
+ const queryClient = new client.QueryServiceClient(
28
+ new GrpcWebFetchTransport({
29
+ baseUrl: `${apiEndpoint}/api`,
30
+ })
31
+ );
32
+
33
+ const populateDataIfNeeded = async (from, filename) => {
34
+ const filePath = path.join(DIR_NAME, filename);
35
+ if (Object.keys(await readFile(filePath)).length > 0) {
36
+ return;
37
+ }
38
+ const {response} = await queryClient.query({
39
+ options: {
40
+ oneofKind: 'merge',
41
+ merge: {
42
+ start: client.Timestamp.fromDate(from),
43
+ end: client.Timestamp.fromDate(new Date()),
44
+ query: 'parca_agent_cpu:samples:count:cpu:nanoseconds:delta{container="parca"}',
45
+ },
46
+ },
47
+ reportType: client.QueryRequest_ReportType.TOP,
48
+ mode: client.QueryRequest_Mode.MERGE,
49
+ });
50
+ if (response.report.oneofKind !== 'top') {
51
+ throw new Error('Expected topTable report');
52
+ }
53
+ await writeToFile(response.report.top, filePath);
54
+ };
55
+
56
+ const writeToFile = async (data, filename) => {
57
+ await fs.createFile(filename);
58
+ return await fs.writeFile(filename, JSON.stringify(data));
59
+ };
60
+
61
+ const readFile = async filename => {
62
+ try {
63
+ return await fs.readJSON(filename);
64
+ } catch (e) {
65
+ return {};
66
+ }
67
+ };
68
+
69
+ const run = async () => {
70
+ await Promise.all([
71
+ populateDataIfNeeded(new Date(new Date().getTime() - 1000 * 60), 'parca-toptable-1m.json'),
72
+ populateDataIfNeeded(
73
+ new Date(new Date().getTime() - 1000 * 60 * 10),
74
+ 'parca-toptable-10m.json'
75
+ ),
76
+ populateDataIfNeeded(
77
+ new Date(new Date().getTime() - 1000 * 60 * 20),
78
+ 'parca-toptable-20m.json'
79
+ ),
80
+ ]);
81
+ };
82
+
83
+ run()
84
+ .then(() => {
85
+ console.log('done');
86
+ process.exit(0);
87
+ })
88
+ .catch(err => {
89
+ console.error('Error:', err);
90
+ process.exit(1);
91
+ });
@@ -0,0 +1,175 @@
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 React, {useCallback, useMemo} from 'react';
15
+
16
+ import {getLastItem, valueFormatter, isSearchMatch} from '@parca/functions';
17
+ import {
18
+ useAppSelector,
19
+ selectCompareMode,
20
+ selectSearchNodeString,
21
+ setSearchNodeString,
22
+ useAppDispatch,
23
+ } from '@parca/store';
24
+ import {TopNode, TopNodeMeta, Top} from '@parca/client';
25
+ import {Table} from '@parca/components';
26
+ import {createColumnHelper, ColumnDef} from '@tanstack/react-table';
27
+
28
+ import {hexifyAddress} from '../utils';
29
+
30
+ import '../TopTable.styles.css';
31
+
32
+ interface TopTableProps {
33
+ data?: Top;
34
+ sampleUnit: string;
35
+ }
36
+
37
+ export const RowLabel = (meta: TopNodeMeta | undefined): string => {
38
+ if (meta === undefined) return '<unknown>';
39
+ const mapping = `${
40
+ meta?.mapping?.file !== undefined && meta?.mapping?.file !== ''
41
+ ? `[${getLastItem(meta.mapping.file) ?? ''}]`
42
+ : ''
43
+ }`;
44
+ if (meta.function?.name !== undefined && meta.function?.name !== '')
45
+ return `${mapping} ${meta.function.name}`;
46
+
47
+ const address = hexifyAddress(meta.location?.address);
48
+ const fallback = `${mapping} ${address}`;
49
+
50
+ return fallback === '' ? '<unknown>' : fallback;
51
+ };
52
+
53
+ const columnHelper = createColumnHelper<TopNode>();
54
+
55
+ const addPlusSign = (num: string): string => {
56
+ if (num.charAt(0) === '0' || num.charAt(0) === '-') {
57
+ return num;
58
+ }
59
+
60
+ return `+${num}`;
61
+ };
62
+
63
+ export const TopTable = ({data: top, sampleUnit: unit}: TopTableProps): JSX.Element => {
64
+ const currentSearchString = useAppSelector(selectSearchNodeString);
65
+ const compareMode = useAppSelector(selectCompareMode);
66
+ const dispatch = useAppDispatch();
67
+
68
+ const columns = React.useMemo(() => {
69
+ const cols: Array<ColumnDef<TopNode, any>> = [
70
+ columnHelper.accessor('meta', {
71
+ header: () => <span className="text-left">Name</span>,
72
+ cell: info => {
73
+ const meta = info.row.original.meta;
74
+ const name = RowLabel(meta);
75
+ return name;
76
+ },
77
+ sortingFn: (a, b) => {
78
+ const aName = RowLabel(a.original.meta);
79
+ const bName = RowLabel(b.original.meta);
80
+ return aName.localeCompare(bName);
81
+ },
82
+ }),
83
+ columnHelper.accessor('flat', {
84
+ header: () => 'Flat',
85
+ cell: info => valueFormatter(Number(info.getValue()), unit, 2),
86
+ size: 150,
87
+ meta: {
88
+ align: 'right',
89
+ },
90
+ sortDescFirst: true,
91
+ }),
92
+ columnHelper.accessor('cumulative', {
93
+ header: () => 'Cumulative',
94
+ cell: info => valueFormatter(Number(info.getValue()), unit, 2),
95
+ size: 150,
96
+ meta: {
97
+ align: 'right',
98
+ },
99
+ sortDescFirst: true,
100
+ }),
101
+ ];
102
+ if (compareMode) {
103
+ cols.push(
104
+ columnHelper.accessor('diff', {
105
+ header: () => 'Diff',
106
+ cell: info => addPlusSign(valueFormatter(Number(info.getValue()), unit, 2)),
107
+ size: 150,
108
+ meta: {
109
+ align: 'right',
110
+ },
111
+ sortDescFirst: true,
112
+ })
113
+ );
114
+ }
115
+ return cols;
116
+ }, [unit, compareMode]);
117
+
118
+ const selectSpan = useCallback(
119
+ (span: string): void => {
120
+ dispatch(setSearchNodeString(span.trim()));
121
+ },
122
+ [dispatch]
123
+ );
124
+
125
+ const onRowClick = useCallback(
126
+ (row: TopNode) => {
127
+ const meta = row.meta;
128
+ if (meta === undefined) {
129
+ return;
130
+ }
131
+ const name = RowLabel(meta);
132
+ selectSpan(name);
133
+ },
134
+ [selectSpan]
135
+ );
136
+
137
+ const shouldHighlightRow = useCallback(
138
+ (row: TopNode) => {
139
+ const meta = row.meta;
140
+ if (meta === undefined) return false;
141
+ const name = RowLabel(meta);
142
+ return isSearchMatch(currentSearchString, name);
143
+ },
144
+ [currentSearchString]
145
+ );
146
+
147
+ const enableHighlighting = useMemo(() => {
148
+ return currentSearchString != null && currentSearchString?.length > 0;
149
+ }, [currentSearchString]);
150
+
151
+ const initialSorting = useMemo(() => {
152
+ return [{id: compareMode ? 'diff' : 'cumulative', desc: true}];
153
+ }, [compareMode]);
154
+
155
+ const total = top != null ? top.list.length : 0;
156
+
157
+ if (total === 0) return <>Profile has no samples</>;
158
+
159
+ return (
160
+ <>
161
+ <div className="w-full font-robotoMono h-[80vh] overflow-scroll">
162
+ <Table
163
+ data={top?.list ?? []}
164
+ columns={columns}
165
+ initialSorting={initialSorting}
166
+ onRowClick={onRowClick}
167
+ enableHighlighting={enableHighlighting}
168
+ shouldHighlightRow={shouldHighlightRow}
169
+ />
170
+ </div>
171
+ </>
172
+ );
173
+ };
174
+
175
+ export default TopTable;
@@ -20,6 +20,7 @@ import ResultBox from './ResultBox';
20
20
  interface Props {
21
21
  queryRequest: QueryRequest;
22
22
  queryClient: QueryServiceClient;
23
+ disabled?: boolean;
23
24
  }
24
25
 
25
26
  interface ProfileShareModalProps {
@@ -117,12 +118,12 @@ const ProfileShareModal = ({
117
118
  );
118
119
  };
119
120
 
120
- const ProfileShareButton = ({queryRequest, queryClient}: Props): JSX.Element => {
121
+ const ProfileShareButton = ({queryRequest, queryClient, disabled = false}: Props): JSX.Element => {
121
122
  const [isOpen, setIsOpen] = useState<boolean>(false);
122
123
 
123
124
  return (
124
125
  <>
125
- <Button color="neutral" className="w-fit" onClick={() => setIsOpen(true)}>
126
+ <Button color="neutral" className="w-fit" onClick={() => setIsOpen(true)} disabled={disabled}>
126
127
  <Icon icon="ei:share-apple" width={20} />
127
128
  </Button>
128
129
  <ProfileShareModal
package/tsconfig.json CHANGED
@@ -8,5 +8,12 @@
8
8
  "noEmit": false,
9
9
  "declaration": true
10
10
  },
11
- "exclude": ["node_modules", "dist", "dist/**/*.d.ts", "**/*.test.ts", "**/*.benchmark.tsx"]
11
+ "exclude": [
12
+ "node_modules",
13
+ "dist",
14
+ "dist/**/*.d.ts",
15
+ "**/*.test.ts",
16
+ "**/*.benchmark.tsx",
17
+ "**/benchdata/**/*.*"
18
+ ]
12
19
  }
package/dist/TopTable.js DELETED
@@ -1,144 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
- if (ar || !(i in from)) {
15
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
- ar[i] = from[i];
17
- }
18
- }
19
- return to.concat(ar || Array.prototype.slice.call(from));
20
- };
21
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
- // Copyright 2022 The Parca Authors
23
- // Licensed under the Apache License, Version 2.0 (the "License");
24
- // you may not use this file except in compliance with the License.
25
- // You may obtain a copy of the License at
26
- //
27
- // http://www.apache.org/licenses/LICENSE-2.0
28
- //
29
- // Unless required by applicable law or agreed to in writing, software
30
- // distributed under the License is distributed on an "AS IS" BASIS,
31
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- // See the License for the specific language governing permissions and
33
- // limitations under the License.
34
- import React from 'react';
35
- import { getLastItem, valueFormatter, isSearchMatch } from '@parca/functions';
36
- import { useAppSelector, selectCompareMode, selectSearchNodeString, setSearchNodeString, useAppDispatch, } from '@parca/store';
37
- import { hexifyAddress } from './utils';
38
- import './TopTable.styles.css';
39
- var Arrow = function (_a) {
40
- var direction = _a.direction;
41
- return (_jsx("svg", __assign({ className: "".concat(direction !== undefined ? 'fill-[#161616] dark:fill-[#ffffff]' : ''), fill: "#777d87", height: "10", viewBox: "0 0 11 10", width: "11", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx("path", { clipRule: "evenodd", d: "m.573997 0 5.000003 10 5-10h-9.999847z", fillRule: "evenodd" }) })));
42
- };
43
- var useSortableData = function (top, config) {
44
- if (config === void 0) { config = {
45
- key: 'cumulative',
46
- direction: 'desc',
47
- }; }
48
- var _a = React.useState(config), sortConfig = _a[0], setSortConfig = _a[1];
49
- var rawTableReport = top != null ? top.list : [];
50
- var items = rawTableReport.map(function (node) {
51
- var _a, _b;
52
- return (__assign(__assign({}, node), {
53
- // Warning: string to number can overflow
54
- // https://github.com/timostamm/protobuf-ts/blob/master/MANUAL.md#bigint-support
55
- diff: Number(node.diff), cumulative: Number(node.cumulative), flat: Number(node.flat), name: (_b = (_a = node.meta) === null || _a === void 0 ? void 0 : _a.function) === null || _b === void 0 ? void 0 : _b.name }));
56
- });
57
- var sortedItems = React.useMemo(function () {
58
- if (items.length === 0)
59
- return;
60
- var sortableItems = __spreadArray([], items, true);
61
- if (sortConfig !== null) {
62
- sortableItems.sort(function (a, b) {
63
- var itemA = a[sortConfig.key];
64
- var itemB = b[sortConfig.key];
65
- if (itemA === undefined && itemB === undefined) {
66
- return 0;
67
- }
68
- if (itemA === undefined) {
69
- return sortConfig.direction === 'asc' ? -1 : 1;
70
- }
71
- if (itemB === undefined) {
72
- return sortConfig.direction === 'asc' ? 1 : -1;
73
- }
74
- if (itemA < itemB) {
75
- return sortConfig.direction === 'asc' ? -1 : 1;
76
- }
77
- if (itemA > itemB) {
78
- return sortConfig.direction === 'asc' ? 1 : -1;
79
- }
80
- return 0;
81
- });
82
- }
83
- return sortableItems;
84
- }, [items, sortConfig]);
85
- var requestSort = function (key) {
86
- var direction = 'desc';
87
- if (sortConfig != null && sortConfig.key === key && sortConfig.direction === 'desc') {
88
- direction = 'asc';
89
- }
90
- setSortConfig({ key: key, direction: direction });
91
- };
92
- return { items: sortedItems, requestSort: requestSort, sortConfig: sortConfig };
93
- };
94
- export var RowLabel = function (meta) {
95
- var _a, _b, _c, _d, _e, _f;
96
- if (meta === undefined)
97
- return '<unknown>';
98
- var mapping = "".concat(((_a = meta === null || meta === void 0 ? void 0 : meta.mapping) === null || _a === void 0 ? void 0 : _a.file) !== undefined && ((_b = meta === null || meta === void 0 ? void 0 : meta.mapping) === null || _b === void 0 ? void 0 : _b.file) !== ''
99
- ? "[".concat((_c = getLastItem(meta.mapping.file)) !== null && _c !== void 0 ? _c : '', "]")
100
- : '');
101
- if (((_d = meta.function) === null || _d === void 0 ? void 0 : _d.name) !== undefined && ((_e = meta.function) === null || _e === void 0 ? void 0 : _e.name) !== '')
102
- return "".concat(mapping, " ").concat(meta.function.name);
103
- var address = hexifyAddress((_f = meta.location) === null || _f === void 0 ? void 0 : _f.address);
104
- var fallback = "".concat(mapping, " ").concat(address);
105
- return fallback === '' ? '<unknown>' : fallback;
106
- };
107
- export var TopTable = function (_a) {
108
- var _b, _c, _d, _e;
109
- var top = _a.data, sampleUnit = _a.sampleUnit;
110
- var _f = useSortableData(top), items = _f.items, requestSort = _f.requestSort, sortConfig = _f.sortConfig;
111
- var currentSearchString = useAppSelector(selectSearchNodeString);
112
- var compareMode = useAppSelector(selectCompareMode);
113
- var dispatch = useAppDispatch();
114
- var unit = sampleUnit;
115
- var total = top != null ? top.list.length : 0;
116
- if (total === 0)
117
- return _jsx(_Fragment, { children: "Profile has no samples" });
118
- var getClassNamesFor = function (name) {
119
- if (sortConfig == null) {
120
- return;
121
- }
122
- return sortConfig.key === name ? sortConfig.direction : undefined;
123
- };
124
- var addPlusSign = function (num) {
125
- if (num.charAt(0) === '0' || num.charAt(0) === '-') {
126
- return num;
127
- }
128
- return "+".concat(num);
129
- };
130
- var selectSpan = function (span) {
131
- dispatch(setSearchNodeString(span.trim()));
132
- };
133
- return (_jsx(_Fragment, { children: _jsx("div", __assign({ className: "w-full font-robotoMono" }, { children: _jsxs("table", __assign({ className: "iciclegraph-table table-fixed text-left w-full divide-y divide-gray-200 dark:divide-gray-700", tabIndex: 1 }, { children: [_jsx("thead", __assign({ className: "bg-gray-50 dark:bg-gray-800" }, { children: _jsxs("tr", { children: [_jsxs("th", __assign({ className: "text-sm cursor-pointer pt-2 pb-2 pl-2", onClick: function () { return requestSort('name'); } }, { children: ["Name", _jsx("span", __assign({ className: "inline-block align-middle ml-2 ".concat((_b = getClassNamesFor('name')) !== null && _b !== void 0 ? _b : '') }, { children: _jsx(Arrow, { direction: getClassNamesFor('name') }) }))] })), _jsxs("th", __assign({ className: "text-right text-sm cursor-pointer pt-2 pb-2 w-[150px]", onClick: function () { return requestSort('flat'); } }, { children: ["Flat", _jsx("span", __assign({ className: "inline-block align-middle ml-2 ".concat((_c = getClassNamesFor('flat')) !== null && _c !== void 0 ? _c : '') }, { children: _jsx(Arrow, { direction: getClassNamesFor('flat') }) }))] })), _jsxs("th", __assign({ className: "text-right text-sm cursor-pointer pt-2 pb-2 pr-2 w-[150px]", onClick: function () { return requestSort('cumulative'); } }, { children: ["Cumulative", _jsx("span", __assign({ className: "inline-block align-middle ml-2 ".concat((_d = getClassNamesFor('cumulative')) !== null && _d !== void 0 ? _d : '') }, { children: _jsx(Arrow, { direction: getClassNamesFor('cumulative') }) }))] })), compareMode && (_jsxs("th", __assign({ className: "text-right text-sm cursor-pointer pt-2 pb-2 pr-2 w-[150px]", onClick: function () { return requestSort('diff'); } }, { children: ["Diff", _jsx("span", __assign({ className: "inline-block align-middle ml-2 ".concat((_e = getClassNamesFor('diff')) !== null && _e !== void 0 ? _e : '') }, { children: _jsx(Arrow, { direction: getClassNamesFor('diff') }) }))] })))] }) })), _jsx("tbody", __assign({ className: "bg-white divide-y divide-gray-200 dark:bg-gray-900 dark:divide-gray-700" }, { children: items === null || items === void 0 ? void 0 : items.map(function (report, index) {
134
- var name = RowLabel(report.meta);
135
- return (_jsxs("tr", __assign({ className: "hover:bg-[#62626212] dark:hover:bg-[#ffffff12] cursor-pointer", style: {
136
- opacity: currentSearchString !== undefined &&
137
- currentSearchString !== '' &&
138
- !isSearchMatch(currentSearchString, name)
139
- ? 0.5
140
- : 1,
141
- }, onClick: function () { return selectSpan(name); } }, { children: [_jsx("td", __assign({ className: "text-xs py-1.5 pl-2" }, { children: name })), _jsx("td", __assign({ className: "text-xs py-1.5 text-right" }, { children: valueFormatter(report.flat, unit, 2) })), _jsx("td", __assign({ className: "text-xs py-1.5 text-right pr-2" }, { children: valueFormatter(report.cumulative, unit, 2) })), compareMode && (_jsx("td", __assign({ className: "text-xs py-1.5 text-right pr-2" }, { children: addPlusSign(valueFormatter(report.diff, unit, 2)) })))] }), index));
142
- }) }))] })) })) }));
143
- };
144
- export default TopTable;