Skip to content

Commit

Permalink
feat: plug collected performance measures into the export
Browse files Browse the repository at this point in the history
  • Loading branch information
adhorodyski committed Dec 20, 2024
1 parent 85ae9f8 commit b1924cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Performance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type BlankHOC = <P extends Record<string, unknown>>(Component: React.ComponentTy
type SetupPerformanceObserver = () => void;
type DiffObject = (object: Record<string, unknown>, base: Record<string, unknown>) => Record<string, unknown>;
type GetPerformanceMetrics = () => PerformanceEntry[];
type GetPerformanceMeasures = () => PerformanceEntry[];
type PrintPerformanceMetrics = () => void;
type MarkStart = (name: string, detail?: Record<string, unknown>) => PerformanceMark | void;
type MarkEnd = (name: string, detail?: Record<string, unknown>) => PerformanceMark | void;
Expand All @@ -36,6 +37,7 @@ type PerformanceModule = {
diffObject: DiffObject;
setupPerformanceObserver: SetupPerformanceObserver;
getPerformanceMetrics: GetPerformanceMetrics;
getPerformanceMeasures: GetPerformanceMeasures;
printPerformanceMetrics: PrintPerformanceMetrics;
markStart: MarkStart;
markEnd: MarkEnd;
Expand Down Expand Up @@ -70,6 +72,7 @@ const Performance: PerformanceModule = {
// When performance monitoring is disabled the implementations are blank
diffObject,
setupPerformanceObserver: () => {},
getPerformanceMeasures: () => [],
getPerformanceMetrics: () => [],
printPerformanceMetrics: () => {},
markStart: () => {},
Expand Down Expand Up @@ -168,6 +171,8 @@ if (Metrics.canCapturePerformanceMetrics()) {
}).observe({type: 'mark', buffered: true});
};

Performance.getPerformanceMeasures = (): PerformanceEntry[] => rnPerformance.getEntriesByType('measure');

Performance.getPerformanceMetrics = (): PerformanceEntry[] =>
[
...rnPerformance.getEntriesByName('nativeLaunch'),
Expand Down
13 changes: 7 additions & 6 deletions src/pages/settings/Troubleshoot/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(() => {
Expand All @@ -86,9 +87,9 @@ function TroubleshootPage() {
action: exportOnyxState,
},
{
translationKey: 'initialSettingsPage.troubleshoot.exportPerformanceMetrics',
translationKey: 'initialSettingsPage.troubleshoot.exportPerformanceData',
icon: Expensicons.Download,
action: exportPerformanceMetrics,
action: exportPerformanceData,
},
];

Expand All @@ -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 (
<ScreenWrapper
Expand Down

0 comments on commit b1924cb

Please sign in to comment.