Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perfTotal and duration has same docs, same as networkConnect and sentRequest [BUG] #2359

Closed
vmachacek opened this issue Jun 5, 2024 · 3 comments

Comments

@vmachacek
Copy link

Description/Screenshot

when looking into TS docs I see this

image

Why perfTotal and duration has same documentation? Are they same properties with different name?

same goes for networkConnect and sentRequest

Expected behavior

docs would mention nuances between those two pairs (if applicable)

@MSNev
Copy link
Collaborator

MSNev commented Jun 5, 2024

No these are not the same, the actual format "G" is however.

This was generated code from a very long time ago, I tend to point people at this to clarify what they are as the values are derived from the browser reported metrics with the same (or simular) names

/*
* https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API
* | -startTime
* | -redirectStart
* | | -redirectEnd
* | | | -fetchStart
* | | | | -domainLookupStart
* | | | | |- domainLookupEnd
* | | | | | | -connectStart
* | | | | | | | -secureConnectionStart
* | | | | | | | | -connectEnd
* | | | | | | | | | -requestStart
* | | | | | | | | | | | -responseStart
* | | | | | | | | | | | | | -responseEnd
* +------------+-+---+----------------+-+--+--------+-+-----------+-+------------+-+
* |--redirect--| |---|--domainLookup--| |--connect--| |--request--| |--response--| |
* |-------------------networkConnect----------------|
* | |---------sentRequest--------|
* |------------------------------------perfTotal-----------------------------------|
*/

@MSNev
Copy link
Collaborator

MSNev commented Jun 5, 2024

While these are for the Dependency requests vs the identified Page View values. So the standard documentation might provide some better values https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming

@vmachacek
Copy link
Author

vmachacek commented Jun 6, 2024

@MSNev thanks

this is code I ended up using for mapping

const log = {
    name: resourceTiming.name,
    uri: window.location.href,
    duration: this.convertToTimeSpan(resourceTiming.duration),
    networkConnect: this.convertToTimeSpan(resourceTiming.connectEnd - resourceTiming.startTime),
    sentRequest: this.convertToTimeSpan(resourceTiming.responseEnd - resourceTiming.requestStart),
    receivedResponse: this.convertToTimeSpan(resourceTiming.responseEnd - resourceTiming.responseStart),
    perfTotal: this.convertToTimeSpan(resourceTiming.responseEnd - resourceTiming.startTime)
};

convertToTimeSpan(milliseconds: number): string {
        const totalSeconds = milliseconds / 1000;
        const days = Math.floor(totalSeconds / 86400);
        const hours = Math.floor((totalSeconds % 86400) / 3600);
        const minutes = Math.floor((totalSeconds % 3600) / 60);
        const seconds = (totalSeconds % 60).toFixed(7);

        return `${days}:${this.pad(hours, 2)}:${this.pad(minutes, 2)}:${this.pad(seconds, 10)}`;
    }

    // Helper function to pad numbers with leading zeros
    pad(num: number | string, size: number): string {
        let s = num.toString();
        while (s.length < size) {
            s = "0" + s;
        }
        return s;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants