index.tsx 23 KB

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