Bug 1497236 - serialize timings for socket process
authorJunior Hsu <juhsu@mozilla.com>
Tue, 22 Jan 2019 14:54:12 +0800
changeset 448031 e6a2c240ec8b8cc48869299595445dabbb3a3544
parent 448030 167739a37b93e4b1563e9ef2cc882270278115a6
child 448032 4b8b2c3e9188dab0b7a3191a4043aebd2901ecad
push id26
push userjuhsu@mozilla.com
push dateMon, 28 Jan 2019 05:00:22 +0000
bugs1497236
milestone66.0a1
Bug 1497236 - serialize timings for socket process Reviewers: kershaw Reviewed By: kershaw Bug #: 1497236 Differential Revision: https://phabricator.services.mozilla.com/D15615
netwerk/ipc/NeckoMessageUtils.h
netwerk/protocol/http/HttpTransactionChild.cpp
netwerk/protocol/http/HttpTransactionParent.cpp
netwerk/protocol/http/HttpTransactionParent.h
netwerk/protocol/http/PHttpTransaction.ipdl
--- a/netwerk/ipc/NeckoMessageUtils.h
+++ b/netwerk/ipc/NeckoMessageUtils.h
@@ -127,20 +127,53 @@ struct ParamTraits<mozilla::net::NetAddr
 #endif
     }
 
     /* We've been tricked by some socket family we don't know about! */
     return false;
   }
 };
 
-template <>
-struct ParamTraits<mozilla::net::ResourceTimingStruct> {
+template<>
+struct ParamTraits<mozilla::net::TimingStruct>
+{
+  static void Write(Message* aMsg, const mozilla::net::TimingStruct& aParam)
+  {
+    WriteParam(aMsg, aParam.domainLookupStart);
+    WriteParam(aMsg, aParam.domainLookupEnd);
+    WriteParam(aMsg, aParam.connectStart);
+    WriteParam(aMsg, aParam.tcpConnectEnd);
+    WriteParam(aMsg, aParam.secureConnectionStart);
+    WriteParam(aMsg, aParam.connectEnd);
+    WriteParam(aMsg, aParam.requestStart);
+    WriteParam(aMsg, aParam.responseStart);
+    WriteParam(aMsg, aParam.responseEnd);
+  }
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter,
+                   mozilla::net::TimingStruct* aResult)
+  {
+    return ReadParam(aMsg, aIter, &aResult->domainLookupStart) &&
+           ReadParam(aMsg, aIter, &aResult->domainLookupEnd) &&
+           ReadParam(aMsg, aIter, &aResult->connectStart) &&
+           ReadParam(aMsg, aIter, &aResult->tcpConnectEnd) &&
+           ReadParam(aMsg, aIter, &aResult->secureConnectionStart) &&
+           ReadParam(aMsg, aIter, &aResult->connectEnd) &&
+           ReadParam(aMsg, aIter, &aResult->requestStart) &&
+           ReadParam(aMsg, aIter, &aResult->responseStart) &&
+           ReadParam(aMsg, aIter, &aResult->responseEnd);
+  }
+};
+
+template<>
+struct ParamTraits<mozilla::net::ResourceTimingStruct>
+{
   static void Write(Message* aMsg,
-                    const mozilla::net::ResourceTimingStruct& aParam) {
+                    const mozilla::net::ResourceTimingStruct& aParam)
+  {
     WriteParam(aMsg, aParam.domainLookupStart);
     WriteParam(aMsg, aParam.domainLookupEnd);
     WriteParam(aMsg, aParam.connectStart);
     WriteParam(aMsg, aParam.tcpConnectEnd);
     WriteParam(aMsg, aParam.secureConnectionStart);
     WriteParam(aMsg, aParam.connectEnd);
     WriteParam(aMsg, aParam.requestStart);
     WriteParam(aMsg, aParam.responseStart);
--- a/netwerk/protocol/http/HttpTransactionChild.cpp
+++ b/netwerk/protocol/http/HttpTransactionChild.cpp
@@ -232,32 +232,35 @@ HttpTransactionChild::OnStartRequest(nsI
   } else {
     optionalHead = mozilla::void_t();
   }
   Unused << SendOnStartRequest(status,
                                optionalHead,
                                serializedSecurityInfoOut,
                                mSelfAddr,
                                mPeerAddr,
-                               mTransaction->ProxyConnectFailed());
+                               mTransaction->ProxyConnectFailed(),
+                               mTransaction->Timings());
   LOG(("HttpTransactionChild::OnStartRequest end [this=%p]\n", this));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpTransactionChild::OnStopRequest(nsIRequest* aRequest,
                                     nsISupports* aContext,
                                     nsresult aStatus)
 {
   LOG(("HttpTransactionChild::OnStopRequest [this=%p]\n", this));
   MOZ_ASSERT(mTransaction);
 
   Unused << SendOnStopRequest(aStatus,
                               mTransaction->ResponseIsComplete(),
-                              mTransaction->GetTransferSize());
+                              mTransaction->GetTransferSize(),
+                              mTransaction->Timings());
+
   mTransaction = nullptr;
   mTransactionPump = nullptr;
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // HttpTransactionChild <nsITransportEventSink>
 //-----------------------------------------------------------------------------
--- a/netwerk/protocol/http/HttpTransactionParent.cpp
+++ b/netwerk/protocol/http/HttpTransactionParent.cpp
@@ -167,27 +167,51 @@ HttpTransactionParent::GetNetworkAddress
   peer = mPeerAddr;
 }
 
 // TODO: propogate the sticky information from socket process
 bool HttpTransactionParent::IsStickyConnection() {
   return false;
 }
 
