Skip to content

Commit 08bb8a2

Browse files
Johan K. Jensenwebkit-commit-queue
authored andcommitted
Web Inspector: Frontend should have access to Resource Timing information
https://bugs.webkit.org/show_bug.cgi?id=160095 Patch by Johan K. Jensen <johan_jensen@apple.com> on 2016-08-26 Reviewed by Alex Christensen. Source/JavaScriptCore: Rename ResourceTiming property. * inspector/protocol/Network.json: Rename navigationStart to startTime so it's applicable for all resources and not just the main resource. Source/WebCore: Show correct information with Resource Timing information from ResourceLoader rather than DocumentLoader. No new tests, frontend doesn't use the timing data yet. * inspector/InspectorNetworkAgent.cpp: (WebCore::InspectorNetworkAgent::buildObjectForTiming): (WebCore::InspectorNetworkAgent::buildObjectForResourceResponse): (WebCore::InspectorNetworkAgent::buildObjectForCachedResource): (WebCore::InspectorNetworkAgent::willSendRequest): (WebCore::InspectorNetworkAgent::didReceiveResponse): (WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache): (WebCore::buildObjectForTiming): Deleted. (WebCore::buildObjectForResourceResponse): Deleted. (WebCore::buildObjectForCachedResource): Deleted. Use ResourceLoader instead of DocumentLoader to get Resource Timing information. Move functions to member functions to access the executionStopWatch. (WebCore::InspectorNetworkAgent::didFinishLoading): Use the load timing finishTime and convert to elapsed time for frontend. * inspector/InspectorNetworkAgent.h: * loader/SubresourceLoader.cpp: (WebCore::SubresourceLoader::didFinishLoading): Pass the web process load timing on to the inspector. Source/WTF: Add method to get elapsed time for any monotonic time. Used by InspectorNetworkAgent. * wtf/Stopwatch.h: (WTF::Stopwatch::elapsedTimeSinceMonotonicTime): Canonical link: https://commits.webkit.org/179438@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205062 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9493fec commit 08bb8a2

8 files changed

Lines changed: 98 additions & 20 deletions

File tree

Source/JavaScriptCore/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2016-08-26 Johan K. Jensen <johan_jensen@apple.com>
2+
3+
Web Inspector: Frontend should have access to Resource Timing information
4+
https://bugs.webkit.org/show_bug.cgi?id=160095
5+
6+
Reviewed by Alex Christensen.
7+
8+
Rename ResourceTiming property.
9+
10+
* inspector/protocol/Network.json:
11+
Rename navigationStart to startTime so it's applicable
12+
for all resources and not just the main resource.
13+
114
2016-08-25 Joseph Pecoraro <pecoraro@apple.com>
215

316
Web Inspector: Provide a way to clear an IndexedDB object store

Source/JavaScriptCore/inspector/protocol/Network.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"type": "object",
3434
"description": "Timing information for the request.",
3535
"properties": [
36-
{ "name": "navigationStart", "type": "number", "description": "Timing's navigationStart is a baseline in seconds, while the other numbers are ticks in milliseconds relatively to this navigationStart." },
36+
{ "name": "startTime", "type": "number", "description": "Timing's startTime is a baseline in seconds, while the other numbers are ticks in milliseconds relatively to this." },
3737
{ "name": "domainLookupStart", "type": "number", "description": "Started DNS address resolve." },
3838
{ "name": "domainLookupEnd", "type": "number", "description": "Finished DNS address resolve." },
3939
{ "name": "connectStart", "type": "number", "description": "Started connecting to the remote host." },

Source/WTF/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2016-08-26 Johan K. Jensen <johan_jensen@apple.com>
2+
3+
Web Inspector: Frontend should have access to Resource Timing information
4+
https://bugs.webkit.org/show_bug.cgi?id=160095
5+
6+
Reviewed by Alex Christensen.
7+
8+
Add method to get elapsed time for any monotonic time.
9+
Used by InspectorNetworkAgent.
10+
11+
* wtf/Stopwatch.h:
12+
(WTF::Stopwatch::elapsedTimeSinceMonotonicTime):
13+
114
2016-08-26 Csaba Osztrogonác <ossy@webkit.org>
215

316
Fix the ENABLE(WEBASSEMBLY) build on Linux

Source/WTF/wtf/Stopwatch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Stopwatch : public RefCounted<Stopwatch> {
4343
void stop();
4444

4545
double elapsedTime();
46+
double elapsedTimeSinceMonotonicTime(double);
4647

4748
bool isActive() const { return !std::isnan(m_lastStartTime); }
4849
private:
@@ -81,6 +82,14 @@ inline double Stopwatch::elapsedTime()
8182
return m_elapsedTime + (monotonicallyIncreasingTime() - m_lastStartTime);
8283
}
8384

85+
inline double Stopwatch::elapsedTimeSinceMonotonicTime(double monotonicTime)
86+
{
87+
if (!isActive())
88+
return m_elapsedTime;
89+
90+
return m_elapsedTime + (monotonicTime - m_lastStartTime);
91+
}
92+
8493
} // namespace WTF
8594

