Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et tw=80 : */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : // HttpLog.h should generally be included first
8 : #include "HttpLog.h"
9 :
10 : #include "nsHttpConnectionMgr.h"
11 : #include "nsHttpConnection.h"
12 : #include "Http2Session.h"
13 : #include "nsHttpHandler.h"
14 : #include "nsIConsoleService.h"
15 : #include "nsHttpRequestHead.h"
16 : #include "nsServiceManagerUtils.h"
17 : #include "nsSocketTransportService2.h"
18 :
19 : #include "mozilla/IntegerPrintfMacros.h"
20 : #include "mozilla/SizePrintfMacros.h"
21 :
22 : namespace mozilla {
23 : namespace net {
24 :
25 : void
26 0 : nsHttpConnectionMgr::PrintDiagnostics()
27 : {
28 0 : nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgPrintDiagnostics, 0, nullptr);
29 0 : if (NS_FAILED(rv)) {
30 0 : LOG(("nsHttpConnectionMgr::PrintDiagnostics\n"
31 : " failed to post OnMsgPrintDiagnostics event"));
32 : }
33 0 : }
34 :
35 : void
36 0 : nsHttpConnectionMgr::OnMsgPrintDiagnostics(int32_t, ARefBase *)
37 : {
38 0 : MOZ_ASSERT(OnSocketThread(), "not on socket thread");
39 :
40 : nsCOMPtr<nsIConsoleService> consoleService =
41 0 : do_GetService(NS_CONSOLESERVICE_CONTRACTID);
42 0 : if (!consoleService)
43 0 : return;
44 :
45 0 : mLogData.AppendPrintf("HTTP Connection Diagnostics\n---------------------\n");
46 0 : mLogData.AppendPrintf("IsSpdyEnabled() = %d\n", gHttpHandler->IsSpdyEnabled());
47 0 : mLogData.AppendPrintf("MaxSocketCount() = %d\n", gHttpHandler->MaxSocketCount());
48 0 : mLogData.AppendPrintf("mNumActiveConns = %d\n", mNumActiveConns);
49 0 : mLogData.AppendPrintf("mNumIdleConns = %d\n", mNumIdleConns);
50 :
51 0 : for (auto iter = mCT.Iter(); !iter.Done(); iter.Next()) {
52 0 : nsAutoPtr<nsConnectionEntry>& ent = iter.Data();
53 :
54 0 : mLogData.AppendPrintf(" ent host = %s hashkey = %s\n",
55 0 : ent->mConnInfo->Origin(), ent->mConnInfo->HashKey().get());
56 0 : mLogData.AppendPrintf(" AtActiveConnectionLimit = %d\n",
57 0 : AtActiveConnectionLimit(ent, NS_HTTP_ALLOW_KEEPALIVE));
58 0 : mLogData.AppendPrintf(" RestrictConnections = %d\n",
59 0 : RestrictConnections(ent));
60 0 : mLogData.AppendPrintf(" Pending Q Length = %" PRIuSIZE "\n",
61 0 : ent->PendingQLength());
62 0 : mLogData.AppendPrintf(" Active Conns Length = %" PRIuSIZE "\n",
63 0 : ent->mActiveConns.Length());
64 0 : mLogData.AppendPrintf(" Idle Conns Length = %" PRIuSIZE "\n",
65 0 : ent->mIdleConns.Length());
66 0 : mLogData.AppendPrintf(" Half Opens Length = %" PRIuSIZE "\n",
67 0 : ent->mHalfOpens.Length());
68 0 : mLogData.AppendPrintf(" Coalescing Keys Length = %" PRIuSIZE "\n",
69 0 : ent->mCoalescingKeys.Length());
70 0 : mLogData.AppendPrintf(" Spdy using = %d\n", ent->mUsingSpdy);
71 :
72 : uint32_t i;
73 0 : for (i = 0; i < ent->mActiveConns.Length(); ++i) {
74 0 : mLogData.AppendPrintf(" :: Active Connection #%u\n", i);
75 0 : ent->mActiveConns[i]->PrintDiagnostics(mLogData);
76 : }
77 0 : for (i = 0; i < ent->mIdleConns.Length(); ++i) {
78 0 : mLogData.AppendPrintf(" :: Idle Connection #%u\n", i);
79 0 : ent->mIdleConns[i]->PrintDiagnostics(mLogData);
80 : }
81 0 : for (i = 0; i < ent->mHalfOpens.Length(); ++i) {
82 0 : mLogData.AppendPrintf(" :: Half Open #%u\n", i);
83 0 : ent->mHalfOpens[i]->PrintDiagnostics(mLogData);
84 : }
85 0 : i = 0;
86 0 : for (auto it = ent->mPendingTransactionTable.Iter();
87 0 : !it.Done();
88 0 : it.Next()) {
89 0 : mLogData.AppendPrintf(" :: Pending Transactions with Window ID = %"
90 0 : PRIu64 "\n", it.Key());
91 0 : for (uint32_t j = 0; j < it.UserData()->Length(); ++j) {
92 0 : mLogData.AppendPrintf(" ::: Pending Transaction #%u\n", i);
93 0 : it.UserData()->ElementAt(j)->PrintDiagnostics(mLogData);
94 0 : ++i;
95 : }
96 : }
97 0 : for (i = 0; i < ent->mCoalescingKeys.Length(); ++i) {
98 0 : mLogData.AppendPrintf(" :: Coalescing Key #%u %s\n",
99 0 : i, ent->mCoalescingKeys[i].get());
100 : }
101 : }
102 :
103 0 : consoleService->LogStringMessage(NS_ConvertUTF8toUTF16(mLogData).Data());
104 0 : mLogData.Truncate();
105 : }
106 :
107 : void
108 0 : nsHttpConnectionMgr::nsHalfOpenSocket::PrintDiagnostics(nsCString &log)
109 : {
110 0 : log.AppendPrintf(" has connected = %d, isSpeculative = %d\n",
111 0 : HasConnected(), IsSpeculative());
112 :
113 0 : TimeStamp now = TimeStamp::Now();
114 :
115 0 : if (mPrimarySynStarted.IsNull())
116 0 : log.AppendPrintf(" primary not started\n");
117 : else
118 0 : log.AppendPrintf(" primary started %.2fms ago\n",
119 0 : (now - mPrimarySynStarted).ToMilliseconds());
120 :
121 0 : if (mBackupSynStarted.IsNull())
122 0 : log.AppendPrintf(" backup not started\n");
123 : else
124 0 : log.AppendPrintf(" backup started %.2f ago\n",
125 0 : (now - mBackupSynStarted).ToMilliseconds());
126 :
127 0 : log.AppendPrintf(" primary transport %d, backup transport %d\n",
128 0 : !!mSocketTransport.get(), !!mBackupTransport.get());
129 0 : }
130 :
131 : void
132 0 : nsHttpConnection::PrintDiagnostics(nsCString &log)
133 : {
134 0 : log.AppendPrintf(" CanDirectlyActivate = %d\n", CanDirectlyActivate());
135 :
136 0 : log.AppendPrintf(" npncomplete = %d setupSSLCalled = %d\n",
137 0 : mNPNComplete, mSetupSSLCalled);
138 :
139 0 : log.AppendPrintf(" spdyVersion = %d reportedSpdy = %d everspdy = %d\n",
140 0 : mUsingSpdyVersion, mReportedSpdy, mEverUsedSpdy);
141 :
142 0 : log.AppendPrintf(" iskeepalive = %d dontReuse = %d isReused = %d\n",
143 0 : IsKeepAlive(), mDontReuse, mIsReused);
144 :
145 0 : log.AppendPrintf(" mTransaction = %d mSpdySession = %d\n",
146 0 : !!mTransaction.get(), !!mSpdySession.get());
147 :
148 0 : PRIntervalTime now = PR_IntervalNow();
149 0 : log.AppendPrintf(" time since last read = %ums\n",
150 0 : PR_IntervalToMilliseconds(now - mLastReadTime));
151 :
152 0 : log.AppendPrintf(" max-read/read/written %" PRId64 "/%" PRId64 "/%" PRId64 "\n",
153 0 : mMaxBytesRead, mTotalBytesRead, mTotalBytesWritten);
154 :
155 0 : log.AppendPrintf(" rtt = %ums\n", PR_IntervalToMilliseconds(mRtt));
156 :
157 0 : log.AppendPrintf(" idlemonitoring = %d transactionCount=%d\n",
158 0 : mIdleMonitoring, mHttp1xTransactionCount);
159 :
160 0 : if (mSpdySession)
161 0 : mSpdySession->PrintDiagnostics(log);
162 0 : }
163 :
164 : void
165 0 : Http2Session::PrintDiagnostics(nsCString &log)
166 : {
167 0 : log.AppendPrintf(" ::: HTTP2\n");
168 0 : log.AppendPrintf(" shouldgoaway = %d mClosed = %d CanReuse = %d nextID=0x%X\n",
169 0 : mShouldGoAway, mClosed, CanReuse(), mNextStreamID);
170 :
171 0 : log.AppendPrintf(" concurrent = %d maxconcurrent = %d\n",
172 0 : mConcurrent, mMaxConcurrent);
173 :
174 0 : log.AppendPrintf(" roomformorestreams = %d roomformoreconcurrent = %d\n",
175 0 : RoomForMoreStreams(), RoomForMoreConcurrent());
176 :
177 0 : log.AppendPrintf(" transactionHashCount = %d streamIDHashCount = %d\n",
178 : mStreamTransactionHash.Count(),
179 0 : mStreamIDHash.Count());
180 :
181 0 : log.AppendPrintf(" Queued Stream Size = %" PRIuSIZE "\n", mQueuedStreams.GetSize());
182 :
183 0 : PRIntervalTime now = PR_IntervalNow();
184 0 : log.AppendPrintf(" Ping Threshold = %ums\n",
185 0 : PR_IntervalToMilliseconds(mPingThreshold));
186 0 : log.AppendPrintf(" Ping Timeout = %ums\n",
187 0 : PR_IntervalToMilliseconds(gHttpHandler->SpdyPingTimeout()));
188 0 : log.AppendPrintf(" Idle for Any Activity (ping) = %ums\n",
189 0 : PR_IntervalToMilliseconds(now - mLastReadEpoch));
190 0 : log.AppendPrintf(" Idle for Data Activity = %ums\n",
191 0 : PR_IntervalToMilliseconds(now - mLastDataReadEpoch));
192 0 : if (mPingSentEpoch)
193 0 : log.AppendPrintf(" Ping Outstanding (ping) = %ums, expired = %d\n",
194 0 : PR_IntervalToMilliseconds(now - mPingSentEpoch),
195 0 : now - mPingSentEpoch >= gHttpHandler->SpdyPingTimeout());
196 : else
197 0 : log.AppendPrintf(" No Ping Outstanding\n");
198 0 : }
199 :
200 : void
201 0 : nsHttpTransaction::PrintDiagnostics(nsCString &log)
202 : {
203 0 : if (!mRequestHead)
204 0 : return;
205 :
206 0 : nsAutoCString requestURI;
207 0 : mRequestHead->RequestURI(requestURI);
208 0 : log.AppendPrintf(" :::: uri = %s\n", requestURI.get());
209 0 : log.AppendPrintf(" caps = 0x%x\n", mCaps);
210 0 : log.AppendPrintf(" priority = %d\n", mPriority);
211 0 : log.AppendPrintf(" restart count = %u\n", mRestartCount);
212 : }
213 :
214 : void
215 0 : nsHttpConnectionMgr::PendingTransactionInfo::PrintDiagnostics(nsCString &log)
216 : {
217 0 : log.AppendPrintf(" ::: Pending transaction\n");
218 0 : mTransaction->PrintDiagnostics(log);
219 0 : RefPtr<nsHalfOpenSocket> halfOpen = do_QueryReferent(mHalfOpen);
220 0 : log.AppendPrintf(" Waiting for half open sock: %p or connection: %p\n",
221 0 : halfOpen.get(), mActiveConn.get());
222 0 : }
223 :
224 : } // namespace net
225 : } // namespace mozilla
|