index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import EmptyMessage from 'sentry/components/emptyMessage';
  4. import Placeholder from 'sentry/components/placeholder';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {useQuery} from 'sentry/utils/queryClient';
  9. import countDomNodes from 'sentry/utils/replays/countDomNodes';
  10. import type ReplayReader from 'sentry/utils/replays/replayReader';
  11. import DomNodesChart from 'sentry/views/replays/detail/memoryPanel/domNodesChart';
  12. import MemoryChart from 'sentry/views/replays/detail/memoryPanel/memoryChart';
  13. function useCountDomNodes({replay}: {replay: null | ReplayReader}) {
  14. return useQuery(
  15. ['countDomNodes', replay],
  16. () =>
  17. countDomNodes({
  18. frames: replay?.getRRWebMutations(),
  19. rrwebEvents: replay?.getRRWebFrames(),
  20. startTimestampMs: replay?.getStartTimestampMs() ?? 0,
  21. }),
  22. {enabled: Boolean(replay), cacheTime: Infinity}
  23. );
  24. }
  25. export default function MemoryPanel() {
  26. const {
  27. currentTime,
  28. currentHoverTime,
  29. isFetching,
  30. replay,
  31. setCurrentHoverTime,
  32. setCurrentTime,
  33. } = useReplayContext();
  34. const memoryFrames = replay?.getMemoryFrames();
  35. const {data: frameToCount} = useCountDomNodes({replay});
  36. const domNodeData = useMemo(
  37. () => Array.from(frameToCount?.values() || []),
  38. [frameToCount]
  39. );
  40. const memoryChart =
  41. !replay || isFetching ? (
  42. <Placeholder height="100%" />
  43. ) : !replay || !memoryFrames?.length ? (
  44. <EmptyMessage
  45. data-test-id="replay-details-memory-tab"
  46. title={t('No memory metrics found')}
  47. description={t(
  48. 'Memory metrics are only captured within Chromium based browser sessions.'
  49. )}
  50. />
  51. ) : (
  52. <MemoryChart
  53. currentHoverTime={currentHoverTime}
  54. currentTime={currentTime}
  55. durationMs={replay.getDurationMs()}
  56. memoryFrames={memoryFrames}
  57. setCurrentHoverTime={setCurrentHoverTime}
  58. setCurrentTime={setCurrentTime}
  59. startOffsetMs={replay.getStartOffsetMs()}
  60. />
  61. );
  62. const domNodesChart =
  63. !replay || isFetching ? (
  64. <Placeholder height="100%" />
  65. ) : (
  66. <DomNodesChart
  67. currentHoverTime={currentHoverTime}
  68. currentTime={currentTime}
  69. durationMs={replay.getDurationMs()}
  70. datapoints={domNodeData}
  71. setCurrentHoverTime={setCurrentHoverTime}
  72. setCurrentTime={setCurrentTime}
  73. startOffsetMs={replay.getStartOffsetMs()}
  74. startTimestampMs={replay.getStartTimestampMs()}
  75. />
  76. );
  77. return (
  78. <Grid>
  79. <ChartWrapper>{memoryChart}</ChartWrapper>
  80. <ChartWrapper>{domNodesChart}</ChartWrapper>
  81. </Grid>
  82. );
  83. }
  84. const Grid = styled('div')`
  85. display: grid;
  86. grid-template-rows: 1fr 1fr;
  87. grid-template-columns: 1fr;
  88. gap: ${space(1)};
  89. justify-content: center;
  90. height: 100%;
  91. `;
  92. const ChartWrapper = styled('div')`
  93. border: 1px solid ${p => p.theme.border};
  94. border-radius: ${space(0.5)};
  95. padding: ${space(1)};
  96. overflow: hidden;
  97. display: flex;
  98. & > * {
  99. flex-grow: 1;
  100. }
  101. `;