@parca/profile 0.19.140 → 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 (253) hide show
  1. package/CHANGELOG.md +5 -1
  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.d.ts.map +1 -1
  9. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +104 -72
  10. package/dist/MatchersInput/SuggestionItem.js +91 -12
  11. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  12. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  13. package/dist/MatchersInput/SuggestionsList.js +371 -157
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  15. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  16. package/dist/MatchersInput/index.js +308 -115
  17. package/dist/MetricsCircle/index.js +39 -3
  18. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  19. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  20. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  21. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  22. package/dist/MetricsGraph/index.js +552 -203
  23. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  24. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  25. package/dist/MetricsSeries/index.js +70 -7
  26. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  27. package/dist/PreSelectedMatchers/index.js +249 -102
  28. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
  29. package/dist/ProfileExplorer/ProfileExplorerCompare.js +241 -45
  30. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  31. package/dist/ProfileExplorer/index.js +183 -32
  32. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  33. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  34. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
  35. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
  36. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  37. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  38. package/dist/ProfileFlameChart/index.d.ts.map +1 -1
  39. package/dist/ProfileFlameChart/index.js +267 -129
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +288 -89
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +72 -47
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  55. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  56. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  57. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  58. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  59. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  60. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  61. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  62. package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
  63. package/dist/ProfileFlameGraph/index.js +324 -150
  64. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  65. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  66. package/dist/ProfileMetricsGraph/index.js +519 -258
  67. package/dist/ProfileSelector/CompareButton.js +132 -12
  68. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  69. package/dist/ProfileSelector/MetricsGraphSection.js +236 -64
  70. package/dist/ProfileSelector/index.d.ts.map +1 -1
  71. package/dist/ProfileSelector/index.js +727 -141
  72. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  73. package/dist/ProfileSource.js +230 -163
  74. package/dist/ProfileTypeSelector/index.js +214 -125
  75. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  76. package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
  77. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +141 -35
  78. package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
  79. package/dist/ProfileView/components/ColorStackLegend.js +185 -55
  80. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  81. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  82. package/dist/ProfileView/components/DiffLegend.js +172 -29
  83. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  84. package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
  85. package/dist/ProfileView/components/InvertCallStack/index.js +100 -12
  86. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  87. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  88. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  89. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +2 -1
  90. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
  91. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -118
  92. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  93. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  94. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  95. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  96. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +678 -194
  97. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  98. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
  99. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +199 -157
  100. package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
  101. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  102. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  103. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  104. package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
  105. package/dist/ProfileView/components/ViewSelector/index.js +212 -86
  106. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  107. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  108. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  109. package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
  110. package/dist/ProfileView/context/DashboardContext.js +85 -29
  111. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  112. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  113. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  114. package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
  115. package/dist/ProfileView/hooks/useResetFlameGraphState.js +32 -12
  116. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
  117. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +71 -27
  118. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
  119. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +40 -19
  120. package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
  121. package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
  122. package/dist/ProfileView/hooks/useVisualizationState.js +258 -67
  123. package/dist/ProfileView/index.js +383 -45
  124. package/dist/ProfileView/types/visualization.js +1 -13
  125. package/dist/ProfileView/utils/colorUtils.js +8 -7
  126. package/dist/ProfileViewWithData.d.ts.map +1 -1
  127. package/dist/ProfileViewWithData.js +332 -228
  128. package/dist/QueryControls/index.js +418 -47
  129. package/dist/Sandwich/components/CalleesSection.js +54 -4
  130. package/dist/Sandwich/components/CallersSection.js +97 -27
  131. package/dist/Sandwich/components/TableSection.js +77 -4
  132. package/dist/Sandwich/index.d.ts.map +1 -1
  133. package/dist/Sandwich/index.js +126 -14
  134. package/dist/Sandwich/utils/processRowData.js +48 -39
  135. package/dist/SelectWithRefresh/index.js +102 -28
  136. package/dist/SimpleMatchers/Select.js +520 -187
  137. package/dist/SimpleMatchers/index.js +590 -288
  138. package/dist/SourceView/Highlighter.js +230 -70
  139. package/dist/SourceView/LineNo.js +72 -17
  140. package/dist/SourceView/index.d.ts.map +1 -1
  141. package/dist/SourceView/index.js +178 -104
  142. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  143. package/dist/SourceView/lang-detector/index.js +28 -14
  144. package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
  145. package/dist/SourceView/useSelectedLineRange.js +99 -23
  146. package/dist/Table/ColorCell.js +42 -1
  147. package/dist/Table/ColumnsVisibility.js +114 -6
  148. package/dist/Table/MoreDropdown.d.ts.map +1 -1
  149. package/dist/Table/MoreDropdown.js +122 -25
  150. package/dist/Table/TableContextMenu.d.ts.map +1 -1
  151. package/dist/Table/TableContextMenu.js +151 -137
  152. package/dist/Table/TableContextMenuWrapper.js +59 -14
  153. package/dist/Table/hooks/useColorManagement.js +58 -16
  154. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  155. package/dist/Table/hooks/useTableConfiguration.js +333 -169
  156. package/dist/Table/index.d.ts.map +1 -1
  157. package/dist/Table/index.js +222 -128
  158. package/dist/Table/utils/functions.js +169 -144
  159. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  160. package/dist/TimelineGuide/index.js +209 -16
  161. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  162. package/dist/TopTable/index.d.ts.map +1 -1
  163. package/dist/TopTable/index.js +342 -123
  164. package/dist/contexts/LabelsQueryProvider.js +94 -32
  165. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  166. package/dist/contexts/utils.js +37 -15
  167. package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
  168. package/dist/hooks/useCompareModeMeta.js +158 -64
  169. package/dist/hooks/useLabels.js +295 -52
  170. package/dist/hooks/useQueryState.d.ts +3 -3
  171. package/dist/hooks/useQueryState.d.ts.map +1 -1
  172. package/dist/hooks/useQueryState.js +373 -332
  173. package/dist/index.d.ts +2 -3
  174. package/dist/index.d.ts.map +1 -1
  175. package/dist/index.js +22 -8
  176. package/dist/testdata/fg-diff.json +3750 -0
  177. package/dist/testdata/fg-simple.json +1879 -0
  178. package/dist/testdata/link_data.json +56 -0
  179. package/dist/testdata/tabular.json +30 -0
  180. package/dist/testdata/test_flamegraph.json +26846 -0
  181. package/dist/testdata/test_graph.json +53 -0
  182. package/dist/useDelayedLoader.js +32 -18
  183. package/dist/useGrpcQuery/index.js +71 -11
  184. package/dist/useHasProfileData.js +90 -12
  185. package/dist/useQuery.js +205 -64
  186. package/dist/useSumBy.d.ts +1 -1
  187. package/dist/useSumBy.d.ts.map +1 -1
  188. package/dist/useSumBy.js +294 -138
  189. package/dist/utils.js +62 -30
  190. package/package.json +9 -10
  191. package/src/GraphTooltipArrow/index.tsx +3 -0
  192. package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +13 -11
  193. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  194. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  195. package/src/MatchersInput/index.tsx +1 -1
  196. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  197. package/src/PreSelectedMatchers/index.tsx +3 -0
  198. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +9 -4
  199. package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
  200. package/src/ProfileFlameChart/index.tsx +28 -21
  201. package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +9 -10
  202. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +6 -5
  203. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  204. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  205. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  206. package/src/ProfileFlameGraph/index.tsx +9 -6
  207. package/src/ProfileMetricsGraph/index.tsx +8 -6
  208. package/src/ProfileSelector/MetricsGraphSection.tsx +10 -5
  209. package/src/ProfileSelector/index.tsx +61 -39
  210. package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +6 -10
  211. package/src/ProfileView/components/ColorStackLegend.tsx +4 -2
  212. package/src/ProfileView/components/InvertCallStack/index.tsx +4 -5
  213. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +192 -94
  214. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
  215. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +28 -24
  216. package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +5 -4
  217. package/src/ProfileView/components/Toolbars/index.tsx +3 -3
  218. package/src/ProfileView/components/ViewSelector/index.tsx +16 -9
  219. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  220. package/src/ProfileView/context/DashboardContext.tsx +6 -6
  221. package/src/ProfileView/hooks/useResetFlameGraphState.ts +4 -6
  222. package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +26 -24
  223. package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +8 -16
  224. package/src/ProfileView/hooks/useVisualizationState.ts +69 -61
  225. package/src/ProfileViewWithData.tsx +35 -29
  226. package/src/Sandwich/index.tsx +3 -4
  227. package/src/SourceView/index.tsx +2 -4
  228. package/src/SourceView/useSelectedLineRange.ts +19 -34
  229. package/src/Table/MoreDropdown.tsx +11 -9
  230. package/src/Table/TableContextMenu.tsx +13 -10
  231. package/src/Table/hooks/useTableConfiguration.tsx +11 -16
  232. package/src/Table/index.tsx +21 -12
  233. package/src/TopTable/index.tsx +4 -3
  234. package/src/hooks/useCompareModeMeta.ts +91 -61
  235. package/src/hooks/useQueryState.test.tsx +345 -275
  236. package/src/hooks/useQueryState.ts +118 -136
  237. package/src/index.tsx +15 -16
  238. package/src/useDelayedLoader.ts +10 -10
  239. package/src/useSumBy.ts +15 -21
  240. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -455
  241. package/dist/hooks/urlParsers.d.ts +0 -18
  242. package/dist/hooks/urlParsers.d.ts.map +0 -1
  243. package/dist/hooks/urlParsers.js +0 -32
  244. package/dist/hooks/useColorBy.d.ts +0 -5
  245. package/dist/hooks/useColorBy.d.ts.map +0 -1
  246. package/dist/hooks/useColorBy.js +0 -26
  247. package/dist/hooks/useDashboardItems.d.ts +0 -5
  248. package/dist/hooks/useDashboardItems.d.ts.map +0 -1
  249. package/dist/hooks/useDashboardItems.js +0 -27
  250. package/dist/hooks/useQueryState.test.js +0 -868
  251. package/src/hooks/urlParsers.ts +0 -38
  252. package/src/hooks/useColorBy.ts +0 -42
  253. package/src/hooks/useDashboardItems.ts +0 -46
