regressedProfileFunctions.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {useCallback, useMemo} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import Pagination from 'sentry/components/pagination';
  4. import {useProfileFunctionTrends} from 'sentry/utils/profiling/hooks/useProfileFunctionTrends';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. const MAX_REGRESSED_FUNCTIONS = 5;
  9. const REGRESSIONS_CURSOR = 'functionRegressionCursor';
  10. interface MostRegressedProfileFunctionsProps {
  11. transaction: string;
  12. }
  13. export function MostRegressedProfileFunctions(props: MostRegressedProfileFunctionsProps) {
  14. const location = useLocation();
  15. const fnTrendCursor = useMemo(
  16. () => decodeScalar(location.query[REGRESSIONS_CURSOR]),
  17. [location.query]
  18. );
  19. const handleRegressedFunctionsCursor = useCallback((cursor, pathname, query) => {
  20. browserHistory.push({
  21. pathname,
  22. query: {...query, [REGRESSIONS_CURSOR]: cursor},
  23. });
  24. }, []);
  25. const functionQuery = useMemo(() => {
  26. const conditions = new MutableSearch('');
  27. conditions.setFilterValues('is_application', ['1']);
  28. conditions.setFilterValues('transaction', [props.transaction]);
  29. return conditions.formatString();
  30. }, [props.transaction]);
  31. const trendsQuery = useProfileFunctionTrends({
  32. trendFunction: 'p95()',
  33. trendType: 'regression',
  34. query: functionQuery,
  35. limit: MAX_REGRESSED_FUNCTIONS,
  36. cursor: fnTrendCursor,
  37. });
  38. return (
  39. <div>
  40. Most regressed functions
  41. <Pagination
  42. pageLinks={trendsQuery.getResponseHeader?.('Link')}
  43. onCursor={handleRegressedFunctionsCursor}
  44. size="xs"
  45. />
  46. <div>
  47. {trendsQuery.isLoading && 'Loading...'}
  48. {!trendsQuery.isLoading &&
  49. trendsQuery?.data?.map((t, i) => <div key={i}>{t.function}</div>)}
  50. </div>
  51. </div>
  52. );
  53. }