index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. import {useCallback, useEffect, useMemo, useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import type {Location} from 'history';
  5. import {Button, LinkButton} from 'sentry/components/button';
  6. import {CompactSelect} from 'sentry/components/compactSelect';
  7. import type {SelectOption} from 'sentry/components/compactSelect/types';
  8. import Count from 'sentry/components/count';
  9. import DateTime from 'sentry/components/dateTime';
  10. import ErrorBoundary from 'sentry/components/errorBoundary';
  11. import SearchBar from 'sentry/components/events/searchBar';
  12. import IdBadge from 'sentry/components/idBadge';
  13. import * as Layout from 'sentry/components/layouts/thirds';
  14. import LoadingIndicator from 'sentry/components/loadingIndicator';
  15. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  16. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  17. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  18. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  19. import PerformanceDuration from 'sentry/components/performanceDuration';
  20. import {AggregateFlamegraph} from 'sentry/components/profiling/flamegraph/aggregateFlamegraph';
  21. import {AggregateFlamegraphTreeTable} from 'sentry/components/profiling/flamegraph/aggregateFlamegraphTreeTable';
  22. import {FlamegraphSearch} from 'sentry/components/profiling/flamegraph/flamegraphToolbar/flamegraphSearch';
  23. import {
  24. ProfilingBreadcrumbs,
  25. ProfilingBreadcrumbsProps,
  26. } from 'sentry/components/profiling/profilingBreadcrumbs';
  27. import {SegmentedControl} from 'sentry/components/segmentedControl';
  28. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  29. import type {SmartSearchBarProps} from 'sentry/components/smartSearchBar';
  30. import SmartSearchBar from 'sentry/components/smartSearchBar';
  31. import {TabList, Tabs} from 'sentry/components/tabs';
  32. import {MAX_QUERY_LENGTH} from 'sentry/constants';
  33. import {t} from 'sentry/locale';
  34. import {space} from 'sentry/styles/space';
  35. import type {Organization, PageFilters, Project} from 'sentry/types';
  36. import {DeepPartial} from 'sentry/types/utils';
  37. import {defined} from 'sentry/utils';
  38. import EventView from 'sentry/utils/discover/eventView';
  39. import {isAggregateField} from 'sentry/utils/discover/fields';
  40. import {
  41. CanvasPoolManager,
  42. CanvasScheduler,
  43. useCanvasScheduler,
  44. } from 'sentry/utils/profiling/canvasScheduler';
  45. import {FlamegraphState} from 'sentry/utils/profiling/flamegraph/flamegraphStateProvider/flamegraphContext';
  46. import {FlamegraphStateProvider} from 'sentry/utils/profiling/flamegraph/flamegraphStateProvider/flamegraphContextProvider';
  47. import {FlamegraphThemeProvider} from 'sentry/utils/profiling/flamegraph/flamegraphThemeProvider';
  48. import {Frame} from 'sentry/utils/profiling/frame';
  49. import {useAggregateFlamegraphQuery} from 'sentry/utils/profiling/hooks/useAggregateFlamegraphQuery';
  50. import {useCurrentProjectFromRouteParam} from 'sentry/utils/profiling/hooks/useCurrentProjectFromRouteParam';
  51. import {useProfileEvents} from 'sentry/utils/profiling/hooks/useProfileEvents';
  52. import {useProfileFilters} from 'sentry/utils/profiling/hooks/useProfileFilters';
  53. import {decodeScalar} from 'sentry/utils/queryString';
  54. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  55. import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
  56. import {useLocation} from 'sentry/utils/useLocation';
  57. import useOrganization from 'sentry/utils/useOrganization';
  58. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  59. import {
  60. FlamegraphProvider,
  61. useFlamegraph,
  62. } from 'sentry/views/profiling/flamegraphProvider';
  63. import {ProfilesSummaryChart} from 'sentry/views/profiling/landing/profilesSummaryChart';
  64. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  65. import {ProfilingFieldType} from 'sentry/views/profiling/profileSummary/content';
  66. import {LegacySummaryPage} from 'sentry/views/profiling/profileSummary/legacySummaryPage';
  67. import {ProfilesTable} from 'sentry/views/profiling/profileSummary/profilesTable';
  68. import {DEFAULT_PROFILING_DATETIME_SELECTION} from 'sentry/views/profiling/utils';
  69. import {MostRegressedProfileFunctions} from './regressedProfileFunctions';
  70. import {SlowestProfileFunctions} from './slowestProfileFunctions';
  71. function decodeViewOrDefault(
  72. value: string | string[] | null | undefined,
  73. defaultValue: 'flamegraph' | 'profiles'
  74. ): 'flamegraph' | 'profiles' {
  75. if (!value || Array.isArray(value)) {
  76. return defaultValue;
  77. }
  78. if (value === 'flamegraph' || value === 'profiles') {
  79. return value;
  80. }
  81. return defaultValue;
  82. }
  83. const DEFAULT_FLAMEGRAPH_PREFERENCES: DeepPartial<FlamegraphState> = {
  84. preferences: {
  85. sorting: 'alphabetical' satisfies FlamegraphState['preferences']['sorting'],
  86. },
  87. };
  88. interface ProfileSummaryHeaderProps {
  89. location: Location;
  90. onViewChange: (newVie: 'flamegraph' | 'profiles') => void;
  91. organization: Organization;
  92. project: Project | null;
  93. query: string;
  94. transaction: string;
  95. view: 'flamegraph' | 'profiles';
  96. }
  97. function ProfileSummaryHeader(props: ProfileSummaryHeaderProps) {
  98. const breadcrumbTrails: ProfilingBreadcrumbsProps['trails'] = useMemo(() => {
  99. return [
  100. {
  101. type: 'landing',
  102. payload: {
  103. query: props.location.query,
  104. },
  105. },
  106. {
  107. type: 'profile summary',
  108. payload: {
  109. projectSlug: props.project?.slug ?? '',
  110. query: props.location.query,
  111. transaction: props.transaction,
  112. },
  113. },
  114. ];
  115. }, [props.location.query, props.project?.slug, props.transaction]);
  116. const transactionSummaryTarget =
  117. props.project &&
  118. props.transaction &&
  119. transactionSummaryRouteWithQuery({
  120. orgSlug: props.organization.slug,
  121. transaction: props.transaction,
  122. projectID: props.project.id,
  123. query: {query: props.query},
  124. });
  125. return (
  126. <ProfilingHeader>
  127. <ProfilingHeaderContent>
  128. <ProfilingBreadcrumbs
  129. organization={props.organization}
  130. trails={breadcrumbTrails}
  131. />
  132. <Layout.Title>
  133. <ProfilingTitleContainer>
  134. {props.project ? (
  135. <IdBadge
  136. hideName
  137. project={props.project}
  138. avatarSize={22}
  139. avatarProps={{hasTooltip: true, tooltip: props.project.slug}}
  140. />
  141. ) : null}
  142. {props.transaction}
  143. </ProfilingTitleContainer>
  144. </Layout.Title>
  145. </ProfilingHeaderContent>
  146. {transactionSummaryTarget && (
  147. <Layout.HeaderActions>
  148. <LinkButton to={transactionSummaryTarget} size="sm">
  149. {t('View Transaction Summary')}
  150. </LinkButton>
  151. </Layout.HeaderActions>
  152. )}
  153. <Tabs onChange={props.onViewChange} value={props.view}>
  154. <TabList hideBorder>
  155. <TabList.Item key="flamegraph">{t('Flamegraph')}</TabList.Item>
  156. <TabList.Item key="profiles">{t('Sampled Profiles')}</TabList.Item>
  157. </TabList>
  158. </Tabs>
  159. </ProfilingHeader>
  160. );
  161. }
  162. const ProfilingHeader = styled(Layout.Header)`
  163. padding: ${space(1)} ${space(2)} ${space(0)} ${space(2)} !important;
  164. `;
  165. const ProfilingHeaderContent = styled(Layout.HeaderContent)`
  166. margin-bottom: ${space(1)};
  167. h1 {
  168. line-height: normal;
  169. }
  170. `;
  171. const ProfilingTitleContainer = styled('div')`
  172. display: flex;
  173. align-items: center;
  174. gap: ${space(1)};
  175. font-size: ${p => p.theme.fontSizeLarge};
  176. `;
  177. interface ProfileFiltersProps {
  178. location: Location;
  179. organization: Organization;
  180. projectIds: EventView['project'];
  181. query: string;
  182. selection: PageFilters;
  183. transaction: string | undefined;
  184. usingTransactions: boolean;
  185. }
  186. function ProfileFilters(props: ProfileFiltersProps) {
  187. const filtersQuery = useMemo(() => {
  188. // To avoid querying for the filters each time the query changes,
  189. // do not pass the user query to get the filters.
  190. const search = new MutableSearch('');
  191. if (defined(props.transaction)) {
  192. search.setFilterValues('transaction_name', [props.transaction]);
  193. }
  194. return search.formatString();
  195. }, [props.transaction]);
  196. const profileFilters = useProfileFilters({
  197. query: filtersQuery,
  198. selection: props.selection,
  199. disabled: props.usingTransactions,
  200. });
  201. const handleSearch: SmartSearchBarProps['onSearch'] = useCallback(
  202. (searchQuery: string) => {
  203. browserHistory.push({
  204. ...props.location,
  205. query: {
  206. ...props.location.query,
  207. query: searchQuery || undefined,
  208. cursor: undefined,
  209. },
  210. });
  211. },
  212. [props.location]
  213. );
  214. return (
  215. <ActionBar>
  216. <PageFilterBar condensed>
  217. <EnvironmentPageFilter />
  218. <DatePageFilter />
  219. </PageFilterBar>
  220. {props.usingTransactions ? (
  221. <SearchBar
  222. searchSource="profile_summary"
  223. organization={props.organization}
  224. projectIds={props.projectIds}
  225. query={props.query}
  226. onSearch={handleSearch}
  227. maxQueryLength={MAX_QUERY_LENGTH}
  228. />
  229. ) : (
  230. <SmartSearchBar
  231. organization={props.organization}
  232. hasRecentSearches
  233. searchSource="profile_summary"
  234. supportedTags={profileFilters}
  235. query={props.query}
  236. onSearch={handleSearch}
  237. maxQueryLength={MAX_QUERY_LENGTH}
  238. />
  239. )}
  240. </ActionBar>
  241. );
  242. }
  243. const ActionBar = styled('div')`
  244. display: grid;
  245. gap: ${space(1)};
  246. grid-template-columns: min-content auto;
  247. padding: ${space(1)} ${space(1)};
  248. background-color: ${p => p.theme.background};
  249. `;
  250. interface ProfileSummaryPageProps {
  251. location: Location;
  252. params: {
  253. projectId?: Project['slug'];
  254. };
  255. selection: PageFilters;
  256. view: 'flamegraph' | 'profile list';
  257. }
  258. function ProfileSummaryPage(props: ProfileSummaryPageProps) {
  259. const organization = useOrganization();
  260. const project = useCurrentProjectFromRouteParam();
  261. const profilingUsingTransactions = organization.features.includes(
  262. 'profiling-using-transactions'
  263. );
  264. const transaction = decodeScalar(props.location.query.transaction);
  265. if (!transaction) {
  266. throw new TypeError(
  267. `Profile summary requires a transaction query params, got ${
  268. transaction?.toString() ?? transaction
  269. }`
  270. );
  271. }
  272. const rawQuery = decodeScalar(props.location?.query?.query, '');
  273. const projectIds: number[] = useMemo(() => {
  274. if (!defined(project)) {
  275. return [];
  276. }
  277. const projects = parseInt(project.id, 10);
  278. if (isNaN(projects)) {
  279. return [];
  280. }
  281. return [projects];
  282. }, [project]);
  283. const projectSlugs: string[] = useMemo(() => {
  284. return defined(project) ? [project.slug] : [];
  285. }, [project]);
  286. const query = useMemo(() => {
  287. const search = new MutableSearch(rawQuery);
  288. if (defined(transaction)) {
  289. search.setFilterValues('transaction', [transaction]);
  290. }
  291. // there are no aggregations happening on this page,
  292. // so remove any aggregate filters
  293. Object.keys(search.filters).forEach(field => {
  294. if (isAggregateField(field)) {
  295. search.removeFilter(field);
  296. }
  297. });
  298. return search.formatString();
  299. }, [rawQuery, transaction]);
  300. const {data, isLoading, isError} = useAggregateFlamegraphQuery({transaction});
  301. const [visualization, setVisualization] = useLocalStorageState<
  302. 'flamegraph' | 'call tree'
  303. >('flamegraph-visualization', 'flamegraph');
  304. const onVisualizationChange = useCallback(
  305. (value: 'flamegraph' | 'call tree') => {
  306. setVisualization(value);
  307. },
  308. [setVisualization]
  309. );
  310. const [frameFilter, setFrameFilter] = useLocalStorageState<
  311. 'system' | 'application' | 'all'
  312. >('flamegraph-frame-filter', 'application');
  313. const onFrameFilterChange = useCallback(
  314. (value: 'system' | 'application' | 'all') => {
  315. setFrameFilter(value);
  316. },
  317. [setFrameFilter]
  318. );
  319. const flamegraphFrameFilter: ((frame: Frame) => boolean) | undefined = useMemo(() => {
  320. if (frameFilter === 'all') {
  321. return () => true;
  322. }
  323. if (frameFilter === 'application') {
  324. return frame => frame.is_application;
  325. }
  326. return frame => !frame.is_application;
  327. }, [frameFilter]);
  328. const canvasPoolManager = useMemo(() => new CanvasPoolManager(), []);
  329. const scheduler = useCanvasScheduler(canvasPoolManager);
  330. const location = useLocation();
  331. const [view, setView] = useState<'flamegraph' | 'profiles'>(
  332. decodeViewOrDefault(location.query.view, 'flamegraph')
  333. );
  334. useEffect(() => {
  335. const newView = decodeViewOrDefault(location.query.view, 'flamegraph');
  336. if (newView !== view) {
  337. setView(decodeViewOrDefault(location.query.view, 'flamegraph'));
  338. }
  339. }, [location.query.view, view]);
  340. const onSetView = useCallback(
  341. (newView: 'flamegraph' | 'profiles') => {
  342. setView(newView);
  343. browserHistory.push({
  344. ...location,
  345. query: {
  346. ...location.query,
  347. view: newView,
  348. },
  349. });
  350. },
  351. [location]
  352. );
  353. return (
  354. <SentryDocumentTitle
  355. title={t('Profiling \u2014 Profile Summary')}
  356. orgSlug={organization.slug}
  357. >
  358. <ProfileSummaryContainer>
  359. <PageFiltersContainer
  360. shouldForceProject={defined(project)}
  361. forceProject={project}
  362. specificProjectSlugs={projectSlugs}
  363. defaultSelection={
  364. profilingUsingTransactions
  365. ? {datetime: DEFAULT_PROFILING_DATETIME_SELECTION}
  366. : undefined
  367. }
  368. >
  369. <ProfileSummaryHeader
  370. view={view}
  371. onViewChange={onSetView}
  372. organization={organization}
  373. location={props.location}
  374. project={project}
  375. query={query}
  376. transaction={transaction}
  377. />
  378. <ProfileFilters
  379. projectIds={projectIds}
  380. organization={organization}
  381. location={props.location}
  382. query={rawQuery}
  383. selection={props.selection}
  384. transaction={transaction}
  385. usingTransactions={profilingUsingTransactions}
  386. />
  387. <ProfilesSummaryChart
  388. referrer="api.profiling.profile-summary-chart"
  389. query={query}
  390. hideCount
  391. />
  392. {view === 'profiles' ? (
  393. <ProfilesTable />
  394. ) : (
  395. <ProfileVisualizationContainer>
  396. <ProfileVisualization>
  397. <ProfileGroupProvider
  398. traceID=""
  399. type="flamegraph"
  400. input={data ?? null}
  401. frameFilter={flamegraphFrameFilter}
  402. >
  403. <FlamegraphStateProvider initialState={DEFAULT_FLAMEGRAPH_PREFERENCES}>
  404. <FlamegraphThemeProvider>
  405. <FlamegraphProvider>
  406. <AggregateFlamegraphContainer>
  407. <AggregateFlamegraphToolbar
  408. scheduler={scheduler}
  409. canvasPoolManager={canvasPoolManager}
  410. visualization={visualization}
  411. onVisualizationChange={onVisualizationChange}
  412. frameFilter={frameFilter}
  413. onFrameFilterChange={onFrameFilterChange}
  414. hideSystemFrames={false}
  415. setHideSystemFrames={() => void 0}
  416. />
  417. {isLoading ? (
  418. <RequestStateMessageContainer>
  419. <LoadingIndicator />
  420. </RequestStateMessageContainer>
  421. ) : isError ? (
  422. <RequestStateMessageContainer>
  423. {t('There was an error loading the flamegraph.')}
  424. </RequestStateMessageContainer>
  425. ) : null}
  426. {visualization === 'flamegraph' ? (
  427. <AggregateFlamegraph
  428. canvasPoolManager={canvasPoolManager}
  429. scheduler={scheduler}
  430. />
  431. ) : (
  432. <AggregateFlamegraphTreeTable
  433. recursion={null}
  434. expanded={false}
  435. frameFilter={frameFilter}
  436. canvasScheduler={scheduler}
  437. canvasPoolManager={canvasPoolManager}
  438. />
  439. )}
  440. </AggregateFlamegraphContainer>
  441. </FlamegraphProvider>
  442. </FlamegraphThemeProvider>
  443. </FlamegraphStateProvider>
  444. </ProfileGroupProvider>
  445. </ProfileVisualization>
  446. <ProfileDigestContainer>
  447. <ProfileDigestScrollContainer>
  448. <ProfileDigest />
  449. <MostRegressedProfileFunctions transaction={transaction} />
  450. <SlowestProfileFunctions transaction={transaction} />
  451. </ProfileDigestScrollContainer>
  452. </ProfileDigestContainer>
  453. </ProfileVisualizationContainer>
  454. )}
  455. </PageFiltersContainer>
  456. </ProfileSummaryContainer>
  457. </SentryDocumentTitle>
  458. );
  459. }
  460. const RequestStateMessageContainer = styled('div')`
  461. position: absolute;
  462. left: 0;
  463. right: 0;
  464. top: 0;
  465. bottom: 0;
  466. display: flex;
  467. justify-content: center;
  468. align-items: center;
  469. color: ${p => p.theme.subText};
  470. `;
  471. const AggregateFlamegraphContainer = styled('div')`
  472. display: flex;
  473. flex-direction: column;
  474. flex: 1 1 100%;
  475. height: 100%;
  476. width: 100%;
  477. overflow: hidden;
  478. position: absolute;
  479. left: 0px;
  480. top: 0px;
  481. `;
  482. interface AggregateFlamegraphToolbarProps {
  483. canvasPoolManager: CanvasPoolManager;
  484. frameFilter: 'system' | 'application' | 'all';
  485. hideSystemFrames: boolean;
  486. onFrameFilterChange: (value: 'system' | 'application' | 'all') => void;
  487. onVisualizationChange: (value: 'flamegraph' | 'call tree') => void;
  488. scheduler: CanvasScheduler;
  489. setHideSystemFrames: (value: boolean) => void;
  490. visualization: 'flamegraph' | 'call tree';
  491. }
  492. function AggregateFlamegraphToolbar(props: AggregateFlamegraphToolbarProps) {
  493. const flamegraph = useFlamegraph();
  494. const flamegraphs = useMemo(() => [flamegraph], [flamegraph]);
  495. const spans = useMemo(() => [], []);
  496. const frameSelectOptions: SelectOption<'system' | 'application' | 'all'>[] =
  497. useMemo(() => {
  498. return [
  499. {value: 'system', label: t('System Frames')},
  500. {value: 'application', label: t('Application Frames')},
  501. {value: 'all', label: t('All Frames')},
  502. ];
  503. }, []);
  504. const onResetZoom = useCallback(() => {
  505. props.scheduler.dispatch('reset zoom');
  506. }, [props.scheduler]);
  507. const onFrameFilterChange = useCallback(
  508. (value: {value: 'application' | 'system' | 'all'}) => {
  509. props.onFrameFilterChange(value.value);
  510. },
  511. [props]
  512. );
  513. return (
  514. <AggregateFlamegraphToolbarContainer>
  515. <ViewSelectContainer>
  516. <SegmentedControl
  517. aria-label={t('View')}
  518. size="xs"
  519. value={props.visualization}
  520. onChange={props.onVisualizationChange}
  521. >
  522. <SegmentedControl.Item key="flamegraph">
  523. {t('Flamegraph')}
  524. </SegmentedControl.Item>
  525. <SegmentedControl.Item key="call tree">{t('Call Tree')}</SegmentedControl.Item>
  526. </SegmentedControl>
  527. </ViewSelectContainer>
  528. <AggregateFlamegraphSearch
  529. spans={spans}
  530. canvasPoolManager={props.canvasPoolManager}
  531. flamegraphs={flamegraphs}
  532. />
  533. <Button size="xs" onClick={onResetZoom}>
  534. {t('Reset Zoom')}
  535. </Button>
  536. <CompactSelect
  537. onChange={onFrameFilterChange}
  538. value={props.frameFilter}
  539. size="xs"
  540. options={frameSelectOptions}
  541. />
  542. </AggregateFlamegraphToolbarContainer>
  543. );
  544. }
  545. const ViewSelectContainer = styled('div')`
  546. min-width: 160px;
  547. `;
  548. const AggregateFlamegraphToolbarContainer = styled('div')`
  549. display: flex;
  550. justify-content: space-between;
  551. gap: ${space(1)};
  552. padding: ${space(1)} ${space(0.5)};
  553. background-color: ${p => p.theme.background};
  554. /*
  555. force height to be the same as profile digest header,
  556. but subtract 1px for the border that doesnt exist on the header
  557. */
  558. height: 41px;
  559. `;
  560. const AggregateFlamegraphSearch = styled(FlamegraphSearch)`
  561. max-width: 300px;
  562. `;
  563. const ProfileVisualization = styled('div')`
  564. grid-area: visualization;
  565. position: relative;
  566. height: 100%;
  567. `;
  568. const ProfileDigestContainer = styled('div')`
  569. grid-area: digest;
  570. border-left: 1px solid ${p => p.theme.border};
  571. background-color: ${p => p.theme.background};
  572. display: flex;
  573. flex: 1 1 100%;
  574. flex-direction: column;
  575. position: relative;
  576. overflow: hidden;
  577. `;
  578. const ProfileDigestScrollContainer = styled('div')`
  579. position: absolute;
  580. left: 0;
  581. right: 0;
  582. top: 0;
  583. bottom: 0;
  584. display: flex;
  585. flex-direction: column;
  586. `;
  587. const ProfileVisualizationContainer = styled('div')`
  588. display: grid;
  589. grid-template-areas: 'visualization digest';
  590. grid-template-columns: 60% 40%;
  591. flex: 1 1 100%;
  592. `;
  593. const ProfileSummaryContainer = styled('div')`
  594. display: flex;
  595. flex-direction: column;
  596. flex: 1 1 100%;
  597. /*
  598. * The footer component is a sibling of this div.
  599. * Remove it so the flamegraph can take up the
  600. * entire screen.
  601. */
  602. ~ footer {
  603. display: none;
  604. }
  605. `;
  606. const PROFILE_DIGEST_FIELDS = [
  607. 'last_seen()',
  608. 'p75()',
  609. 'p95()',
  610. 'p99()',
  611. 'count()',
  612. ] satisfies ProfilingFieldType[];
  613. const percentiles = ['p75()', 'p95()', 'p99()'] as const;
  614. function ProfileDigest() {
  615. const location = useLocation();
  616. const profilesCursor = useMemo(
  617. () => decodeScalar(location.query.cursor),
  618. [location.query.cursor]
  619. );
  620. const profiles = useProfileEvents<ProfilingFieldType>({
  621. cursor: profilesCursor,
  622. fields: PROFILE_DIGEST_FIELDS,
  623. query: '',
  624. sort: {key: 'last_seen()', order: 'desc'},
  625. referrer: 'api.profiling.profile-summary-table',
  626. });
  627. const data = profiles.data?.data?.[0];
  628. return (
  629. <ProfileDigestHeader>
  630. <div>
  631. <ProfileDigestLabel>{t('Last Seen')}</ProfileDigestLabel>
  632. <div>
  633. {profiles.isLoading ? (
  634. ''
  635. ) : profiles.isError ? (
  636. ''
  637. ) : (
  638. <DateTime date={new Date(data?.['last_seen()'] as string)} />
  639. )}
  640. </div>
  641. </div>
  642. {percentiles.map(p => {
  643. return (
  644. <ProfileDigestColumn key={p}>
  645. <ProfileDigestLabel>{p}</ProfileDigestLabel>
  646. <div>
  647. {profiles.isLoading ? (
  648. ''
  649. ) : profiles.isError ? (
  650. ''
  651. ) : (
  652. <PerformanceDuration nanoseconds={data?.[p] as number} abbreviation />
  653. )}
  654. </div>
  655. </ProfileDigestColumn>
  656. );
  657. })}
  658. <ProfileDigestColumn>
  659. <ProfileDigestLabel>{t('profiles')}</ProfileDigestLabel>
  660. <div>
  661. {profiles.isLoading ? (
  662. ''
  663. ) : profiles.isError ? (
  664. ''
  665. ) : (
  666. <Count value={data?.['count()'] as number} />
  667. )}
  668. </div>
  669. </ProfileDigestColumn>
  670. </ProfileDigestHeader>
  671. );
  672. }
  673. const ProfileDigestColumn = styled('div')`
  674. text-align: right;
  675. `;
  676. const ProfileDigestHeader = styled('div')`
  677. display: flex;
  678. justify-content: space-between;
  679. align-items: center;
  680. padding: 0 ${space(1)};
  681. border-bottom: 1px solid ${p => p.theme.border};
  682. /* force height to be same as toolbar */
  683. height: 42px;
  684. flex-shrink: 0;
  685. `;
  686. const ProfileDigestLabel = styled('span')`
  687. color: ${p => p.theme.textColor};
  688. font-size: ${p => p.theme.fontSizeSmall};
  689. font-weight: 600;
  690. text-transform: uppercase;
  691. `;
  692. export default function ProfileSummaryPageToggle(props: ProfileSummaryPageProps) {
  693. const organization = useOrganization();
  694. if (organization.features.includes('profiling-summary-redesign')) {
  695. return (
  696. <ProfileSummaryContainer data-test-id="profile-summary-redesign">
  697. <ErrorBoundary>
  698. <ProfileSummaryPage {...props} />
  699. </ErrorBoundary>
  700. </ProfileSummaryContainer>
  701. );
  702. }
  703. return (
  704. <div data-test-id="profile-summary-legacy">
  705. <LegacySummaryPage {...props} />
  706. </div>
  707. );
  708. }