@parca/profile 0.19.139 → 0.19.142

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 (170) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/GraphTooltipArrow/Content.js +224 -30
  3. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +192 -33
  4. package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +53 -3
  5. package/dist/GraphTooltipArrow/index.d.ts.map +1 -1
  6. package/dist/GraphTooltipArrow/index.js +86 -56
  7. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +37 -37
  8. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +103 -73
  9. package/dist/MatchersInput/SuggestionItem.js +91 -12
  10. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  11. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  12. package/dist/MatchersInput/SuggestionsList.js +371 -157
  13. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  15. package/dist/MatchersInput/index.js +308 -115
  16. package/dist/MetricsCircle/index.js +39 -3
  17. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  18. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  19. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  20. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  21. package/dist/MetricsGraph/index.js +552 -203
  22. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  23. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  24. package/dist/MetricsSeries/index.js +70 -7
  25. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  26. package/dist/PreSelectedMatchers/index.js +249 -102
  27. package/dist/ProfileExplorer/ProfileExplorerCompare.js +240 -49
  28. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  29. package/dist/ProfileExplorer/index.js +183 -32
  30. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  31. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  32. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  33. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  34. package/dist/ProfileFlameChart/index.js +266 -134
  35. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +287 -88
  36. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  37. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  38. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  39. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +71 -45
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  55. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  56. package/dist/ProfileFlameGraph/index.js +324 -148
  57. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  58. package/dist/ProfileMetricsGraph/index.js +518 -259
  59. package/dist/ProfileSelector/CompareButton.js +132 -12
  60. package/dist/ProfileSelector/MetricsGraphSection.js +234 -67
  61. package/dist/ProfileSelector/index.d.ts.map +1 -1
  62. package/dist/ProfileSelector/index.js +730 -142
  63. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  64. package/dist/ProfileSource.js +230 -163
  65. package/dist/ProfileTypeSelector/index.js +214 -125
  66. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  67. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +139 -33
  68. package/dist/ProfileView/components/ColorStackLegend.js +184 -55
  69. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  70. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  71. package/dist/ProfileView/components/DiffLegend.js +172 -29
  72. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  73. package/dist/ProfileView/components/InvertCallStack/index.js +99 -10
  74. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  75. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  76. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  77. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -120
  78. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  79. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  80. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  81. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  82. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +675 -195
  83. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  84. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +198 -157
  85. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  86. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  87. package/dist/ProfileView/components/ViewSelector/index.js +211 -91
  88. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  89. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  90. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  91. package/dist/ProfileView/context/DashboardContext.js +84 -28
  92. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  93. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  94. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  95. package/dist/ProfileView/hooks/useResetFlameGraphState.js +31 -10
  96. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +72 -29
  97. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +39 -13
  98. package/dist/ProfileView/hooks/useVisualizationState.js +262 -87
  99. package/dist/ProfileView/index.js +383 -45
  100. package/dist/ProfileView/types/visualization.js +1 -13
  101. package/dist/ProfileView/utils/colorUtils.js +8 -7
  102. package/dist/ProfileViewWithData.js +332 -237
  103. package/dist/QueryControls/index.js +418 -47
  104. package/dist/Sandwich/components/CalleesSection.js +54 -4
  105. package/dist/Sandwich/components/CallersSection.js +97 -27
  106. package/dist/Sandwich/components/TableSection.js +77 -4
  107. package/dist/Sandwich/index.js +125 -12
  108. package/dist/Sandwich/utils/processRowData.js +48 -39
  109. package/dist/SelectWithRefresh/index.js +102 -28
  110. package/dist/SimpleMatchers/Select.js +520 -187
  111. package/dist/SimpleMatchers/index.js +590 -288
  112. package/dist/SourceView/Highlighter.js +230 -70
  113. package/dist/SourceView/LineNo.js +72 -17
  114. package/dist/SourceView/index.js +177 -101
  115. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  116. package/dist/SourceView/lang-detector/index.js +28 -14
  117. package/dist/SourceView/useSelectedLineRange.js +97 -16
  118. package/dist/Table/ColorCell.js +42 -1
  119. package/dist/Table/ColumnsVisibility.js +114 -6
  120. package/dist/Table/MoreDropdown.js +121 -27
  121. package/dist/Table/TableContextMenu.js +150 -139
  122. package/dist/Table/TableContextMenuWrapper.js +59 -14
  123. package/dist/Table/hooks/useColorManagement.js +58 -16
  124. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  125. package/dist/Table/hooks/useTableConfiguration.js +331 -168
  126. package/dist/Table/index.js +222 -126
  127. package/dist/Table/utils/functions.js +169 -144
  128. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  129. package/dist/TimelineGuide/index.js +209 -16
  130. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  131. package/dist/TopTable/index.js +340 -122
  132. package/dist/contexts/LabelsQueryProvider.js +94 -32
  133. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  134. package/dist/contexts/utils.js +37 -15
  135. package/dist/hooks/useCompareModeMeta.js +157 -94
  136. package/dist/hooks/useLabels.js +295 -52
  137. package/dist/hooks/useQueryState.js +371 -330
  138. package/dist/index.js +21 -16
  139. package/dist/testdata/fg-diff.json +3750 -0
  140. package/dist/testdata/fg-simple.json +1879 -0
  141. package/dist/testdata/link_data.json +56 -0
  142. package/dist/testdata/tabular.json +30 -0
  143. package/dist/testdata/test_flamegraph.json +26846 -0
  144. package/dist/testdata/test_graph.json +53 -0
  145. package/dist/useDelayedLoader.js +32 -18
  146. package/dist/useGrpcQuery/index.js +71 -11
  147. package/dist/useHasProfileData.js +90 -12
  148. package/dist/useQuery.js +205 -64
  149. package/dist/useSumBy.d.ts.map +1 -1
  150. package/dist/useSumBy.js +294 -138
  151. package/dist/utils.js +62 -30
  152. package/package.json +9 -9
  153. package/src/GraphTooltipArrow/index.tsx +3 -0
  154. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  155. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  156. package/src/MatchersInput/index.tsx +1 -1
  157. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  158. package/src/PreSelectedMatchers/index.tsx +3 -0
  159. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +3 -0
  160. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  161. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  162. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  163. package/src/ProfileSelector/index.tsx +30 -7
  164. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +3 -0
  165. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  166. package/src/Table/hooks/useTableConfiguration.tsx +7 -13
  167. package/src/useDelayedLoader.ts +10 -10
  168. package/src/useSumBy.ts +12 -18
  169. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -541
  170. package/dist/hooks/useQueryState.test.js +0 -984