8695
using WTF::Stopwatch;

Source/WebCore/ChangeLog

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
2016-08-26 Johan K. Jensen <johan_jensen@apple.com>
2+
3+
Web Inspector: Frontend should have access to Resource Timing information
4+
https://bugs.webkit.org/show_bug.cgi?id=160095
5+
6+
Reviewed by Alex Christensen.
7+
8+
Show correct information with Resource Timing information
9+
from ResourceLoader rather than DocumentLoader.
10+
11+
No new tests, frontend doesn't use the timing data yet.
12+
13+
* inspector/InspectorNetworkAgent.cpp:
14+
(WebCore::InspectorNetworkAgent::buildObjectForTiming):
15+
(WebCore::InspectorNetworkAgent::buildObjectForResourceResponse):
16+
(WebCore::InspectorNetworkAgent::buildObjectForCachedResource):
17+
(WebCore::InspectorNetworkAgent::willSendRequest):
18+
(WebCore::InspectorNetworkAgent::didReceiveResponse):
19+
(WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache):
20+
(WebCore::buildObjectForTiming): Deleted.
21+
(WebCore::buildObjectForResourceResponse): Deleted.
22+
(WebCore::buildObjectForCachedResource): Deleted.
23+
Use ResourceLoader instead of DocumentLoader to get Resource Timing information.
24+
Move functions to member functions to access the executionStopWatch.
25+
26+
(WebCore::InspectorNetworkAgent::didFinishLoading):
27+
Use the load timing finishTime and convert to elapsed time for frontend.
28+
29+
* inspector/InspectorNetworkAgent.h:
30+
* loader/SubresourceLoader.cpp:
31+
(WebCore::SubresourceLoader::didFinishLoading):
32+
Pass the web process load timing on to the inspector.
33+
134
2016-08-26 Chris Dumez <cdumez@apple.com>
235

336
Unreviewed, fix Windows build after r205048.

Source/WebCore/inspector/InspectorNetworkAgent.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ static Ref<InspectorObject> buildObjectForHeaders(const HTTPHeaderMap& headers)
184184
return headersObject;
185185
}
186186

