index.tsx 26 KB

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