index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {Fragment} 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 useCurrentHoverTime from 'sentry/utils/replays/playback/providers/useCurrentHoverTime';
  9. import MemoryChart from 'sentry/views/replays/detail/memoryPanel/memoryChart';
  10. export default function MemoryPanel() {
  11. const {currentTime, isFetching, replay, setCurrentTime} = useReplayContext();
  12. const [currentHoverTime, setCurrentHoverTime] = useCurrentHoverTime();
  13. const memoryFrames = replay?.getMemoryFrames();
  14. const memoryChart =
  15. !replay || isFetching ? (
  16. <Placeholder height="100%" />
  17. ) : !replay || !memoryFrames?.length ? (
  18. <EmptyMessage
  19. data-test-id="replay-details-memory-tab"
  20. title={t('No memory metrics found')}
  21. description={t(
  22. 'Memory metrics are only captured within Chromium based browser sessions.'
  23. )}
  24. />
  25. ) : (
  26. <Fragment>
  27. <ChartTitle>{t('Heap Size')}</ChartTitle>
  28. <MemoryChart
  29. currentHoverTime={currentHoverTime}
  30. currentTime={currentTime}
  31. durationMs={replay.getDurationMs()}
  32. memoryFrames={memoryFrames}
  33. setCurrentHoverTime={setCurrentHoverTime}
  34. setCurrentTime={setCurrentTime}
  35. startTimestampMs={replay.getStartTimestampMs()}
  36. />
  37. </Fragment>
  38. );
  39. return (
  40. <Grid>
  41. <ChartWrapper>{memoryChart}</ChartWrapper>
  42. </Grid>
  43. );
  44. }
  45. const Grid = styled('div')`
  46. display: grid;
  47. grid-template-rows: 1fr 1fr;
  48. grid-template-columns: 1fr;
  49. gap: ${space(1)};
  50. justify-content: center;
  51. height: 100%;
  52. `;
  53. const ChartWrapper = styled('div')`
  54. border: 1px solid ${p => p.theme.border};
  55. border-radius: ${space(0.5)};
  56. padding: ${space(1)};
  57. overflow: hidden;
  58. display: flex;
  59. flex-direction: column;
  60. & > * {
  61. flex-grow: 1;
  62. }
  63. `;
  64. const ChartTitle = styled('h5')`
  65. font-size: ${p => p.theme.fontSizeLarge};
  66. font-weight: ${p => p.theme.text.cardTitle.fontWeight};
  67. line-height: ${p => p.theme.text.cardTitle.lineHeight};
  68. color: ${p => p.theme.subText};
  69. flex: 0 1 auto;
  70. margin: 0;
  71. `;