forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API and scaffolding for Performance.mark implementation
Summary: [Changelog][Internal] Adds API definition for [Performance.mark](https://www.w3.org/TR/user-timing/#mark-method) support. This is a bare bone implementation, that just logs events on the native side. The next step is the native logic for queuing, flushing etc. Note that here I route both JS and native marks to native for now, for simplicity sake - ultimately this may not be what we want, as it may be more efficient to process marks, logged from JS, on the JS side. Reviewed By: rubennorte Differential Revision: D41472148 fbshipit-source-id: bdf2b182b8472a71a5500235849bca5af1c2f360
- Loading branch information
Showing
5 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow strict | ||
*/ | ||
|
||
import type {HighResTimeStamp} from './PerformanceObserver'; | ||
|
||
import NativePerformanceObserver, { | ||
RawPerformanceEntryTypeValues, | ||
} from './NativePerformanceObserver'; | ||
import {PerformanceEntry} from './PerformanceObserver'; | ||
|
||
type DetailType = mixed; | ||
|
||
export type PerformanceMarkOptions = { | ||
detail?: DetailType, | ||
startTime?: HighResTimeStamp, | ||
}; | ||
|
||
function getCurrentTimeStamp(): HighResTimeStamp { | ||
return global.nativePerformanceNow?.() ?? Date.now(); | ||
} | ||
|
||
export class PerformanceMark extends PerformanceEntry { | ||
detail: DetailType; | ||
|
||
constructor(markName: string, markOptions?: PerformanceMarkOptions) { | ||
let startTime = markOptions?.startTime ?? getCurrentTimeStamp(); | ||
super({name: markName, entryType: 'mark', startTime, duration: 0}); | ||
if (markOptions !== undefined) { | ||
this.detail = markOptions.detail; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Partial implementation of the Performance interface for RN, | ||
* corresponding to the standard in | ||
* https://www.w3.org/TR/user-timing/#extensions-performance-interface | ||
*/ | ||
export default class Performance { | ||
mark( | ||
markName: string, | ||
markOptions?: PerformanceMarkOptions, | ||
): PerformanceMark { | ||
const mark = new PerformanceMark(markName, markOptions); | ||
NativePerformanceObserver?.logEntryForDebug?.({ | ||
name: markName, | ||
entryType: RawPerformanceEntryTypeValues.MARK, | ||
startTime: mark.startTime, | ||
duration: mark.duration, | ||
}); | ||
return mark; | ||
} | ||
|
||
clearMarks(markName?: string): void {} | ||
|
||
now(): HighResTimeStamp { | ||
return getCurrentTimeStamp(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters