Skip to content

Commit

Permalink
add perf markers
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBurnside authored Mar 6, 2024
1 parent 9f55109 commit c0e4b89
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
3 changes: 1 addition & 2 deletions common/config/webpack/sampleapp.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const webpackConfig = (sampleAppDir, env, babelConfig) => {
entry: {
build: './src/index.tsx'
},
mode: env.production ? 'production' : 'development',
...(env.production || !env.development ? {} : { devtool: 'eval-source-map' }),
mode: 'production',
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: env.production ? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { VideoStreamOptions, CreateVideoStreamViewResult, ViewScalingMode } from '../../types';

/** @private */
Expand Down Expand Up @@ -49,8 +49,18 @@ const useVideoStreamLifecycleMaintainer = (
scalingMode
} = props;

const wasVideoStreamViewAvailable = useRef(false);
const [videoStreamViewResult, setVideoStreamViewResult] = useState<CreateVideoStreamViewResult | undefined>();

useEffect(() => {
performance.mark('videoStreamView-notAvailable');
}, []);

if (wasVideoStreamViewAvailable.current === false && videoStreamViewResult) {
wasVideoStreamViewAvailable.current = true;
performance.mark('videoStreamView-available');
}

useEffect(() => {
if (isStreamAvailable && !renderElementExists) {
onCreateStreamView?.({ isMirrored, scalingMode })?.then((result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ const MainScreen = (props: MainScreenProps): JSX.Element => {
<ConfigurationPage
mobileView={props.mobileView}
startCallHandler={(): void => {
console.log('perftests-startCall');
performance.mark('perftests-startCall');
if (callees) {
adapter.startCall(callees);
} else {
Expand Down
46 changes: 45 additions & 1 deletion samples/CallWithChat/src/app/views/CallScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { TeamsMeetingLinkLocator } from '@azure/communication-calling';
import { CallState, TeamsMeetingLinkLocator } from '@azure/communication-calling';
import { CommunicationUserIdentifier } from '@azure/communication-common';
import {
toFlatCommunicationIdentifier,
Expand All @@ -22,6 +22,9 @@ import { WEB_APP_TITLE } from '../utils/constants';
import { useIsMobile } from '../utils/useIsMobile';
import { isIOS } from '../utils/utils';

// eslint-disable-next-line no-var, @typescript-eslint/no-explicit-any
var pageTimings = (window as any)._pageTimings || ((window as any)._pageTimings = {});

export interface CallScreenProps {
token: string;
userId: CommunicationUserIdentifier;
Expand Down Expand Up @@ -115,6 +118,9 @@ export const CallScreen = (props: CallScreenProps): JSX.Element => {
[userId, token]
);

const callStatus = useRef<CallState>('None');
const remoteParticipantIdsWithVideosReadys = useRef<unknown[]>([]);

const afterAdapterCreate = useCallback(
async (adapter: CallWithChatAdapter): Promise<CallWithChatAdapter> => {
adapter.on('callError', (e) => {
Expand All @@ -135,6 +141,44 @@ export const CallScreen = (props: CallScreenProps): JSX.Element => {
callIdRef.current = state?.call?.id;
console.log(`Call Id: ${callIdRef.current}`);
}

if (state?.call?.state) {
if (state.call.state !== callStatus.current) {
callStatus.current = state.call.state;
performance.mark(`callStateChange-${callStatus.current}`);
console.log(`Call State: ${callStatus.current}`);
}
}

if (state.call?.remoteParticipants) {
const remoteParticipants = state.call.remoteParticipants;
const participantsWithVideosReady = Object.values(remoteParticipants)
.filter((participant) => {
const streams = Object.values(participant.videoStreams);
const videoStreamsReady = streams.some(
(stream) => stream.mediaStreamType === 'Video' && !!stream.view?.target
);
return videoStreamsReady;
})
.map((participant) => participant.identifier);

const newParticipantsWithVideosReady = participantsWithVideosReady.filter(
(participant) => !remoteParticipantIdsWithVideosReadys.current.includes(participant)
);

newParticipantsWithVideosReady.forEach((participant) => {
remoteParticipantIdsWithVideosReadys.current.push(participant);
performance.mark(`remoteParticipantVideoReady-${participant}`);
console.log(`Remote participant with video ready: ${participant}`);

// update page timings
// Collect perf metrics from page and add them to pageTimings object
performance.getEntriesByType('mark').forEach((perfMark) => {
pageTimings[perfMark.name] = Math.round(perfMark.startTime);
});
console.log('Page Timings:', pageTimings);
});
}
});
return adapter;
},
Expand Down

0 comments on commit c0e4b89

Please sign in to comment.