signal-desktop/ts/components/Profiler.tsx

37 lines
808 B
TypeScript
Raw Normal View History

2021-08-11 16:06:20 -07:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2025-04-29 13:27:33 -07:00
import type { ProfilerOnRenderCallback, ReactNode } from 'react';
import React from 'react';
2025-06-16 11:59:31 -07:00
import { createLogger } from '../logging/log';
const log = createLogger('Profiler');
2021-08-11 16:06:20 -07:00
export type PropsType = Readonly<{
id: string;
children: ReactNode;
}>;
2025-04-29 13:27:33 -07:00
const onRender: ProfilerOnRenderCallback = (
2021-08-11 16:06:20 -07:00
id,
phase,
actual,
base,
start,
commit
) => {
log.info(
2025-06-16 11:59:31 -07:00
`tsx(${id}): actual=${actual.toFixed(1)}ms phase=${phase} ` +
2021-08-11 16:06:20 -07:00
`base=${base.toFixed(1)}ms start=${start.toFixed(1)}ms ` +
`commit=${commit.toFixed(1)}ms`
);
};
2022-11-17 16:45:19 -08:00
export function Profiler({ id, children }: PropsType): JSX.Element {
2021-08-11 16:06:20 -07:00
return (
2023-10-24 12:53:20 -04:00
<React.Profiler id={id} onRender={onRender}>
2021-08-11 16:06:20 -07:00
{children}
2023-10-24 12:53:20 -04:00
</React.Profiler>
2021-08-11 16:06:20 -07:00
);
2022-11-17 16:45:19 -08:00
}