@@ -1,4 +1,16 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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; } }
10
+ 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; }
11
+ 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; } }
12
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
+ import { c as _c } from "react-compiler-runtime";
2
14
  // Copyright 2022 The Parca Authors
3
15
  // Licensed under the Apache License, Version 2.0 (the "License");
4
16
  // you may not use this file except in compliance with the License.
@@ -11,283 +23,532 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
11
23
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
24
  // See the License for the specific language governing permissions and
13
25
  // limitations under the License.
26
+
14
27
  import { useEffect, useMemo, useState } from 'react';
15
28
  import { Icon } from '@iconify/react';
16
29
  import { AnimatePresence, motion } from 'framer-motion';
17
- import { useQueryState } from 'nuqs';
18
- import { MetricsGraphSkeleton, TextWithTooltip, useParcaContext, } from '@parca/components';
30
+ import { MetricsGraphSkeleton, NumberParser, NumberSerializer, TextWithTooltip, useParcaContext, useURLStateCustom } from '@parca/components';
19
31
  import { Query } from '@parca/parser';
20
32
  import { TEST_IDS, testId } from '@parca/test-utils';
21
33
  import { capitalizeOnlyFirstLetter, formatDate, timePattern, valueFormatter } from '@parca/utilities';
22
34
  import { MergedProfileSelection } from '..';
23
35
  import MetricsGraph from '../MetricsGraph';
24
36
  import { useMetricsGraphDimensions } from '../MetricsGraph/useMetricsGraphDimensions';
25
- import { intParam } from '../hooks/urlParsers';
26
37
  import { getStepCountFromScreenWidth, useQueryRange } from './hooks/useQueryRange';
