From b1924cbae2afece812c3c0625ad14e6a7875f28e Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Fri, 20 Dec 2024 14:22:27 +0100 Subject: [PATCH] feat: plug collected performance measures into the export --- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/libs/Performance.tsx | 5 +++++ .../settings/Troubleshoot/TroubleshootPage.tsx | 13 +++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 49b1a973897c..8c36f88c7605 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1259,7 +1259,7 @@ const translations = { maskExportOnyxStateData: 'Mask fragile member data while exporting Onyx state', exportOnyxState: 'Export Onyx state', importOnyxState: 'Import Onyx state', - exportPerformanceMetrics: 'Export performance metrics', + exportPerformanceData: 'Export performance data', testCrash: 'Test crash', resetToOriginalState: 'Reset to original state', usingImportedState: 'You are using imported state. Press here to clear it.', diff --git a/src/languages/es.ts b/src/languages/es.ts index fd85fac9b147..65f2af9000b7 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1258,7 +1258,7 @@ const translations = { maskExportOnyxStateData: 'Enmascare los datos frágiles del miembro mientras exporta el estado Onyx', exportOnyxState: 'Exportar estado Onyx', importOnyxState: 'Importar estado Onyx', - exportPerformanceMetrics: 'Exportar métricas de rendimiento', + exportPerformanceData: 'Exportar datos de rendimiento', testCrash: 'Prueba de fallo', resetToOriginalState: 'Restablecer al estado original', usingImportedState: 'Estás utilizando el estado importado. Pulsa aquí para borrarlo.', diff --git a/src/libs/Performance.tsx b/src/libs/Performance.tsx index ef2b08e47229..4547e13f3cef 100644 --- a/src/libs/Performance.tsx +++ b/src/libs/Performance.tsx @@ -23,6 +23,7 @@ type BlankHOC =

>(Component: React.ComponentTy type SetupPerformanceObserver = () => void; type DiffObject = (object: Record, base: Record) => Record; type GetPerformanceMetrics = () => PerformanceEntry[]; +type GetPerformanceMeasures = () => PerformanceEntry[]; type PrintPerformanceMetrics = () => void; type MarkStart = (name: string, detail?: Record) => PerformanceMark | void; type MarkEnd = (name: string, detail?: Record) => PerformanceMark | void; @@ -36,6 +37,7 @@ type PerformanceModule = { diffObject: DiffObject; setupPerformanceObserver: SetupPerformanceObserver; getPerformanceMetrics: GetPerformanceMetrics; + getPerformanceMeasures: GetPerformanceMeasures; printPerformanceMetrics: PrintPerformanceMetrics; markStart: MarkStart; markEnd: MarkEnd; @@ -70,6 +72,7 @@ const Performance: PerformanceModule = { // When performance monitoring is disabled the implementations are blank diffObject, setupPerformanceObserver: () => {}, + getPerformanceMeasures: () => [], getPerformanceMetrics: () => [], printPerformanceMetrics: () => {}, markStart: () => {}, @@ -168,6 +171,8 @@ if (Metrics.canCapturePerformanceMetrics()) { }).observe({type: 'mark', buffered: true}); }; + Performance.getPerformanceMeasures = (): PerformanceEntry[] => rnPerformance.getEntriesByType('measure'); + Performance.getPerformanceMetrics = (): PerformanceEntry[] => [ ...rnPerformance.getEntriesByName('nativeLaunch'), diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index fedfc8a19a73..ebda3975b3b3 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -29,6 +29,7 @@ import {setShouldMaskOnyxState} from '@libs/actions/MaskOnyx'; import ExportOnyxState from '@libs/ExportOnyxState'; import localFileDownload from '@libs/localFileDownload'; import Navigation from '@libs/Navigation/Navigation'; +import Performance from '@libs/Performance'; import {clearOnyxAndResetApp} from '@userActions/App'; import * as Report from '@userActions/Report'; import type {TranslationPaths} from '@src/languages/types'; @@ -62,9 +63,9 @@ function TroubleshootPage() { }); }, [shouldMaskOnyxState]); - const exportPerformanceMetrics = useCallback(() => { - const data = {metrics: []}; - localFileDownload('performance-metrics', JSON.stringify(data, null, 2)); + const exportPerformanceData = useCallback(() => { + const measures = Performance.getPerformanceMeasures(); + localFileDownload('performance-data', JSON.stringify(measures)); }, []); const menuItems = useMemo(() => { @@ -86,9 +87,9 @@ function TroubleshootPage() { action: exportOnyxState, }, { - translationKey: 'initialSettingsPage.troubleshoot.exportPerformanceMetrics', + translationKey: 'initialSettingsPage.troubleshoot.exportPerformanceData', icon: Expensicons.Download, - action: exportPerformanceMetrics, + action: exportPerformanceData, }, ]; @@ -105,7 +106,7 @@ function TroubleshootPage() { wrapperStyle: [styles.sectionMenuItemTopDescription], })) .reverse(); - }, [waitForNavigate, exportOnyxState, exportPerformanceMetrics, shouldStoreLogs, translate, styles.sectionMenuItemTopDescription]); + }, [waitForNavigate, exportOnyxState, exportPerformanceData, shouldStoreLogs, translate, styles.sectionMenuItemTopDescription]); return (