@@ -1,3 +1,10 @@
1
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
2
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
8
  // Copyright 2022 The Parca Authors
2
9
  // Licensed under the Apache License, Version 2.0 (the "License");
3
10
  // you may not use this file except in compliance with the License.
@@ -10,135 +17,151 @@
10
17
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
18
  // See the License for the specific language governing permissions and
12
19
  // limitations under the License.
13
- import { BINARY_FEATURE_TYPES, EVERYTHING_ELSE, FILENAMES_FEATURE_TYPES, } from '@parca/store';
20
+
21
+ import { BINARY_FEATURE_TYPES, EVERYTHING_ELSE, FILENAMES_FEATURE_TYPES } from '@parca/store';
14
22
  import { divide, getLastItem, valueFormatter } from '@parca/utilities';
15
23
  import { MergedProfileSource } from '../../ProfileSource';
16
24
  import { hexifyAddress } from '../../utils';
17
- import { FIELD_DEPTH, FIELD_FUNCTION_NAME, FIELD_FUNCTION_START_LINE, FIELD_INLINED, FIELD_LABELS_ONLY, FIELD_LOCATION_ADDRESS, FIELD_MAPPING_FILE, } from './index';
25
+ import { FIELD_DEPTH, FIELD_FUNCTION_NAME, FIELD_FUNCTION_START_LINE, FIELD_INLINED, FIELD_LABELS_ONLY, FIELD_LOCATION_ADDRESS, FIELD_MAPPING_FILE } from './index';
18
26
  export function nodeLabel(table, row, showBinaryName) {
19
- const labelsOnly = table.getChild(FIELD_LABELS_ONLY)?.get(row);
20
- const depth = table.getChild(FIELD_DEPTH)?.get(row) ?? 0;
21
- if (depth === 1 && labelsOnly !== null && labelsOnly) {
22
- return getLabelSet(table, row);
23
- }
24
- const functionName = arrowToString(table.getChild(FIELD_FUNCTION_NAME)?.get(row));
25
- if (functionName !== null && functionName !== '') {
26
- return functionName;
27
- }
28
- let mappingString = '';
29
- if (showBinaryName) {
30
- const mappingFile = table.getChild(FIELD_MAPPING_FILE)?.get(row) ?? '';
31
- const binary = getLastItem(mappingFile ?? undefined);
32
- if (binary != null)
33
- mappingString = `[${binary}]`;
34
- }
35
- const addressBigInt = table.getChild(FIELD_LOCATION_ADDRESS)?.get(row);
36
- const address = hexifyAddress(addressBigInt);
37
- const fallback = `${mappingString}${address}`;
38
- return fallback === '' ? '<unknown>' : fallback;
27
+ var _table$getChild, _table$getChild$get, _table$getChild2, _table$getChild3, _table$getChild5;
28
+ var labelsOnly = (_table$getChild = table.getChild(FIELD_LABELS_ONLY)) === null || _table$getChild === void 0 ? void 0 : _table$getChild.get(row);
29
+ var depth = (_table$getChild$get = (_table$getChild2 = table.getChild(FIELD_DEPTH)) === null || _table$getChild2 === void 0 ? void 0 : _table$getChild2.get(row)) !== null && _table$getChild$get !== void 0 ? _table$getChild$get : 0;
30
+ if (depth === 1 && labelsOnly !== null && labelsOnly) {
31
+ return getLabelSet(table, row);
32
+ }
33
+ var functionName = arrowToString((_table$getChild3 = table.getChild(FIELD_FUNCTION_NAME)) === null || _table$getChild3 === void 0 ? void 0 : _table$getChild3.get(row));
34
+ if (functionName !== null && functionName !== '') {
35
+ return functionName;
36
+ }
37
+ var mappingString = '';
38
+ if (showBinaryName) {
39
+ var _table$getChild$get2, _table$getChild4;
40
+ var mappingFile = (_table$getChild$get2 = (_table$getChild4 = table.getChild(FIELD_MAPPING_FILE)) === null || _table$getChild4 === void 0 ? void 0 : _table$getChild4.get(row)) !== null && _table$getChild$get2 !== void 0 ? _table$getChild$get2 : '';
41
+ var binary = getLastItem(mappingFile !== null && mappingFile !== void 0 ? mappingFile : undefined);
42
+ if (binary != null) mappingString = "[".concat(binary, "]");
43
+ }
44
+ var addressBigInt = (_table$getChild5 = table.getChild(FIELD_LOCATION_ADDRESS)) === null || _table$getChild5 === void 0 ? void 0 : _table$getChild5.get(row);
45
+ var address = hexifyAddress(addressBigInt);
46
+ var fallback = "".concat(mappingString).concat(address);
47
+ return fallback === '' ? '<unknown>' : fallback;
39
48
  }