187-
static Ref<Inspector::Protocol::Network::ResourceTiming> buildObjectForTiming(const NetworkLoadTiming& timing, DocumentLoader* loader)
187+
Ref<Inspector::Protocol::Network::ResourceTiming> InspectorNetworkAgent::buildObjectForTiming(const NetworkLoadTiming& timing, ResourceLoader& resourceLoader)
188188
{
189+
double monotonicTime = resourceLoader.loadTiming().startTime();
190+
double startTimeInInspector = m_environment.executionStopwatch()->elapsedTimeSinceMonotonicTime(monotonicTime);
191+
189192
return Inspector::Protocol::Network::ResourceTiming::create()
190-
.setNavigationStart(loader->timing().startTime())
193+
.setStartTime(startTimeInInspector)
191194
.setDomainLookupStart(timing.domainLookupStart)
192195
.setDomainLookupEnd(timing.domainLookupEnd)
193196
.setConnectStart(timing.connectStart)
@@ -213,7 +216,7 @@ static Ref<Inspector::Protocol::Network::Request> buildObjectForResourceRequest(
213216
return requestObject;
214217
}
215218

216-
static RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResponse(const ResourceResponse& response, DocumentLoader* loader)
219+
RefPtr<Inspector::Protocol::Network::Response> InspectorNetworkAgent::buildObjectForResourceResponse(const ResourceResponse& response, ResourceLoader* resourceLoader)
217220
{
218221
if (response.isNull())
219222
return nullptr;
@@ -230,20 +233,21 @@ static RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResp
230233
.release();
231234

232235
responseObject->setFromDiskCache(response.source() == ResourceResponse::Source::DiskCache || response.source() == ResourceResponse::Source::DiskCacheAfterValidation);
233-
responseObject->setTiming(buildObjectForTiming(response.networkLoadTiming(), loader));
236+
if (resourceLoader)
237+
responseObject->setTiming(buildObjectForTiming(response.networkLoadTiming(), *resourceLoader));
234238

235239
return WTFMove(responseObject);
236240
}
237241

238-
static Ref<Inspector::Protocol::Network::CachedResource> buildObjectForCachedResource(CachedResource* cachedResource, DocumentLoader* loader)
242+
Ref<Inspector::Protocol::Network::CachedResource> InspectorNetworkAgent::buildObjectForCachedResource(CachedResource* cachedResource)
239243
{
240244
auto resourceObject = Inspector::Protocol::Network::CachedResource::create()
241245
.setUrl(cachedResource->url())
242246
.setType(InspectorPageAgent::cachedResourceTypeJson(*cachedResource))
243247
.setBodySize(cachedResource->encodedSize())
244248
.release();
245249

246-
auto resourceResponse = buildObjectForResourceResponse(cachedResource->response(), loader);
250+
auto resourceResponse = buildObjectForResourceResponse(cachedResource->response(), cachedResource->loader());
247251
resourceObject->setResponse(WTFMove(resourceResponse));
248252

249253
String sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(cachedResource);
@@ -305,7 +309,7 @@ void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLo
305309
Inspector::Protocol::Page::ResourceType resourceType = InspectorPageAgent::resourceTypeJson(type);
306310

307311
RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
308-
m_frontendDispatcher->requestWillBeSent(requestId, m_pageAgent->frameId(loader.frame()), m_pageAgent->loaderId(&loader), loader.url().string(), buildObjectForResourceRequest(request), timestamp(), initiatorObject, buildObjectForResourceResponse(redirectResponse, &loader), type != InspectorPageAgent::OtherResource ? &resourceType : nullptr);
312+
m_frontendDispatcher->requestWillBeSent(requestId, m_pageAgent->frameId(loader.frame()), m_pageAgent->loaderId(&loader), loader.url().string(), buildObjectForResourceRequest(request), timestamp(), initiatorObject, buildObjectForResourceResponse(redirectResponse, nullptr), type != InspectorPageAgent::OtherResource ? &resourceType : nullptr);
309313
}
310314

311315
void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier)
@@ -322,7 +326,7 @@ void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, Documen
322326
return;
323327

324328
String requestId = IdentifiersFactory::requestId(identifier);
325-
RefPtr<Inspector::Protocol::Network::Response> resourceResponse = buildObjectForResourceResponse(response, &loader);
329+
RefPtr<Inspector::Protocol::Network::Response> resourceResponse = buildObjectForResourceResponse(response, resourceLoader);
326330

327331
bool isNotModified = response.httpStatusCode() == 304;
328332

@@ -390,18 +394,14 @@ void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentL
390394

391395
m_resourcesData->maybeDecodeDataToContent(requestId);
392396

393-
// FIXME: The finishTime that is passed in is from the NetworkProcess and is more accurate.
394-
// However, all other times passed to the Inspector are generated from the web process. Mixing
395-
// times from different processes can cause the finish time to be earlier than the response
396-
// received time due to inter-process communication lag.
397-
finishTime = timestamp();
397+
double elapsedFinishTime = finishTime ? m_environment.executionStopwatch()->elapsedTimeSinceMonotonicTime(finishTime) : timestamp();
398398

