Add performance marksf or individual fetch() requests (#22176)

This commit is contained in:
Brian Vaughn
2021-08-26 09:19:00 -04:00
committed by GitHub
parent 87a1f82ef2
commit a7b3062003
@@ -451,6 +451,10 @@ function extractAndLoadSourceMaps(
}
function fetchFile(url: string): Promise<string> {
if (__PERFORMANCE_PROFILE__) {
mark('fetchFile("' + url + '")');
}
return new Promise((resolve, reject) => {
fetch(url).then(
response => {
@@ -458,18 +462,27 @@ function fetchFile(url: string): Promise<string> {
response
.text()
.then(text => {
if (__PERFORMANCE_PROFILE__) {
measure('fetchFile("' + url + '")');
}
resolve(text);
})
.catch(error => {
if (__DEBUG__) {
console.log(`fetchFile() Could not read text for url "${url}"`);
}
if (__PERFORMANCE_PROFILE__) {
measure('fetchFile("' + url + '")');
}
reject(null);
});
} else {
if (__DEBUG__) {
console.log(`fetchFile() Got bad response for url "${url}"`);
}
if (__PERFORMANCE_PROFILE__) {
measure('fetchFile("' + url + '")');
}
reject(null);
}
},
@@ -477,6 +490,9 @@ function fetchFile(url: string): Promise<string> {
if (__DEBUG__) {
console.log(`fetchFile() Could not fetch file: ${error.message}`);
}
if (__PERFORMANCE_PROFILE__) {
measure('fetchFile("' + url + '")');
}
reject(null);
},
);