27
- const createProfileContextMenuItems = (addLabelMatcher, data // The original MetricsSeriesPb[] data
28
- ) => {
29
- return [
30
- {
31
- id: 'focus-on-single-series',
32
- label: 'Focus only on this series',
33
- icon: 'ph:star',
34
- onClick: (closestPoint, _series) => {
35
- if (closestPoint != null && data.length > 0 && data[closestPoint.seriesIndex] != null) {
36
- const originalSeriesData = data[closestPoint.seriesIndex];
37
- if (originalSeriesData.labelset?.labels != null) {
38
- const labels = originalSeriesData.labelset.labels.filter((label) => label.name !== '__name__');
39
- const labelsToAdd = labels.map((label) => ({
40
- key: label.name,
41
- value: label.value,
42
- }));
43
- addLabelMatcher(labelsToAdd);
44
- }
45
- }
46
- },
47
- },
48
- {
49
- id: 'add-to-query',
50
- label: 'Add to query',
51
- icon: 'material-symbols:add',
52
- createDynamicItems: (closestPoint, _series) => {
53
- const noLabelsAvailable = [
54
- {
55
- id: 'no-labels-available',
56
- label: 'No labels available',
57
- icon: 'ph:warning',
58
- disabled: () => true,
59
- onClick: () => { }, // No-op for disabled item
60
- },
61
- ];
62
- if (closestPoint == null || data.length === 0 || data[closestPoint.seriesIndex] == null) {
63
- return noLabelsAvailable;
64
- }
65
- const originalSeriesData = data[closestPoint.seriesIndex];
66
- if (originalSeriesData.labelset?.labels == null) {
67
- return noLabelsAvailable;
68
- }
69
- const labels = originalSeriesData.labelset.labels.filter((label) => label.name !== '__name__');
70
- if (labels.length === 0) {
71
- return noLabelsAvailable;
72
- }
73
- return labels.map((label) => ({
74
- id: `add-label-${label.name}`,
75
- label: (_jsx("div", { className: "mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-300", children: `${label.name}="${label.value}"` })),
76
- onClick: () => {
77
- addLabelMatcher({
78
- key: label.name,
79
- value: label.value,
80
- });
81
- },
82
- }));
83
- },
38
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
39
+ var createProfileContextMenuItems = function createProfileContextMenuItems(addLabelMatcher, data) {
40
+ return [{
41
+ id: 'focus-on-single-series',
42
+ label: 'Focus only on this series',
43
+ icon: 'ph:star',
44
+ onClick: function onClick(closestPoint, _series) {
45
+ if (closestPoint != null && data.length > 0 && data[closestPoint.seriesIndex] != null) {
46
+ var _originalSeriesData$l;
47
+ var originalSeriesData = data[closestPoint.seriesIndex];
48
+ if (((_originalSeriesData$l = originalSeriesData.labelset) === null || _originalSeriesData$l === void 0 ? void 0 : _originalSeriesData$l.labels) != null) {
49
+ var labels = originalSeriesData.labelset.labels.filter(function (label) {
50
+ return label.name !== '__name__';
51
+ });
52
+ var labelsToAdd = labels.map(function (label) {
53
+ return {
54
+ key: label.name,
55
+ value: label.value
56
+ };
57
+ });
58
+ addLabelMatcher(labelsToAdd);
59
+ }
60
+ }
61
+ }
62
+ }, {
63
+ id: 'add-to-query',
64
+ label: 'Add to query',
65
+ icon: 'material-symbols:add',
66
+ createDynamicItems: function createDynamicItems(closestPoint, _series) {
67
+ var _originalSeriesData$l2;
68
+ var noLabelsAvailable = [{
69
+ id: 'no-labels-available',
70
+ label: 'No labels available',
71
+ icon: 'ph:warning',
72
+ disabled: function disabled() {
73
+ return true;
84
74
  },
85
- ];
86
- };
87
- const transformMetricsData = (data) => {
88
- const series = data.reduce((agg, s) => {
89
- if (s.labelset !== undefined) {
90
- // Generate ID from sorted labelsets
91
- const labels = s.labelset.labels ?? [];
92
- const sortedLabels = labels
93
- .filter(label => label.name !== '__name__') // Exclude __name__ from ID generation
94
- .sort((a, b) => a.name.localeCompare(b.name));
95
- const id = sortedLabels.map(label => `${label.name}=${label.value}`).join(',');
96
- agg.push({
97
- id: id !== '' ? id : 'default', // fallback to 'default' if no labels
98
- values: s.samples.reduce((agg, d) => {
99
- if (d.timestamp !== undefined && d.valuePerSecond !== undefined) {
100
- const timestampMs = Number(d.timestamp.seconds) * 1000 + d.timestamp.nanos / 1000000;
101
- agg.push([timestampMs, d.valuePerSecond]);
102
- }
103
- return agg;
104
- }, []),
75
+ onClick: function onClick() {} // No-op for disabled item
76
+ }];
77
+ if (closestPoint == null || data.length === 0 || data[closestPoint.seriesIndex] == null) {
78
+ return noLabelsAvailable;
79
+ }
80
+ var originalSeriesData = data[closestPoint.seriesIndex];
81
+ if (((_originalSeriesData$l2 = originalSeriesData.labelset) === null || _originalSeriesData$l2 === void 0 ? void 0 : _originalSeriesData$l2.labels) == null) {
82
+ return noLabelsAvailable;
83
+ }
84
+ var labels = originalSeriesData.labelset.labels.filter(function (label) {
85
+ return label.name !== '__name__';
86
+ });
87
+ if (labels.length === 0) {
88
+ return noLabelsAvailable;
89
+ }
90
+ return labels.map(function (label) {
91
+ return {
92
+ id: "add-label-".concat(label.name),
93
+ label: /*#__PURE__*/_jsx("div", {
94
+ className: "mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-300",
95
+ children: "".concat(label.name, "=\"").concat(label.value, "\"")
96
+ }),
97
+ onClick: function onClick() {
98
+ addLabelMatcher({
99
+ key: label.name,
100
+ value: label.value
105
101
  });
106
- }
107
- return agg;
108
- }, []);
109
- return series;
102
+ }
103
+ };
104
+ });
105
+ }
106
+ }];
107
+ };
108
+ var transformMetricsData = function transformMetricsData(data) {
109
+ var series = data.reduce(function (agg, s) {
110
+ if (s.labelset !== undefined) {
111
+ var _s$labelset$labels;
112
+ // Generate ID from sorted labelsets
113
+ var labels = (_s$labelset$labels = s.labelset.labels) !== null && _s$labelset$labels !== void 0 ? _s$labelset$labels : [];
114
+ var sortedLabels = labels.filter(function (label) {
115
+ return label.name !== '__name__';
116
+ }) // Exclude __name__ from ID generation
117
+ .sort(function (a, b) {
118
+ return a.name.localeCompare(b.name);
119
+ });
120
+ var id = sortedLabels.map(function (label) {
121
+ return "".concat(label.name, "=").concat(label.value);
122
+ }).join(',');
123
+ agg.push({
124
+ id: id !== '' ? id : 'default',
125
+ // fallback to 'default' if no labels
126
+ values: s.samples.reduce(function (agg, d) {
127
+ if (d.timestamp !== undefined && d.valuePerSecond !== undefined) {
128
+ var timestampMs = Number(d.timestamp.seconds) * 1000 + d.timestamp.nanos / 1000000;
129
+ agg.push([timestampMs, d.valuePerSecond]);
130
+ }
131
+ return agg;
132
+ }, [])
133
+ });
134
+ }
135
+ return agg;
136
+ }, []);
137
+ return series;
110
138
  };
111
- const ErrorContent = ({ errorMessage }) => {
112
- return (_jsx("div", { className: "relative rounded border border-red-400 bg-red-100 px-4 py-3 text-red-700", role: "alert", children: _jsx("span", { className: "block sm:inline", children: errorMessage }) }));
139
+ var ErrorContent = function ErrorContent(t0) {
140
+ var $ = _c(2);
141
+ var errorMessage = t0.errorMessage;
142
+ var t1;
143
+ if ($[0] !== errorMessage) {
144
+ t1 = /*#__PURE__*/_jsx("div", {
145
+ className: "relative rounded border border-red-400 bg-red-100 px-4 py-3 text-red-700",
146
+ role: "alert",
147
+ children: /*#__PURE__*/_jsx("span", {
148
+ className: "block sm:inline",
149
+ children: errorMessage
150
+ })
151
+ });
152
+ $[0] = errorMessage;
153
+ $[1] = t1;
154
+ } else {
155
+ t1 = $[1];
156
+ }
157
+ return t1;
113
158
  };
114
- export const ProfileMetricsEmptyState = ({ message }) => {
115
- return (_jsx("div", { className: "flex h-full w-full flex-col items-center justify-center", children: _jsx("p", { children: message }) }));
159
+ export var ProfileMetricsEmptyState = function ProfileMetricsEmptyState(t0) {
160
+ var $ = _c(2);
161
+ var message = t0.message;
162
+ var t1;
163
+ if ($[0] !== message) {
164
+ t1 = /*#__PURE__*/_jsx("div", {
165
+ className: "flex h-full w-full flex-col items-center justify-center",
166
+ children: /*#__PURE__*/_jsx("p", {
167
+ children: message
168
+ })
169
+ });
170
+ $[0] = message;
171
+ $[1] = t1;
172
+ } else {
173
+ t1 = $[1];
174
+ }
175
+ return t1;
116
176
  };
117
- const ProfileMetricsGraph = ({ queryClient, queryExpression, profile, from, to, setTimeRange, addLabelMatcher, onPointClick, comparing = false, sumBy, }) => {
118
- const [rawStepCount] = useQueryState('step_count', intParam.withDefault(getStepCountFromScreenWidth(10)));
119
- // Clamp step count so the step duration is at least 1 second as we don't have this enforced server-side anymore.
120
- const stepCount = useMemo(() => {
121
- const maxForOneSecond = Math.floor((to - from) / 1000);
122
- return Math.min(rawStepCount, maxForOneSecond);
123
- }, [rawStepCount, from, to]);
124
- const { isLoading: metricsGraphLoading, response, error, } = useQueryRange(queryClient, queryExpression, from, to, sumBy, stepCount, queryExpression === '');
125
- const { onError, perf, authenticationErrorMessage, isDarkMode, timezone, profileExplorer } = useParcaContext();
126
- const { width, height, margin, heightStyle } = useMetricsGraphDimensions(comparing, profileExplorer?.metricsGraph.height);
127
- const [showAllSeriesForResponse, setShowAllSeriesForResponse] = useState(null);
128
- useEffect(() => {
129
- if (error !== null) {
130
- onError?.(error);
177
+ var ProfileMetricsGraph = function ProfileMetricsGraph(_ref) {
178
+ var queryClient = _ref.queryClient,
179
+ queryExpression = _ref.queryExpression,
180
+ profile = _ref.profile,
181
+ from = _ref.from,
182
+ to = _ref.to,
183
+ setTimeRange = _ref.setTimeRange,
184
+ addLabelMatcher = _ref.addLabelMatcher,
185
+ onPointClick = _ref.onPointClick,
186
+ _ref$comparing = _ref.comparing,
187
+ comparing = _ref$comparing === void 0 ? false : _ref$comparing,
188
+ sumBy = _ref.sumBy;
189
+ var _useURLStateCustom = useURLStateCustom('step_count', {
190
+ defaultValue: String(getStepCountFromScreenWidth(10)),
191
+ parse: NumberParser,
192
+ stringify: NumberSerializer
193
+ }),
194
+ _useURLStateCustom2 = _slicedToArray(_useURLStateCustom, 1),
195
+ rawStepCount = _useURLStateCustom2[0];
196
+ // Clamp step count so the step duration is at least 1 second as we don't have this enforced server-side anymore.
197
+ var stepCount = useMemo(function () {
198
+ var maxForOneSecond = Math.floor((to - from) / 1000);
199
+ return Math.min(rawStepCount, maxForOneSecond);
200
+ }, [rawStepCount, from, to]);
201
+ var _useQueryRange = useQueryRange(queryClient, queryExpression, from, to, sumBy, stepCount, queryExpression === ''),
202
+ metricsGraphLoading = _useQueryRange.isLoading,
203
+ response = _useQueryRange.response,
204
+ error = _useQueryRange.error;
205
+ var _useParcaContext = useParcaContext(),
206
+ onError = _useParcaContext.onError,
207
+ perf = _useParcaContext.perf,
208
+ authenticationErrorMessage = _useParcaContext.authenticationErrorMessage,
209
+ isDarkMode = _useParcaContext.isDarkMode,
210
+ timezone = _useParcaContext.timezone,
211
+ profileExplorer = _useParcaContext.profileExplorer;
212
+ var _useMetricsGraphDimen = useMetricsGraphDimensions(comparing, profileExplorer === null || profileExplorer === void 0 ? void 0 : profileExplorer.metricsGraph.height),
213
+ width = _useMetricsGraphDimen.width,
214
+ height = _useMetricsGraphDimen.height,
215
+ margin = _useMetricsGraphDimen.margin,
216
+ heightStyle = _useMetricsGraphDimen.heightStyle;
217
+ var _useState = useState(null),
218
+ _useState2 = _slicedToArray(_useState, 2),
219
+ showAllSeriesForResponse = _useState2[0],
220
+ setShowAllSeriesForResponse = _useState2[1];
221
+ useEffect(function () {
222
+ if (error !== null) {
223
+ onError === null || onError === void 0 || onError(error);
224
+ }
225
+ }, [error, onError]);
226
+
227
+ // Reset showAllSeriesForResponse when response changes to free memory
228
+ useEffect(function () {
229
+ setShowAllSeriesForResponse(null);
230
+ }, [response]);
231
+ useEffect(function () {
232
+ if (response === null) {
233
+ return;
234
+ }
235
+ perf === null || perf === void 0 || perf.markInteraction('Metrics graph render', response.series[0].samples.length);
236
+ }, [perf, response]);
237
+ var _useMemo = useMemo(function () {
238
+ if ((response === null || response === void 0 ? void 0 : response.series) != null) {
239
+ // Check if user wants ALL series for THIS specific response
240
+ var userWantsAllForThisResponse = showAllSeriesForResponse === response;
241
+ var maxSeriesLimit = 100;
242
+
243
+ // Limit the number of series to maxSeriesLimit to avoid performance issues (unless user opts to show all)
244
+ if (response.series.length > maxSeriesLimit && !userWantsAllForThisResponse) {
245
+ // Select top `maxSeriesLimit` series based on their max value (to catch series with large spikes)
246
+ var seriesWithMaxValue = response.series.map(function (series) {
247
+ var maxValue = series.samples.reduce(function (max, sample) {
248
+ var _sample$valuePerSecon;
249
+ var value = (_sample$valuePerSecon = sample.valuePerSecond) !== null && _sample$valuePerSecon !== void 0 ? _sample$valuePerSecon : 0;
250
+ return value > max ? value : max;
251
+ }, 0);
252
+ return {
253
+ series: series,
254
+ maxValue: maxValue
255
+ };
256
+ });
257
+
258
+ // Sort by max value descending and take top `maxSeriesLimit` series
259
+ var topSeries = seriesWithMaxValue.sort(function (a, b) {
260
+ return b.maxValue - a.maxValue;
261
+ }).slice(0, maxSeriesLimit).map(function (item) {
262
+ return item.series;
263
+ });
264
+ return [topSeries, {
265
+ isTrimmed: true,
266
+ beforeTrim: response.series.length,
267
+ afterTrim: maxSeriesLimit
268
+ }];
131
269
  }
132
- }, [error, onError]);
133
- // Reset showAllSeriesForResponse when response changes to free memory
134
- useEffect(() => {
135
- setShowAllSeriesForResponse(null);
136
- }, [response]);
137
- useEffect(() => {
138
- if (response === null) {
139
- return;
270
+ return [response.series, {
271
+ isTrimmed: false,
272
+ beforeTrim: 0,
273
+ afterTrim: 0
274
+ }];
275
+ }
276
+ return [null, {
277
+ isTrimmed: false,
278
+ beforeTrim: 0,
279
+ afterTrim: 0
280
+ }];
281
+ }, [response, showAllSeriesForResponse]),
282
+ _useMemo2 = _slicedToArray(_useMemo, 2),
283
+ originalSeries = _useMemo2[0],
284
+ _useMemo2$ = _useMemo2[1],
285
+ isTrimmed = _useMemo2$.isTrimmed,
286
+ beforeTrim = _useMemo2$.beforeTrim,
287
+ afterTrim = _useMemo2$.afterTrim;
288
+ var selectedPoint = useMemo(function () {
289
+ if (profile !== null && profile instanceof MergedProfileSelection) {
290
+ // Iterate over the series and find the series index that matches all
291
+ // labels of the profile selection. We specifically need the index
292
+ // because that's what the SeriesPoint interface expects.
293
+ var seriesIndex = originalSeries === null || originalSeries === void 0 ? void 0 : originalSeries.findIndex(function (s) {
294
+ var _s$labelset;
295
+ return (_s$labelset = s.labelset) === null || _s$labelset === void 0 || (_s$labelset = _s$labelset.labels) === null || _s$labelset === void 0 ? void 0 : _s$labelset.every(function (label) {
296
+ return profile.query.matchers.some(function (matcher) {
297
+ return matcher.key === label.name && matcher.value === label.value;
298
+ });
299
+ });
300
+ });
301
+
302
+ // if we found a series, return the point that matches the from/to timestamp exactly (in millisecond precision)
303
+ if (seriesIndex !== undefined && seriesIndex !== -1 && originalSeries != null && originalSeries[seriesIndex] != null) {
304
+ var series_0 = originalSeries[seriesIndex];
305
+ var pointIndex = series_0.samples.findIndex(function (sample_0) {
306
+ var _sample_0$timestamp, _sample_0$timestamp2;
307
+ return ((_sample_0$timestamp = sample_0.timestamp) === null || _sample_0$timestamp === void 0 ? void 0 : _sample_0$timestamp.seconds) === BigInt(profile.mergeFrom / 1000000000n) && ((_sample_0$timestamp2 = sample_0.timestamp) === null || _sample_0$timestamp2 === void 0 ? void 0 : _sample_0$timestamp2.nanos) === Number(profile.mergeFrom % 1000000000n);
308
+ });
309
+ if (pointIndex !== -1) {
310
+ return {
311
+ seriesIndex: seriesIndex,
312
+ pointIndex: pointIndex
313
+ };
140
314
  }
141
- perf?.markInteraction('Metrics graph render', response.series[0].samples.length);
142
- }, [perf, response]);
143
- const [originalSeries, { isTrimmed, beforeTrim, afterTrim }] = useMemo(() => {
144
- if (response?.series != null) {
145
- // Check if user wants ALL series for THIS specific response
146
- const userWantsAllForThisResponse = showAllSeriesForResponse === response;
147
- const maxSeriesLimit = 100;
148
- // Limit the number of series to maxSeriesLimit to avoid performance issues (unless user opts to show all)
149
- if (response.series.length > maxSeriesLimit && !userWantsAllForThisResponse) {
150
- // Select top `maxSeriesLimit` series based on their max value (to catch series with large spikes)
151
- const seriesWithMaxValue = response.series.map(series => {
152
- const maxValue = series.samples.reduce((max, sample) => {
153
- const value = sample.valuePerSecond ?? 0;
154
- return value > max ? value : max;
155
- }, 0);
156
- return { series, maxValue };
157
- });
158
- // Sort by max value descending and take top `maxSeriesLimit` series
159
- const topSeries = seriesWithMaxValue
160
- .sort((a, b) => b.maxValue - a.maxValue)
161
- .slice(0, maxSeriesLimit)
162
- .map(item => item.series);
163
- return [
164
- topSeries,
165
- { isTrimmed: true, beforeTrim: response.series.length, afterTrim: maxSeriesLimit },
166
- ];
167
- }
168
- return [response.series, { isTrimmed: false, beforeTrim: 0, afterTrim: 0 }];
169
- }
170
- return [null, { isTrimmed: false, beforeTrim: 0, afterTrim: 0 }];
171
- }, [response, showAllSeriesForResponse]);
172
- const selectedPoint = useMemo(() => {
173
- if (profile !== null && profile instanceof MergedProfileSelection) {
174
- // Iterate over the series and find the series index that matches all
175
- // labels of the profile selection. We specifically need the index
176
- // because that's what the SeriesPoint interface expects.
177
- const seriesIndex = originalSeries?.findIndex(s => {
178
- return s.labelset?.labels?.every(label => {
179
- return profile.query.matchers.some(matcher => {
180
- return matcher.key === label.name && matcher.value === label.value;
181
- });
182
- });
183
- });
184
- // if we found a series, return the point that matches the from/to timestamp exactly (in millisecond precision)
185
- if (seriesIndex !== undefined &&
186
- seriesIndex !== -1 &&
187
- originalSeries != null &&
188
- originalSeries[seriesIndex] != null) {
189
- const series = originalSeries[seriesIndex];
190
- const pointIndex = series.samples.findIndex(sample => {
191
- return (sample.timestamp?.seconds === BigInt(profile.mergeFrom / 1000000000n) &&
192
- sample.timestamp?.nanos === Number(profile.mergeFrom % 1000000000n));
193
- });
194
- if (pointIndex !== -1) {
195
- return {
196
- seriesIndex,
197
- pointIndex,
198
- };
199
- }
200
- }
201
- return null;
315
+ }
316
+ return null;
317
+ }
318
+ return null;
319
+ }, [profile, originalSeries]);
320
+ var transformedSeries = useMemo(function () {
321
+ return originalSeries != null ? transformMetricsData(originalSeries) : [];
322
+ }, [originalSeries]);
323
+ var contextMenuItems = useMemo(function () {
324
+ return originalSeries != null ? createProfileContextMenuItems(addLabelMatcher, originalSeries) : [];
325
+ }, [originalSeries, addLabelMatcher]);
326
+ var dataAvailable = originalSeries !== null && originalSeries !== undefined && (originalSeries === null || originalSeries === void 0 ? void 0 : originalSeries.length) > 0;
327
+ var _useMemo3 = useMemo(function () {
328
+ var sampleUnit = '';
329
+ var sampleType = '';
330
+ if (dataAvailable) {
331
+ if (originalSeries !== null && originalSeries !== void 0 && originalSeries.every(function (val, i, arr) {
332
+ var _val$sampleType, _arr$;
333
+ return (val === null || val === void 0 || (_val$sampleType = val.sampleType) === null || _val$sampleType === void 0 ? void 0 : _val$sampleType.unit) === ((_arr$ = arr[0]) === null || _arr$ === void 0 || (_arr$ = _arr$.sampleType) === null || _arr$ === void 0 ? void 0 : _arr$.unit);
334
+ })) {
335
+ var _originalSeries$0$sam, _originalSeries$, _originalSeries$0$sam2, _originalSeries$2;
336
+ sampleUnit = (_originalSeries$0$sam = (_originalSeries$ = originalSeries[0]) === null || _originalSeries$ === void 0 || (_originalSeries$ = _originalSeries$.sampleType) === null || _originalSeries$ === void 0 ? void 0 : _originalSeries$.unit) !== null && _originalSeries$0$sam !== void 0 ? _originalSeries$0$sam : '';
337
+ sampleType = (_originalSeries$0$sam2 = (_originalSeries$2 = originalSeries[0]) === null || _originalSeries$2 === void 0 || (_originalSeries$2 = _originalSeries$2.sampleType) === null || _originalSeries$2 === void 0 ? void 0 : _originalSeries$2.type) !== null && _originalSeries$0$sam2 !== void 0 ? _originalSeries$0$sam2 : '';
202
338
  }
203
- return null;
204
- }, [profile, originalSeries]);
205
- const transformedSeries = useMemo(() => {
206
- return originalSeries != null ? transformMetricsData(originalSeries) : [];
207
- }, [originalSeries]);
208
- const contextMenuItems = useMemo(() => {
209
- return originalSeries != null
210
- ? createProfileContextMenuItems(addLabelMatcher, originalSeries)
211
- : [];
212
- }, [originalSeries, addLabelMatcher]);
213
- const dataAvailable = originalSeries !== null && originalSeries !== undefined && originalSeries?.length > 0;
214
- const { sampleUnit, sampleType, yAxisLabel, yAxisUnit } = useMemo(() => {
215
- let sampleUnit = '';
216
- let sampleType = '';
217
- if (dataAvailable) {
218
- if (originalSeries?.every((val, i, arr) => val?.sampleType?.unit === arr[0]?.sampleType?.unit)) {
219
- sampleUnit = originalSeries[0]?.sampleType?.unit ?? '';
220
- sampleType = originalSeries[0]?.sampleType?.type ?? '';
221
- }
222
- if (sampleUnit === '') {
223
- const profileType = Query.parse(queryExpression).profileType();
224
- sampleUnit = profileType.sampleUnit;
225
- sampleType = profileType.sampleType;
226
- }
339
+ if (sampleUnit === '') {
340
+ var profileType = Query.parse(queryExpression).profileType();
341
+ sampleUnit = profileType.sampleUnit;
342
+ sampleType = profileType.sampleType;
227
343
  }
228
- // Calculate axis labels based on profile data
229
- const isDeltaType = profile !== null ? profile?.query.profType.delta : false;
230
- let yAxisLabel = sampleUnit;
231
- let yAxisUnit = sampleUnit;
232
- if (isDeltaType) {
233
- if (sampleUnit === 'nanoseconds') {
234
- if (sampleType === 'cpu') {
235
- yAxisLabel = 'CPU Cores';
236
- yAxisUnit = '';
237
- }
238
- if (sampleType === 'cuda') {
239
- yAxisLabel = 'GPU Time';
240
- }
241
- }
242
- if (sampleUnit === 'bytes') {
243
- yAxisLabel = 'Bytes per Second';
244
- }
344
+ }
345
+
346
+ // Calculate axis labels based on profile data
347
+ var isDeltaType = profile !== null ? profile === null || profile === void 0 ? void 0 : profile.query.profType.delta : false;
348
+ var yAxisLabel = sampleUnit;
349
+ var yAxisUnit = sampleUnit;
350
+ if (isDeltaType) {
351
+ if (sampleUnit === 'nanoseconds') {
352
+ if (sampleType === 'cpu') {
353
+ yAxisLabel = 'CPU Cores';
354
+ yAxisUnit = '';
355
+ }
356
+ if (sampleType === 'cuda') {
357
+ yAxisLabel = 'GPU Time';
358
+ }
245
359
  }
246
- return { sampleUnit, sampleType, yAxisLabel, yAxisUnit };
247
- }, [dataAvailable, originalSeries, queryExpression, profile]);
248
- const loading = metricsGraphLoading;
249
- // Handle errors after all hooks have been called
250
- if (!metricsGraphLoading && error !== null) {
251
- if (authenticationErrorMessage !== undefined && error.code === 'UNAUTHENTICATED') {
252
- return _jsx(ErrorContent, { errorMessage: authenticationErrorMessage });
360
+ if (sampleUnit === 'bytes') {
361
+ yAxisLabel = 'Bytes per Second';
253
362
  }
254
- return _jsx(ErrorContent, { errorMessage: capitalizeOnlyFirstLetter(error.message) });
363
+ }
364
+ return {
365
+ sampleUnit: sampleUnit,
366
+ sampleType: sampleType,
367
+ yAxisLabel: yAxisLabel,
368
+ yAxisUnit: yAxisUnit
369
+ };
370
+ }, [dataAvailable, originalSeries, queryExpression, profile]),
371
+ sampleUnit_0 = _useMemo3.sampleUnit,
372
+ sampleType_0 = _useMemo3.sampleType,
373
+ yAxisLabel_0 = _useMemo3.yAxisLabel,
374
+ yAxisUnit_0 = _useMemo3.yAxisUnit;
375
+ var loading = metricsGraphLoading;
376
+
377
+ // Handle errors after all hooks have been called
378
+ if (!metricsGraphLoading && error !== null) {
379
+ if (authenticationErrorMessage !== undefined && error.code === 'UNAUTHENTICATED') {
380
+ return /*#__PURE__*/_jsx(ErrorContent, {
381
+ errorMessage: authenticationErrorMessage
382
+ });
255
383
  }
256
- return (_jsx(AnimatePresence, { children: _jsxs(motion.div, { className: "h-full w-full relative", initial: { display: 'none', opacity: 0 }, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: [isTrimmed ? (_jsxs("div", { className: "flex justify-center items-center gap-2", ...testId(TEST_IDS.METRICS_GRAPH_TRIMMED_BANNER), children: [_jsxs("span", { className: "text-sm text-amber-800 dark:text-amber-200 bg-amber-100 dark:bg-amber-900 text-center px-2 rounded", children: ["Note: Showing only ", afterTrim, " of ", new Intl.NumberFormat().format(beforeTrim), " series for performance reasons. Please narrow your query to view more."] }), _jsxs("button", { onClick: () => setShowAllSeriesForResponse(response), className: "text-sm px-1 bg-amber-600 hover:bg-amber-700 dark:bg-amber-700 dark:hover:bg-amber-600 text-white rounded font-medium transition-colors", ...testId(TEST_IDS.METRICS_GRAPH_SHOW_ALL_BUTTON), children: ["Show all ", new Intl.NumberFormat().format(beforeTrim)] })] })) : null, loading ? (_jsx(MetricsGraphSkeleton, { heightStyle: heightStyle, isDarkMode: isDarkMode })) : dataAvailable ? (_jsx(MetricsGraph, { data: transformedSeries, from: from, to: to, setTimeRange: setTimeRange, selectedPoint: selectedPoint, onSampleClick: (closestPoint) => {
257
- // Use original data for both series and point
258
- if (originalSeries?.[closestPoint.seriesIndex] != null) {
259
- const originalSeriesData = originalSeries[closestPoint.seriesIndex];
260
- const originalPoint = originalSeriesData.samples[closestPoint.pointIndex];
261
- if (originalPoint.timestamp != null && originalPoint.valuePerSecond !== undefined) {
262
- const timestampNanos = originalPoint.timestamp.seconds * 1000000000n +
263
- BigInt(originalPoint.timestamp.nanos);
264
- onPointClick(timestampNanos, // Convert to number to match interface
265
- originalSeriesData.labelset?.labels ?? [], queryExpression, Number(originalPoint.duration ?? 0) // Convert bigint to number
266
- );
267
- }
268
- }
269
- }, renderTooltipContent: (seriesIndex, pointIndex) => {
270
- if (originalSeries?.[seriesIndex]?.samples?.[pointIndex] != null) {
271
- const originalSeriesData = originalSeries[seriesIndex];
272
- const originalPoint = originalSeriesData.samples[pointIndex];
273
- if (originalPoint.timestamp != null && originalPoint.valuePerSecond !== undefined) {
274
- const timestampMs = Number(originalPoint.timestamp.seconds) * 1000 +
275
- originalPoint.timestamp.nanos / 1000000;
276
- const labels = originalSeriesData.labelset?.labels ?? [];
277
- const nameLabel = labels.find(e => e.name === '__name__');
278
- const highlightedNameLabel = nameLabel ?? { name: '', value: '' };
279
- const isDeltaType = profile !== null
280
- ? profile?.query.profType.delta
281
- : false;
282
- return (_jsx("div", { className: "flex flex-row", children: _jsxs("div", { className: "ml-2 mr-6", children: [_jsx("span", { className: "font-semibold", children: highlightedNameLabel.value }), _jsx("span", { className: "my-2 block text-gray-700 dark:text-gray-300", children: _jsx("table", { className: "table-auto", children: _jsxs("tbody", { children: [isDeltaType ? (_jsxs(_Fragment, { children: [_jsxs("tr", { children: [_jsx("td", { className: "w-1/4 pr-3", children: "Per\u00A0Second" }), _jsx("td", { className: "w-3/4", children: valueFormatter(originalPoint.valuePerSecond, sampleUnit === 'nanoseconds' && sampleType === 'cpu'
283
- ? 'CPU Cores'
284
- : sampleUnit, 5) })] }), _jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "Total" }), _jsx("td", { className: "w-3/4", children: valueFormatter(originalPoint.value ?? 0, sampleUnit, 2) })] })] })) : (_jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "Value" }), _jsx("td", { className: "w-3/4", children: valueFormatter(originalPoint.valuePerSecond, sampleUnit, 5) })] })), originalPoint.duration != null &&
285
- Number(originalPoint.duration) > 0 && (_jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "Duration" }), _jsx("td", { className: "w-3/4", children: valueFormatter(Number(originalPoint.duration.toString()), 'nanoseconds', 2) })] })), _jsxs("tr", { children: [_jsx("td", { className: "w-1/4", children: "At" }), _jsx("td", { className: "w-3/4", children: formatDate(new Date(timestampMs), timePattern(timezone), timezone) })] })] }) }) }), _jsx("span", { className: "my-2 block text-gray-500", children: labels
286
- .filter((label) => label.name !== '__name__')
287
- .map((label) => (_jsx("div", { className: "mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400", ...testId(TEST_IDS.TOOLTIP_LABEL), children: _jsx(TextWithTooltip, { text: `${label.name}="${label.value}"`, maxTextLength: 37, id: `tooltip-${label.name}` }) }, label.name))) }), _jsxs("div", { className: "flex w-full items-center gap-1 text-xs text-gray-500", children: [_jsx(Icon, { icon: "iconoir:mouse-button-right" }), _jsx("div", { children: "Right click to add labels to query." })] })] }) }));
288
- }
289
- }
290
- return null;
291
- }, yAxisLabel: yAxisLabel, yAxisUnit: yAxisUnit, height: height, width: width, margin: margin, contextMenuItems: contextMenuItems })) : (_jsx(ProfileMetricsEmptyState, { message: "No data found. Try a different query." }))] }, "metrics-graph-loaded") }));
384
+ return /*#__PURE__*/_jsx(ErrorContent, {
385
+ errorMessage: capitalizeOnlyFirstLetter(error.message)
386
+ });
387
+ }
388
+ return /*#__PURE__*/_jsx(AnimatePresence, {
389
+ children: /*#__PURE__*/_jsxs(motion.div, {
390
+ className: "h-full w-full relative",
391
+ initial: {
392
+ display: 'none',
393
+ opacity: 0
394
+ },
395
+ animate: {
396
+ display: 'block',
397
+ opacity: 1
398
+ },
399
+ transition: {
400
+ duration: 0.5
401
+ },
402
+ children: [isTrimmed ? /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
403
+ className: "flex justify-center items-center gap-2"
404
+ }, testId(TEST_IDS.METRICS_GRAPH_TRIMMED_BANNER)), {}, {
405
+ children: [/*#__PURE__*/_jsxs("span", {
406
+ className: "text-sm text-amber-800 dark:text-amber-200 bg-amber-100 dark:bg-amber-900 text-center px-2 rounded",
407
+ children: ["Note: Showing only ", afterTrim, " of ", new Intl.NumberFormat().format(beforeTrim), " series for performance reasons. Please narrow your query to view more."]
408
+ }), /*#__PURE__*/_jsxs("button", _objectSpread(_objectSpread({
409
+ onClick: function onClick() {
410
+ return setShowAllSeriesForResponse(response);
411
+ },
412
+ className: "text-sm px-1 bg-amber-600 hover:bg-amber-700 dark:bg-amber-700 dark:hover:bg-amber-600 text-white rounded font-medium transition-colors"
413
+ }, testId(TEST_IDS.METRICS_GRAPH_SHOW_ALL_BUTTON)), {}, {
414
+ children: ["Show all ", new Intl.NumberFormat().format(beforeTrim)]
415
+ }))]
416
+ })) : null, loading ? /*#__PURE__*/_jsx(MetricsGraphSkeleton, {
417
+ heightStyle: heightStyle,
418
+ isDarkMode: isDarkMode
419
+ }) : dataAvailable ? /*#__PURE__*/_jsx(MetricsGraph, {
420
+ data: transformedSeries,
421
+ from: from,
422
+ to: to,
423
+ setTimeRange: setTimeRange,
424
+ selectedPoint: selectedPoint,
425
+ onSampleClick: function onSampleClick(closestPoint) {
426
+ // Use original data for both series and point
427
+ if ((originalSeries === null || originalSeries === void 0 ? void 0 : originalSeries[closestPoint.seriesIndex]) != null) {
428
+ var originalSeriesData = originalSeries[closestPoint.seriesIndex];
429
+ var originalPoint = originalSeriesData.samples[closestPoint.pointIndex];
430
+ if (originalPoint.timestamp != null && originalPoint.valuePerSecond !== undefined) {
431
+ var _originalSeriesData$l3, _originalSeriesData$l4, _originalPoint$durati;
432
+ var timestampNanos = originalPoint.timestamp.seconds * 1000000000n + BigInt(originalPoint.timestamp.nanos);
433
+ onPointClick(timestampNanos, // Convert to number to match interface
434
+ (_originalSeriesData$l3 = (_originalSeriesData$l4 = originalSeriesData.labelset) === null || _originalSeriesData$l4 === void 0 ? void 0 : _originalSeriesData$l4.labels) !== null && _originalSeriesData$l3 !== void 0 ? _originalSeriesData$l3 : [], queryExpression, Number((_originalPoint$durati = originalPoint.duration) !== null && _originalPoint$durati !== void 0 ? _originalPoint$durati : 0) // Convert bigint to number
435
+ );
436
+ }
437
+ }
438
+ },
439
+ renderTooltipContent: function renderTooltipContent(seriesIndex_0, pointIndex_0) {
440
+ var _originalSeries$serie;
441
+ if ((originalSeries === null || originalSeries === void 0 || (_originalSeries$serie = originalSeries[seriesIndex_0]) === null || _originalSeries$serie === void 0 || (_originalSeries$serie = _originalSeries$serie.samples) === null || _originalSeries$serie === void 0 ? void 0 : _originalSeries$serie[pointIndex_0]) != null) {
442
+ var originalSeriesData_0 = originalSeries[seriesIndex_0];
443
+ var originalPoint_0 = originalSeriesData_0.samples[pointIndex_0];
444
+ if (originalPoint_0.timestamp != null && originalPoint_0.valuePerSecond !== undefined) {
445
+ var _originalSeriesData_, _originalSeriesData_2, _originalPoint_0$valu;
446
+ var timestampMs = Number(originalPoint_0.timestamp.seconds) * 1000 + originalPoint_0.timestamp.nanos / 1000000;
447
+ var labels = (_originalSeriesData_ = (_originalSeriesData_2 = originalSeriesData_0.labelset) === null || _originalSeriesData_2 === void 0 ? void 0 : _originalSeriesData_2.labels) !== null && _originalSeriesData_ !== void 0 ? _originalSeriesData_ : [];
448
+ var nameLabel = labels.find(function (e) {
449
+ return e.name === '__name__';
450
+ });
451
+ var highlightedNameLabel = nameLabel !== null && nameLabel !== void 0 ? nameLabel : {
452
+ name: '',
453
+ value: ''
454
+ };
455
+ var isDeltaType_0 = profile !== null ? profile === null || profile === void 0 ? void 0 : profile.query.profType.delta : false;
456
+ return /*#__PURE__*/_jsx("div", {
457
+ className: "flex flex-row",
458
+ children: /*#__PURE__*/_jsxs("div", {
459
+ className: "ml-2 mr-6",
460
+ children: [/*#__PURE__*/_jsx("span", {
461
+ className: "font-semibold",
462
+ children: highlightedNameLabel.value
463
+ }), /*#__PURE__*/_jsx("span", {
464
+ className: "my-2 block text-gray-700 dark:text-gray-300",
465
+ children: /*#__PURE__*/_jsx("table", {
466
+ className: "table-auto",
467
+ children: /*#__PURE__*/_jsxs("tbody", {
468
+ children: [isDeltaType_0 ? /*#__PURE__*/_jsxs(_Fragment, {
469
+ children: [/*#__PURE__*/_jsxs("tr", {
470
+ children: [/*#__PURE__*/_jsx("td", {
471
+ className: "w-1/4 pr-3",
472
+ children: "Per\xA0Second"
473
+ }), /*#__PURE__*/_jsx("td", {
474
+ className: "w-3/4",
475
+ children: valueFormatter(originalPoint_0.valuePerSecond, sampleUnit_0 === 'nanoseconds' && sampleType_0 === 'cpu' ? 'CPU Cores' : sampleUnit_0, 5)
476
+ })]
477
+ }), /*#__PURE__*/_jsxs("tr", {
478
+ children: [/*#__PURE__*/_jsx("td", {
479
+ className: "w-1/4",
480
+ children: "Total"
481
+ }), /*#__PURE__*/_jsx("td", {
482
+ className: "w-3/4",
483
+ children: valueFormatter((_originalPoint_0$valu = originalPoint_0.value) !== null && _originalPoint_0$valu !== void 0 ? _originalPoint_0$valu : 0, sampleUnit_0, 2)
484
+ })]
485
+ })]
486
+ }) : /*#__PURE__*/_jsxs("tr", {
487
+ children: [/*#__PURE__*/_jsx("td", {
488
+ className: "w-1/4",
489
+ children: "Value"
490
+ }), /*#__PURE__*/_jsx("td", {
491
+ className: "w-3/4",
492
+ children: valueFormatter(originalPoint_0.valuePerSecond, sampleUnit_0, 5)
493
+ })]
494
+ }), originalPoint_0.duration != null && Number(originalPoint_0.duration) > 0 && /*#__PURE__*/_jsxs("tr", {
495
+ children: [/*#__PURE__*/_jsx("td", {
496
+ className: "w-1/4",
497
+ children: "Duration"
498
+ }), /*#__PURE__*/_jsx("td", {
499
+ className: "w-3/4",
500
+ children: valueFormatter(Number(originalPoint_0.duration.toString()), 'nanoseconds', 2)
501
+ })]
502
+ }), /*#__PURE__*/_jsxs("tr", {
503
+ children: [/*#__PURE__*/_jsx("td", {
504
+ className: "w-1/4",
505
+ children: "At"
506
+ }), /*#__PURE__*/_jsx("td", {
507
+ className: "w-3/4",
508
+ children: formatDate(new Date(timestampMs), timePattern(timezone), timezone)
509
+ })]
510
+ })]
511
+ })
512
+ })
513
+ }), /*#__PURE__*/_jsx("span", {
514
+ className: "my-2 block text-gray-500",
515
+ children: labels.filter(function (label_0) {
516
+ return label_0.name !== '__name__';
517
+ }).map(function (label_1) {
518
+ return /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
519
+ className: "mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400"
520
+ }, testId(TEST_IDS.TOOLTIP_LABEL)), {}, {
521
+ children: /*#__PURE__*/_jsx(TextWithTooltip, {
522
+ text: "".concat(label_1.name, "=\"").concat(label_1.value, "\""),
523
+ maxTextLength: 37,
524
+ id: "tooltip-".concat(label_1.name)
525
+ })
526
+ }), label_1.name);
527
+ })
528
+ }), /*#__PURE__*/_jsxs("div", {
529
+ className: "flex w-full items-center gap-1 text-xs text-gray-500",
530
+ children: [/*#__PURE__*/_jsx(Icon, {
531
+ icon: "iconoir:mouse-button-right"
532
+ }), /*#__PURE__*/_jsx("div", {
533
+ children: "Right click to add labels to query."
534
+ })]
535
+ })]
536
+ })
537
+ });
538
+ }
539
+ }
540
+ return null;
541
+ },
542
+ yAxisLabel: yAxisLabel_0,
543
+ yAxisUnit: yAxisUnit_0,
544
+ height: height,
545
+ width: width,
546
+ margin: margin,
547
+ contextMenuItems: contextMenuItems
548
+ }) : /*#__PURE__*/_jsx(ProfileMetricsEmptyState, {
549
+ message: "No data found. Try a different query."
550
+ })]
551
+ }, "metrics-graph-loaded")
552
+ });
292
553
  };
293
- export default ProfileMetricsGraph;
554
+ export default ProfileMetricsGraph;