399399
String sourceMappingURL;
400400
NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->data(requestId);
401401
if (resourceData && resourceData->cachedResource())
402402
sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(resourceData->cachedResource());
403403

404-
m_frontendDispatcher->loadingFinished(requestId, finishTime, !sourceMappingURL.isEmpty() ? &sourceMappingURL : nullptr);
404+
m_frontendDispatcher->loadingFinished(requestId, elapsedFinishTime, !sourceMappingURL.isEmpty() ? &sourceMappingURL : nullptr);
405405
}
406406

407407
void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoader& loader, const ResourceError& error)
@@ -435,7 +435,7 @@ void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader& loade
435435

436436
RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
437437

438-
m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader.url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource, &loader));
438+
m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader.url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource));
439439
}
440440

441441
void InspectorNetworkAgent::setInitialScriptContent(unsigned long identifier, const String& sourceString)

Source/WebCore/inspector/InspectorNetworkAgent.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CachedResource;
4848
class Document;
4949
class DocumentLoader;
5050
class InspectorPageAgent;
51+
class NetworkLoadTiming;
5152
class NetworkResourcesData;
5253
class ResourceError;
5354
class ResourceLoader;
@@ -116,6 +117,10 @@ class InspectorNetworkAgent final : public InspectorAgentBase, public Inspector:
116117
private:
117118
void enable();
118119

120+
Ref<Inspector::Protocol::Network::ResourceTiming> buildObjectForTiming(const NetworkLoadTiming&, ResourceLoader&);
121+
RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResponse(const ResourceResponse&, ResourceLoader*);
122+
Ref<Inspector::Protocol::Network::CachedResource> buildObjectForCachedResource(CachedResource*);
123+
119124
double timestamp();
120125

121126
std::unique_ptr<Inspector::NetworkFrontendDispatcher> m_frontendDispatcher;

Source/WebCore/loader/SubresourceLoader.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,23 +460,28 @@ void SubresourceLoader::didFinishLoading(double finishTime)
460460
Ref<SubresourceLoader> protectedThis(*this);
461461
CachedResourceHandle<CachedResource> protectResource(m_resource);
462462

463-
finishTime = monotonicallyIncreasingTime();
464-
m_loadTiming.setResponseEnd(finishTime);
463+
// FIXME: The finishTime that is passed in is from the NetworkProcess and is more accurate.
464+
// However, all other load times are generated from the web process or offsets.
465+
// Mixing times from different processes can cause the finish time to be earlier than
466+
// the response received time due to inter-process communication lag.
467+
UNUSED_PARAM(finishTime);
468+
double responseEndTime = monotonicallyIncreasingTime();
469+
m_loadTiming.setResponseEnd(responseEndTime);
465470

466471
#if ENABLE(WEB_TIMING)
467472
if (m_documentLoader->cachedResourceLoader().document() && RuntimeEnabledFeatures::sharedFeatures().resourceTimingEnabled())
468473
m_documentLoader->cachedResourceLoader().resourceTimingInformation().addResourceTiming(m_resource, *m_documentLoader->cachedResourceLoader().document(), m_resource->loader()->loadTiming());
469474
#endif
470475

471476
m_state = Finishing;
472-
m_resource->setLoadFinishTime(finishTime);
477+
m_resource->setLoadFinishTime(responseEndTime); // FIXME: Users of the loadFinishTime should use the LoadTiming struct instead.
473478
m_resource->finishLoading(resourceData());
474479

475480
if (wasCancelled())
476481
return;
477482
m_resource->finish();
478483
ASSERT(!reachedTerminalState());
479-
didFinishLoadingOnePart(finishTime);
484+
didFinishLoadingOnePart(responseEndTime);
480485
notifyDone();
481486
if (reachedTerminalState())
482487
return;

0 commit comments

Comments
 (0)