UNPKG

@datadog/mobile-react-native

Version:

A client-side React Native module to interact with Datadog

36 lines (34 loc) 1.3 kB
/* * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. * This product includes software developed at Datadog (https://www.datadoghq.com/). * Copyright 2016-Present Datadog, Inc. */ import { Platform } from 'react-native'; export function createTimings(startTime, responseStartTime, responseEndTime) { const firstByte = formatTiming(startTime, startTime, responseStartTime); const download = formatTiming(startTime, responseStartTime, responseEndTime); // needed for iOS, simply total duration from start to end const fetch = formatTiming(startTime, startTime, responseEndTime); return { firstByte, download, fetch }; } /** * @param origin Start time (absolute) of the request * @param start Start time (absolute) of the timing * @param end End time (absolute) of the timing */ function formatTiming(origin, start, end) { return { duration: timeToNanos(end - start), // if it is Android, startTime should be relative to the origin, // if it is iOS - absolute (unix timestamp) startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin) }; } function timeToNanos(durationMs) { return +(durationMs * 1e6).toFixed(0); } //# sourceMappingURL=resourceTiming.js.map