-// TODO: serialize the timing. Dummy implementation for compliablity only.
-mozilla::TimeStamp HttpTransactionParent::GetDomainLookupStart() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetDomainLookupEnd() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetConnectStart() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetTcpConnectEnd() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetSecureConnectionStart() { return TimeStamp(); }
+mozilla::TimeStamp HttpTransactionParent::GetDomainLookupStart() {
+  return mTimings.domainLookupStart;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetDomainLookupEnd() {
+  return mTimings.domainLookupEnd;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetConnectStart() {
+  return mTimings.connectStart;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetTcpConnectEnd() {
+  return mTimings.tcpConnectEnd;
+}
 
-mozilla::TimeStamp HttpTransactionParent::GetConnectEnd() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetRequestStart() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetResponseStart() { return TimeStamp(); }
-mozilla::TimeStamp HttpTransactionParent::GetResponseEnd() { return TimeStamp(); }
+mozilla::TimeStamp HttpTransactionParent::GetSecureConnectionStart() {
+  return mTimings.secureConnectionStart;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetConnectEnd() {
+  return mTimings.connectEnd;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetRequestStart() {
+  return mTimings.requestStart;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetResponseStart() {
+  return mTimings.responseStart;
+}
+
+mozilla::TimeStamp HttpTransactionParent::GetResponseEnd() {
+  return mTimings.responseEnd;
+}
 
 bool HttpTransactionParent::ResponseIsComplete()
 {
   return mResponseIsComplete;
 }
 
 int64_t HttpTransactionParent::GetTransferSize()
 {
@@ -211,17 +235,18 @@ HttpTransactionParent::AddIPDLReference(
 }
 
 mozilla::ipc::IPCResult
 HttpTransactionParent::RecvOnStartRequest(const nsresult& aStatus,
                                           const OptionalHttpResponseHead& aResponseHead,
                                           const nsCString& aSecurityInfoSerialization,
                                           const NetAddr& aSelfAddr,
                                           const NetAddr& aPeerAddr,
-                                          const bool& aProxyConnectFailed)
+                                          const bool& aProxyConnectFailed,
+                                          const TimingStruct& aTimings)
 {
   LOG(("HttpTransactionParent::RecvOnStartRequest [this=%p aStatus=%" PRIx32 "]\n",
        this, static_cast<uint32_t>(aStatus)));
 
   if (!mCanceled && NS_SUCCEEDED(mStatus)) {
     mStatus = aStatus;
   }
 
@@ -231,16 +256,17 @@ HttpTransactionParent::RecvOnStartReques
   }
 
   if (aResponseHead.type() == OptionalHttpResponseHead::TnsHttpResponseHead) {
     mResponseHead = new nsHttpResponseHead(aResponseHead.get_nsHttpResponseHead());
   }
   mProxyConnectFailed = aProxyConnectFailed;
   mSelfAddr = aSelfAddr;
   mPeerAddr = aPeerAddr;
+  mTimings = aTimings;
 
   nsCOMPtr<nsIStreamListener> chan = mChannel;
 
   nsresult rv = chan->OnStartRequest(this, nullptr);
   if (NS_FAILED(rv)) {
     Cancel(rv);
   }
   return IPC_OK();
@@ -288,29 +314,31 @@ HttpTransactionParent::RecvOnDataAvailab
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 HttpTransactionParent::RecvOnStopRequest(const nsresult& aStatus,
                                          const bool& aResponseIsComplete,
-                                         const int64_t& aTransferSize)
+                                         const int64_t& aTransferSize,
+                                         const TimingStruct& aTimings)
 {
   LOG(("HttpTransactionParent::RecvOnStopRequest [this=%p status=%" PRIx32 "]\n",
        this, static_cast<uint32_t>(aStatus)));
 
   if (!mCanceled && NS_SUCCEEDED(mStatus)) {
     mStatus = aStatus;
   }
 
   nsCOMPtr<nsIRequest> deathGrip = this;
 
   mResponseIsComplete = aResponseIsComplete;
   mTransferSize = aTransferSize;
+  mTimings = aTimings;
 
   nsCOMPtr<nsIStreamListener> chan = mChannel;
   Unused << chan->OnStopRequest(this, nullptr, mStatus);
 
   // We are done with this transaction after OnStopRequest.
   Unused << Send__delete__(this);
   return IPC_OK();
 }
--- a/netwerk/protocol/http/HttpTransactionParent.h
+++ b/netwerk/protocol/http/HttpTransactionParent.h
@@ -39,29 +39,31 @@ public:
   void AddIPDLReference();
 
   mozilla::ipc::IPCResult
   RecvOnStartRequest(const nsresult& aStatus,
                      const OptionalHttpResponseHead& aResponseHead,
                      const nsCString& aSecurityInfoSerialization,
                      const NetAddr& aSelfAddr,
                      const NetAddr& aPeerAddr,
-                     const bool& aProxyConnectFailed) override;
+                     const bool& aProxyConnectFailed,
+                     const TimingStruct& aTimings) override;
   mozilla::ipc::IPCResult
   RecvOnTransportStatus(const nsresult& aStatus,
                         const int64_t& aProgress,
                         const int64_t& aProgressMax) override;
   mozilla::ipc::IPCResult
   RecvOnDataAvailable(const nsCString& aData,
                       const uint64_t& aOffset,
                       const uint32_t& aCount) override;
   mozilla::ipc::IPCResult
   RecvOnStopRequest(const nsresult& aStatus,
                     const bool& aResponseIsComplete,
-                    const int64_t& aTransferSize) override;
+                    const int64_t& aTransferSize,
+                    const TimingStruct& aTimings) override;
 
 private:
   virtual ~HttpTransactionParent();
 
   void GetStructFromInfo(nsHttpConnectionInfo* aInfo, HttpConnectionInfoCloneArgs &aArgs);
 
   nsCOMPtr<nsITransportEventSink> mEventsink;
   nsCOMPtr<nsIStreamListener> mChannel;
@@ -76,14 +78,16 @@ private:
 
   nsLoadFlags mLoadFlags = LOAD_NORMAL;
   bool mProxyConnectFailed = false;
   bool mCanceled = false;
   nsresult mStatus = NS_OK;
 
   NetAddr mSelfAddr;
   NetAddr mPeerAddr;
+
+  TimingStruct mTimings;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // nsHttpTransactionParent_h__
--- a/netwerk/protocol/http/PHttpTransaction.ipdl
+++ b/netwerk/protocol/http/PHttpTransaction.ipdl
@@ -6,42 +6,47 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PSocketProcess;
 include protocol PFileDescriptorSet; // FIXME: bug #792908
 
 include IPCStream;
 include NeckoChannelParams;
 
+include "mozilla/net/NeckoMessageUtils.h";
+
 using class mozilla::net::nsHttpRequestHead from "nsHttpRequestHead.h";
 using mozilla::net::NetAddr from "mozilla/net/DNS.h";
+using struct mozilla::net::TimingStruct from "mozilla/net/TimingStruct.h";
 
 namespace mozilla {
 namespace net {
 
 protocol PHttpTransaction
 {
   manager PSocketProcess;
 
 parent:
   async OnStartRequest(nsresult                   status,
                        OptionalHttpResponseHead   responseHead,
                        nsCString                  securityInfoSerialization,
                        NetAddr                    selfAddr,
                        NetAddr                    peerAddr,
-                       bool                       proxyConnectFailed);
+                       bool                       proxyConnectFailed,
+                       TimingStruct               timings);
   async OnTransportStatus(nsresult status,
                           int64_t progress,
                           int64_t progressMax);
   async OnDataAvailable(nsCString data,
                         uint64_t  offset,
                         uint32_t  count);
   async OnStopRequest(nsresult status,
                       bool responseIsComplete,
-                      int64_t transferSize);
+                      int64_t transferSize,
+                      TimingStruct timings);
 
 child:
   async __delete__();
   async Init(uint32_t caps,
              HttpConnectionInfoCloneArgs aArgs,
              nsHttpRequestHead reqHeaders,
              OptionalIPCStream requestBody,
              uint64_t reqContentLength,