40
- export const extractFeature = (mapping) => {
41
- if (mapping != null && mapping !== '') {
42
- return { name: mapping, type: BINARY_FEATURE_TYPES.Binary };
43
- }
44
- return { name: EVERYTHING_ELSE, type: BINARY_FEATURE_TYPES.Misc };
49
+ export var extractFeature = function extractFeature(mapping) {
50
+ if (mapping != null && mapping !== '') {
51
+ return {
52
+ name: mapping,
53
+ type: BINARY_FEATURE_TYPES.Binary
54
+ };
55
+ }
56
+ return {
57
+ name: EVERYTHING_ELSE,
58
+ type: BINARY_FEATURE_TYPES.Misc
59
+ };
45
60
  };
46
- export const extractFilenameFeature = (filename) => {
47
- if (filename != null && filename !== '') {
48
- return { name: filename, type: FILENAMES_FEATURE_TYPES.Filename };
49
- }
50
- return { name: EVERYTHING_ELSE, type: FILENAMES_FEATURE_TYPES.Misc };
61
+ export var extractFilenameFeature = function extractFilenameFeature(filename) {
62
+ if (filename != null && filename !== '') {
63
+ return {
64
+ name: filename,
65
+ type: FILENAMES_FEATURE_TYPES.Filename
66
+ };
67
+ }
68
+ return {
69
+ name: EVERYTHING_ELSE,
70
+ type: FILENAMES_FEATURE_TYPES.Misc
71
+ };
51
72
  };
52
- export const getTextForCumulative = (hoveringNodeCumulative, totalUnfiltered, total, unit) => {
53
- const filtered = totalUnfiltered > total
54
- ? ` / ${(100 * divide(hoveringNodeCumulative, total)).toFixed(2)}% of filtered`
55
- : '';
56
- return `${valueFormatter(hoveringNodeCumulative, unit, 2)}
57
- (${(100 * divide(hoveringNodeCumulative, totalUnfiltered)).toFixed(2)}%${filtered})`;
73
+ export var getTextForCumulative = function getTextForCumulative(hoveringNodeCumulative, totalUnfiltered, total, unit) {
74
+ var filtered = totalUnfiltered > total ? " / ".concat((100 * divide(hoveringNodeCumulative, total)).toFixed(2), "% of filtered") : '';
75
+ return "".concat(valueFormatter(hoveringNodeCumulative, unit, 2), "\n (").concat((100 * divide(hoveringNodeCumulative, totalUnfiltered)).toFixed(2), "%").concat(filtered, ")");
58
76
  };
59
- export const getTextForCumulativePerSecond = (hoveringNodeCumulative, unit) => {
60
- return `${valueFormatter(hoveringNodeCumulative, unit === 'nanoseconds' ? 'CPU Cores' : unit, 5)}/s`;
77
+ export var getTextForCumulativePerSecond = function getTextForCumulativePerSecond(hoveringNodeCumulative, unit) {
78
+ return "".concat(valueFormatter(hoveringNodeCumulative, unit === 'nanoseconds' ? 'CPU Cores' : unit, 5), "/s");
61
79
  };
62
- export const arrowToString = (buffer) => {
63
- if (buffer == null || typeof buffer === 'string') {
64
- return buffer;
65
- }
66
- if (ArrayBuffer.isView(buffer)) {
67
- return new TextDecoder().decode(buffer);
68
- }
69
- return '';
80
+ export var arrowToString = function arrowToString(buffer) {
81
+ if (buffer == null || typeof buffer === 'string') {
82
+ return buffer;
83
+ }
84
+ if (ArrayBuffer.isView(buffer)) {
85
+ return new TextDecoder().decode(buffer);
86
+ }
87
+ return '';
70
88
  };
71
- export const boundsFromProfileSource = (profileSource) => {
72
- if (profileSource === undefined) {
73
- return [0n, 1n];
74
- }
75
- if (!(profileSource instanceof MergedProfileSource)) {
76
- return [0n, 1n];
77
- }
78
- const request = profileSource.QueryRequest();
79
- if (request.options.oneofKind !== 'merge' ||
80
- request.options.merge.start === undefined ||
81
- request.options.merge.end === undefined) {
82
- return [0n, 1n];
83
- }
84
- const start = request.options.merge.start.seconds * 1000000000n + BigInt(request.options.merge.start.nanos);
85
- const end = request.options.merge.end.seconds * 1000000000n + BigInt(request.options.merge.end.nanos);
86
- return [start, end];
89
+ export var boundsFromProfileSource = function boundsFromProfileSource(profileSource) {
90
+ if (profileSource === undefined) {
91
+ return [0n, 1n];
92
+ }
93
+ if (!(profileSource instanceof MergedProfileSource)) {
94
+ return [0n, 1n];
95
+ }
96
+ var request = profileSource.QueryRequest();
97
+ if (request.options.oneofKind !== 'merge' || request.options.merge.start === undefined || request.options.merge.end === undefined) {
98
+ return [0n, 1n];
99
+ }
100
+ var start = request.options.merge.start.seconds * 1000000000n + BigInt(request.options.merge.start.nanos);
101
+ var end = request.options.merge.end.seconds * 1000000000n + BigInt(request.options.merge.end.nanos);
102
+ return [start, end];
87
103
  };
88
- export const getCurrentPathFrameData = (table, row) => {
89
- const functionName = arrowToString(table.getChild(FIELD_FUNCTION_NAME)?.get(row));
90
- const systemName = arrowToString(table.getChild(FIELD_FUNCTION_NAME)?.get(row));
91
- const fileName = arrowToString(table.getChild(FIELD_MAPPING_FILE)?.get(row));
92
- const lineNumber = table.getChild(FIELD_FUNCTION_START_LINE)?.get(row) ?? 0n;
93
- const addressBigInt = table.getChild(FIELD_LOCATION_ADDRESS)?.get(row);
94
- const address = hexifyAddress(addressBigInt);
95
- const inlined = table.getChild(FIELD_INLINED)?.get(row);
96
- const labelsOnly = table.getChild(FIELD_LABELS_ONLY)?.get(row);
97
- const depth = table.getChild(FIELD_DEPTH)?.get(row) ?? 0;
98
- let labels;
99
- if (depth === 1 && labelsOnly !== null && labelsOnly) {
100
- labels = getLabelSet(table, row);
101
- }
102
- return {
103
- functionName: functionName ?? '',
104
- systemName: systemName ?? '',
105
- fileName: fileName ?? '',
106
- lineNumber: Number(lineNumber),
107
- address,
108
- inlined: inlined ?? false,
109
- labels: labels ?? undefined,
110
- };
104
+ export var getCurrentPathFrameData = function getCurrentPathFrameData(table, row) {
105
+ var _table$getChild6, _table$getChild7, _table$getChild8, _table$getChild$get3, _table$getChild9, _table$getChild0, _table$getChild1, _table$getChild10, _table$getChild$get4, _table$getChild11;
106
+ var functionName = arrowToString((_table$getChild6 = table.getChild(FIELD_FUNCTION_NAME)) === null || _table$getChild6 === void 0 ? void 0 : _table$getChild6.get(row));
107
+ var systemName = arrowToString((_table$getChild7 = table.getChild(FIELD_FUNCTION_NAME)) === null || _table$getChild7 === void 0 ? void 0 : _table$getChild7.get(row));
108
+ var fileName = arrowToString((_table$getChild8 = table.getChild(FIELD_MAPPING_FILE)) === null || _table$getChild8 === void 0 ? void 0 : _table$getChild8.get(row));
109
+ var lineNumber = (_table$getChild$get3 = (_table$getChild9 = table.getChild(FIELD_FUNCTION_START_LINE)) === null || _table$getChild9 === void 0 ? void 0 : _table$getChild9.get(row)) !== null && _table$getChild$get3 !== void 0 ? _table$getChild$get3 : 0n;
110
+ var addressBigInt = (_table$getChild0 = table.getChild(FIELD_LOCATION_ADDRESS)) === null || _table$getChild0 === void 0 ? void 0 : _table$getChild0.get(row);
111
+ var address = hexifyAddress(addressBigInt);
112
+ var inlined = (_table$getChild1 = table.getChild(FIELD_INLINED)) === null || _table$getChild1 === void 0 ? void 0 : _table$getChild1.get(row);
113
+ var labelsOnly = (_table$getChild10 = table.getChild(FIELD_LABELS_ONLY)) === null || _table$getChild10 === void 0 ? void 0 : _table$getChild10.get(row);
114
+ var depth = (_table$getChild$get4 = (_table$getChild11 = table.getChild(FIELD_DEPTH)) === null || _table$getChild11 === void 0 ? void 0 : _table$getChild11.get(row)) !== null && _table$getChild$get4 !== void 0 ? _table$getChild$get4 : 0;
115
+ var labels;
116
+ if (depth === 1 && labelsOnly !== null && labelsOnly) {
117
+ labels = getLabelSet(table, row);
118
+ }
119
+ return {
120
+ functionName: functionName !== null && functionName !== void 0 ? functionName : '',
121
+ systemName: systemName !== null && systemName !== void 0 ? systemName : '',
122
+ fileName: fileName !== null && fileName !== void 0 ? fileName : '',
123
+ lineNumber: Number(lineNumber),
124
+ address: address,
125
+ inlined: inlined !== null && inlined !== void 0 ? inlined : false,
126
+ labels: labels !== null && labels !== void 0 ? labels : undefined
127
+ };
111
128
  };
112
129
  function getLabelSet(table, row) {
113
- const labelPrefix = 'labels.';
114
- const labelColumnNames = table.schema.fields.filter(field => field.name.startsWith(labelPrefix));
115
- return labelColumnNames
116
- .map((field, i) => [
117
- labelColumnNames[i].name.slice(labelPrefix.length),
118
- arrowToString(table.getChild(field.name)?.get(row)) ?? '',
119
- ])
120
- .filter(value => value[1] !== '')
121
- .map(([k, v]) => `${k}="${v}"`)
122
- .join(', ');
130
+ var labelPrefix = 'labels.';
131
+ var labelColumnNames = table.schema.fields.filter(function (field) {
132
+ return field.name.startsWith(labelPrefix);
133
+ });
134
+ return labelColumnNames.map(function (field, i) {
135
+ var _arrowToString, _table$getChild12;
136
+ return [labelColumnNames[i].name.slice(labelPrefix.length), (_arrowToString = arrowToString((_table$getChild12 = table.getChild(field.name)) === null || _table$getChild12 === void 0 ? void 0 : _table$getChild12.get(row))) !== null && _arrowToString !== void 0 ? _arrowToString : ''];
137
+ }).filter(function (value) {
138
+ return value[1] !== '';
139
+ }).map(function (_ref) {
140
+ var _ref2 = _slicedToArray(_ref, 2),
141
+ k = _ref2[0],
142
+ v = _ref2[1];
143
+ return "".concat(k, "=\"").concat(v, "\"");
144
+ }).join(', ');
123
145
  }
124
146
  export function isCurrentPathFrameMatch(table, row, b) {
125
- const a = getCurrentPathFrameData(table, row);
126
- return (a.functionName === b.functionName &&
127
- a.systemName === b.systemName &&
128
- a.fileName === b.fileName &&
129
- a.lineNumber === b.lineNumber &&
130
- a.address === b.address &&
131
- a.inlined === b.inlined &&
132
- a.labels === b.labels);
147
+ var a = getCurrentPathFrameData(table, row);
148
+ return a.functionName === b.functionName && a.systemName === b.systemName && a.fileName === b.fileName && a.lineNumber === b.lineNumber && a.address === b.address && a.inlined === b.inlined && a.labels === b.labels;
133
149
  }
134
150
  export function getMaxDepth(depthColumn) {
135
- if (depthColumn === null)
136
- return 0;
137
- let max = 0;
138
- for (const val of depthColumn) {
139
- const numVal = Number(val);
140
- if (numVal > max)
141
- max = numVal;
151
+ if (depthColumn === null) return 0;
152
+ var max = 0;
153
+ var _iterator = _createForOfIteratorHelper(depthColumn),
154
+ _step;
155
+ try {
156
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
157
+ var val = _step.value;
158
+ var numVal = Number(val);
159
+ if (numVal > max) max = numVal;
142
160
  }
143
- return max;
144
- }
161
+ } catch (err) {
162
+ _iterator.e(err);
163
+ } finally {
164
+ _iterator.f();
165
+ }
166
+ return max;
167
+ }
@@ -0,0 +1,85 @@
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.FLAMEGRAPH_TABLE,
48
+ mode: client.QueryRequest_Mode.MERGE,
49
+ });
50
+ if (response.report.oneofKind !== 'flamegraph') {
51
+ throw new Error('Expected flamegraph report');
52
+ }
53
+ await writeToFile(response.report.flamegraph, 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-1m.json'),
72
+ populateDataIfNeeded(new Date(new Date().getTime() - 1000 * 60 * 10), 'parca-10m.json'),
73
+ populateDataIfNeeded(new Date(new Date().getTime() - 1000 * 60 * 20), 'parca-20m.json'),
74
+ ]);
75
+ };
76
+
77
+ run()
78
+ .then(() => {
79
+ console.log('done');
80
+ process.exit(0);
81
+ })
82
+ .catch(err => {
83
+ console.error('Error:', err);
84
+ process.exit(1);
85
+ });