content.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {Fragment, useCallback, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import {CompactSelect} from 'sentry/components/compactSelect';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import Pagination from 'sentry/components/pagination';
  8. import {AggregateFlamegraphPanel} from 'sentry/components/profiling/aggregateFlamegraphPanel';
  9. import {ProfileEventsTable} from 'sentry/components/profiling/profileEventsTable';
  10. import {SuspectFunctionsTable} from 'sentry/components/profiling/suspectFunctions/suspectFunctionsTable';
  11. import {mobile} from 'sentry/data/platformCategories';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import {PageFilters, Project} from 'sentry/types';
  15. import {useProfileEvents} from 'sentry/utils/profiling/hooks/useProfileEvents';
  16. import {formatSort} from 'sentry/utils/profiling/hooks/utils';
  17. import {decodeScalar} from 'sentry/utils/queryString';
  18. import {ProfilesChart} from 'sentry/views/profiling/landing/profileCharts';
  19. interface ProfileSummaryContentProps {
  20. location: Location;
  21. project: Project;
  22. query: string;
  23. selection: PageFilters;
  24. transaction: string;
  25. }
  26. function ProfileSummaryContent(props: ProfileSummaryContentProps) {
  27. const fields = useMemo(
  28. () => getProfilesTableFields(props.project.platform),
  29. [props.project]
  30. );
  31. const profilesCursor = useMemo(
  32. () => decodeScalar(props.location.query.cursor),
  33. [props.location.query.cursor]
  34. );
  35. const sort = formatSort<ProfilingFieldType>(
  36. decodeScalar(props.location.query.sort),
  37. fields,
  38. {
  39. key: 'timestamp',
  40. order: 'desc',
  41. }
  42. );
  43. const profiles = useProfileEvents<ProfilingFieldType>({
  44. cursor: profilesCursor,
  45. fields,
  46. query: props.query,
  47. sort,
  48. limit: 5,
  49. referrer: 'api.profiling.profile-summary-table',
  50. });
  51. const handleFilterChange = useCallback(
  52. value => {
  53. browserHistory.push({
  54. ...props.location,
  55. query: {...props.location.query, cursor: undefined, sort: value},
  56. });
  57. },
  58. [props.location]
  59. );
  60. return (
  61. <Fragment>
  62. <Layout.Main fullWidth>
  63. <ProfilesChart
  64. referrer="api.profiling.profile-summary-chart"
  65. query={props.query}
  66. hideCount
  67. compact
  68. />
  69. <AggregateFlamegraphPanel transaction={props.transaction} />
  70. <SuspectFunctionsTable
  71. project={props.project}
  72. transaction={props.transaction}
  73. analyticsPageSource="profiling_transaction"
  74. />
  75. <TableHeader>
  76. <CompactSelect
  77. triggerProps={{prefix: t('Filter'), size: 'xs'}}
  78. value={sort.order === 'asc' ? sort.key : `-${sort.key}`}
  79. options={FILTER_OPTIONS}
  80. onChange={opt => handleFilterChange(opt.value)}
  81. />
  82. <StyledPagination
  83. pageLinks={
  84. profiles.status === 'success'
  85. ? profiles.getResponseHeader?.('Link') ?? null
  86. : null
  87. }
  88. size="xs"
  89. />
  90. </TableHeader>
  91. <ProfileEventsTable
  92. columns={fields}
  93. data={profiles.status === 'success' ? profiles.data : null}
  94. error={profiles.status === 'error' ? t('Unable to load profiles') : null}
  95. isLoading={profiles.status === 'loading'}
  96. sort={sort}
  97. />
  98. </Layout.Main>
  99. </Fragment>
  100. );
  101. }
  102. const ALL_FIELDS = [
  103. 'profile.id',
  104. 'timestamp',
  105. 'release',
  106. 'device.model',
  107. 'device.classification',
  108. 'device.arch',
  109. 'transaction.duration',
  110. 'p75()',
  111. 'p95()',
  112. 'p99()',
  113. 'count()',
  114. 'last_seen()',
  115. ] as const;
  116. export type ProfilingFieldType = (typeof ALL_FIELDS)[number];
  117. export function getProfilesTableFields(platform: Project['platform']) {
  118. if (mobile.includes(platform as any)) {
  119. return MOBILE_FIELDS;
  120. }
  121. return DEFAULT_FIELDS;
  122. }
  123. const MOBILE_FIELDS: ProfilingFieldType[] = [
  124. 'profile.id',
  125. 'timestamp',
  126. 'release',
  127. 'device.model',
  128. 'device.classification',
  129. 'device.arch',
  130. 'transaction.duration',
  131. ];
  132. const DEFAULT_FIELDS: ProfilingFieldType[] = [
  133. 'profile.id',
  134. 'timestamp',
  135. 'release',
  136. 'transaction.duration',
  137. ];
  138. const FILTER_OPTIONS = [
  139. {
  140. label: t('Recent Profiles'),
  141. value: '-timestamp',
  142. },
  143. {
  144. label: t('Slowest Profiles'),
  145. value: '-transaction.duration',
  146. },
  147. {
  148. label: t('Fastest Profiles'),
  149. value: 'transaction.duration',
  150. },
  151. ];
  152. const TableHeader = styled('div')`
  153. display: flex;
  154. justify-content: space-between;
  155. margin-bottom: ${space(1)};
  156. `;
  157. const StyledPagination = styled(Pagination)`
  158. margin: 0 0 0 ${space(1)};
  159. `;
  160. export {ProfileSummaryContent};