|
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 "SpdySession3.h" |
|
13 #include "SpdySession31.h" |
|
14 #include "Http2Session.h" |
|
15 #include "nsHttpHandler.h" |
|
16 #include "nsIConsoleService.h" |
|
17 #include "nsHttpRequestHead.h" |
|
18 |
|
19 extern PRThread *gSocketThread; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace net { |
|
23 |
|
24 void |
|
25 nsHttpConnectionMgr::PrintDiagnostics() |
|
26 { |
|
27 PostEvent(&nsHttpConnectionMgr::OnMsgPrintDiagnostics, 0, nullptr); |
|
28 } |
|
29 |
|
30 void |
|
31 nsHttpConnectionMgr::OnMsgPrintDiagnostics(int32_t, void *) |
|
32 { |
|
33 MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); |
|
34 |
|
35 nsCOMPtr<nsIConsoleService> consoleService = |
|
36 do_GetService(NS_CONSOLESERVICE_CONTRACTID); |
|
37 if (!consoleService) |
|
38 return; |
|
39 |
|
40 mLogData.AppendPrintf("HTTP Connection Diagnostics\n---------------------\n"); |
|
41 mLogData.AppendPrintf("IsSpdyEnabled() = %d\n", gHttpHandler->IsSpdyEnabled()); |
|
42 mLogData.AppendPrintf("MaxSocketCount() = %d\n", gHttpHandler->MaxSocketCount()); |
|
43 mLogData.AppendPrintf("mNumActiveConns = %d\n", mNumActiveConns); |
|
44 mLogData.AppendPrintf("mNumIdleConns = %d\n", mNumIdleConns); |
|
45 |
|
46 mCT.Enumerate(PrintDiagnosticsCB, this); |
|
47 |
|
48 consoleService->LogStringMessage(NS_ConvertUTF8toUTF16(mLogData).Data()); |
|
49 mLogData.Truncate(); |
|
50 } |
|
51 |
|
52 PLDHashOperator |
|
53 nsHttpConnectionMgr::PrintDiagnosticsCB(const nsACString &key, |
|
54 nsAutoPtr<nsConnectionEntry> &ent, |
|
55 void *closure) |
|
56 { |
|
57 nsHttpConnectionMgr *self = static_cast<nsHttpConnectionMgr *>(closure); |
|
58 uint32_t i; |
|
59 |
|
60 self->mLogData.AppendPrintf(" ent host = %s hashkey = %s\n", |
|
61 ent->mConnInfo->Host(), ent->mConnInfo->HashKey().get()); |
|
62 self->mLogData.AppendPrintf(" AtActiveConnectionLimit = %d\n", |
|
63 self->AtActiveConnectionLimit(ent, NS_HTTP_ALLOW_KEEPALIVE)); |
|
64 self->mLogData.AppendPrintf(" RestrictConnections = %d\n", |
|
65 self->RestrictConnections(ent)); |
|
66 self->mLogData.AppendPrintf(" Pending Q Length = %u\n", |
|
67 ent->mPendingQ.Length()); |
|
68 self->mLogData.AppendPrintf(" Active Conns Length = %u\n", |
|
69 ent->mActiveConns.Length()); |
|
70 self->mLogData.AppendPrintf(" Idle Conns Length = %u\n", |
|
71 ent->mIdleConns.Length()); |
|
72 self->mLogData.AppendPrintf(" Half Opens Length = %u\n", |
|
73 ent->mHalfOpens.Length()); |
|
74 self->mLogData.AppendPrintf(" Coalescing Key = %s\n", |
|
75 ent->mCoalescingKey.get()); |
|
76 self->mLogData.AppendPrintf(" Spdy using = %d, tested = %d, preferred = %d\n", |
|
77 ent->mUsingSpdy, ent->mTestedSpdy, ent->mSpdyPreferred); |
|
78 self->mLogData.AppendPrintf(" pipelinestate = %d penalty = %d\n", |
|
79 ent->mPipelineState, ent->mPipeliningPenalty); |
|
80 for (i = 0; i < nsAHttpTransaction::CLASS_MAX; ++i) { |
|
81 self->mLogData.AppendPrintf(" pipeline per class penalty 0x%x %d\n", |
|
82 i, ent->mPipeliningClassPenalty[i]); |
|
83 } |
|
84 for (i = 0; i < ent->mActiveConns.Length(); ++i) { |
|
85 self->mLogData.AppendPrintf(" :: Active Connection #%u\n", i); |
|
86 ent->mActiveConns[i]->PrintDiagnostics(self->mLogData); |
|
87 } |
|
88 for (i = 0; i < ent->mIdleConns.Length(); ++i) { |
|
89 self->mLogData.AppendPrintf(" :: Idle Connection #%u\n", i); |
|
90 ent->mIdleConns[i]->PrintDiagnostics(self->mLogData); |
|
91 } |
|
92 for (i = 0; i < ent->mHalfOpens.Length(); ++i) { |
|
93 self->mLogData.AppendPrintf(" :: Half Open #%u\n", i); |
|
94 ent->mHalfOpens[i]->PrintDiagnostics(self->mLogData); |
|
95 } |
|
96 for (i = 0; i < ent->mPendingQ.Length(); ++i) { |
|
97 self->mLogData.AppendPrintf(" :: Pending Transaction #%u\n", i); |
|
98 ent->mPendingQ[i]->PrintDiagnostics(self->mLogData); |
|
99 } |
|
100 |
|
101 return PL_DHASH_NEXT; |
|
102 } |
|
103 |
|
104 void |
|
105 nsHttpConnectionMgr::nsHalfOpenSocket::PrintDiagnostics(nsCString &log) |
|
106 { |
|
107 log.AppendPrintf(" has connected = %d, isSpeculative = %d\n", |
|
108 HasConnected(), IsSpeculative()); |
|
109 |
|
110 TimeStamp now = TimeStamp::Now(); |
|
111 |
|
112 if (mPrimarySynStarted.IsNull()) |
|
113 log.AppendPrintf(" primary not started\n"); |
|
114 else |
|
115 log.AppendPrintf(" primary started %.2fms ago\n", |
|
116 (now - mPrimarySynStarted).ToMilliseconds()); |
|
117 |
|
118 if (mBackupSynStarted.IsNull()) |
|
119 log.AppendPrintf(" backup not started\n"); |
|
120 else |
|
121 log.AppendPrintf(" backup started %.2f ago\n", |
|
122 (now - mBackupSynStarted).ToMilliseconds()); |
|
123 |
|
124 log.AppendPrintf(" primary transport %d, backup transport %d\n", |
|
125 !!mSocketTransport.get(), !!mBackupTransport.get()); |
|
126 } |
|
127 |
|
128 void |
|
129 nsHttpConnection::PrintDiagnostics(nsCString &log) |
|
130 { |
|
131 log.AppendPrintf(" CanDirectlyActivate = %d\n", CanDirectlyActivate()); |
|
132 |
|
133 log.AppendPrintf(" npncomplete = %d setupSSLCalled = %d\n", |
|
134 mNPNComplete, mSetupSSLCalled); |
|
135 |
|
136 log.AppendPrintf(" spdyVersion = %d reportedSpdy = %d everspdy = %d\n", |
|
137 mUsingSpdyVersion, mReportedSpdy, mEverUsedSpdy); |
|
138 |
|
139 log.AppendPrintf(" iskeepalive = %d dontReuse = %d isReused = %d\n", |
|
140 IsKeepAlive(), mDontReuse, mIsReused); |
|
141 |
|
142 log.AppendPrintf(" mTransaction = %d mSpdySession = %d\n", |
|
143 !!mTransaction.get(), !!mSpdySession.get()); |
|
144 |
|
145 PRIntervalTime now = PR_IntervalNow(); |
|
146 log.AppendPrintf(" time since last read = %ums\n", |
|
147 PR_IntervalToMilliseconds(now - mLastReadTime)); |
|
148 |
|
149 log.AppendPrintf(" max-read/read/written %lld/%lld/%lld\n", |
|
150 mMaxBytesRead, mTotalBytesRead, mTotalBytesWritten); |
|
151 |
|
152 log.AppendPrintf(" rtt = %ums\n", PR_IntervalToMilliseconds(mRtt)); |
|
153 |
|
154 log.AppendPrintf(" idlemonitoring = %d transactionCount=%d\n", |
|
155 mIdleMonitoring, mHttp1xTransactionCount); |
|
156 |
|
157 log.AppendPrintf(" supports pipeline = %d classification = 0x%x\n", |
|
158 mSupportsPipelining, mClassification); |
|
159 |
|
160 if (mSpdySession) |
|
161 mSpdySession->PrintDiagnostics(log); |
|
162 } |
|
163 |
|
164 |
|
165 void |
|
166 SpdySession3::PrintDiagnostics(nsCString &log) |
|
167 { |
|
168 log.AppendPrintf(" ::: SPDY VERSION 3\n"); |
|
169 log.AppendPrintf(" shouldgoaway = %d mClosed = %d CanReuse = %d nextID=0x%X\n", |
|
170 mShouldGoAway, mClosed, CanReuse(), mNextStreamID); |
|
171 |
|
172 log.AppendPrintf(" concurrent = %d maxconcurrent = %d\n", |
|
173 mConcurrent, mMaxConcurrent); |
|
174 |
|
175 log.AppendPrintf(" roomformorestreams = %d roomformoreconcurrent = %d\n", |
|
176 RoomForMoreStreams(), RoomForMoreConcurrent()); |
|
177 |
|
178 log.AppendPrintf(" transactionHashCount = %d streamIDHashCount = %d\n", |
|
179 mStreamTransactionHash.Count(), |
|
180 mStreamIDHash.Count()); |
|
181 |
|
182 log.AppendPrintf(" Queued Stream Size = %d\n", mQueuedStreams.GetSize()); |
|
183 |
|
184 PRIntervalTime now = PR_IntervalNow(); |
|
185 log.AppendPrintf(" Ping Threshold = %ums next ping id = 0x%X\n", |
|
186 PR_IntervalToMilliseconds(mPingThreshold), |
|
187 mNextPingID); |
|
188 log.AppendPrintf(" Ping Timeout = %ums\n", |
|
189 PR_IntervalToMilliseconds(gHttpHandler->SpdyPingTimeout())); |
|
190 log.AppendPrintf(" Idle for Any Activity (ping) = %ums\n", |
|
191 PR_IntervalToMilliseconds(now - mLastReadEpoch)); |
|
192 log.AppendPrintf(" Idle for Data Activity = %ums\n", |
|
193 PR_IntervalToMilliseconds(now - mLastDataReadEpoch)); |
|
194 if (mPingSentEpoch) |
|
195 log.AppendPrintf(" Ping Outstanding (ping) = %ums, expired = %d\n", |
|
196 PR_IntervalToMilliseconds(now - mPingSentEpoch), |
|
197 now - mPingSentEpoch >= gHttpHandler->SpdyPingTimeout()); |
|
198 else |
|
199 log.AppendPrintf(" No Ping Outstanding\n"); |
|
200 } |
|
201 |
|
202 void |
|
203 SpdySession31::PrintDiagnostics(nsCString &log) |
|
204 { |
|
205 log.AppendPrintf(" ::: SPDY VERSION 3.1\n"); |
|
206 log.AppendPrintf(" shouldgoaway = %d mClosed = %d CanReuse = %d nextID=0x%X\n", |
|
207 mShouldGoAway, mClosed, CanReuse(), mNextStreamID); |
|
208 |
|
209 log.AppendPrintf(" concurrent = %d maxconcurrent = %d\n", |
|
210 mConcurrent, mMaxConcurrent); |
|
211 |
|
212 log.AppendPrintf(" roomformorestreams = %d roomformoreconcurrent = %d\n", |
|
213 RoomForMoreStreams(), RoomForMoreConcurrent()); |
|
214 |
|
215 log.AppendPrintf(" transactionHashCount = %d streamIDHashCount = %d\n", |
|
216 mStreamTransactionHash.Count(), |
|
217 mStreamIDHash.Count()); |
|
218 |
|
219 log.AppendPrintf(" Queued Stream Size = %d\n", mQueuedStreams.GetSize()); |
|
220 |
|
221 PRIntervalTime now = PR_IntervalNow(); |
|
222 log.AppendPrintf(" Ping Threshold = %ums next ping id = 0x%X\n", |
|
223 PR_IntervalToMilliseconds(mPingThreshold), |
|
224 mNextPingID); |
|
225 log.AppendPrintf(" Ping Timeout = %ums\n", |
|
226 PR_IntervalToMilliseconds(gHttpHandler->SpdyPingTimeout())); |
|
227 log.AppendPrintf(" Idle for Any Activity (ping) = %ums\n", |
|
228 PR_IntervalToMilliseconds(now - mLastReadEpoch)); |
|
229 log.AppendPrintf(" Idle for Data Activity = %ums\n", |
|
230 PR_IntervalToMilliseconds(now - mLastDataReadEpoch)); |
|
231 if (mPingSentEpoch) |
|
232 log.AppendPrintf(" Ping Outstanding (ping) = %ums, expired = %d\n", |
|
233 PR_IntervalToMilliseconds(now - mPingSentEpoch), |
|
234 now - mPingSentEpoch >= gHttpHandler->SpdyPingTimeout()); |
|
235 else |
|
236 log.AppendPrintf(" No Ping Outstanding\n"); |
|
237 } |
|
238 |
|
239 void |
|
240 Http2Session::PrintDiagnostics(nsCString &log) |
|
241 { |
|
242 log.AppendPrintf(" ::: HTTP2\n"); |
|
243 log.AppendPrintf(" shouldgoaway = %d mClosed = %d CanReuse = %d nextID=0x%X\n", |
|
244 mShouldGoAway, mClosed, CanReuse(), mNextStreamID); |
|
245 |
|
246 log.AppendPrintf(" concurrent = %d maxconcurrent = %d\n", |
|
247 mConcurrent, mMaxConcurrent); |
|
248 |
|
249 log.AppendPrintf(" roomformorestreams = %d roomformoreconcurrent = %d\n", |
|
250 RoomForMoreStreams(), RoomForMoreConcurrent()); |
|
251 |
|
252 log.AppendPrintf(" transactionHashCount = %d streamIDHashCount = %d\n", |
|
253 mStreamTransactionHash.Count(), |
|
254 mStreamIDHash.Count()); |
|
255 |
|
256 log.AppendPrintf(" Queued Stream Size = %d\n", mQueuedStreams.GetSize()); |
|
257 |
|
258 PRIntervalTime now = PR_IntervalNow(); |
|
259 log.AppendPrintf(" Ping Threshold = %ums\n", |
|
260 PR_IntervalToMilliseconds(mPingThreshold)); |
|
261 log.AppendPrintf(" Ping Timeout = %ums\n", |
|
262 PR_IntervalToMilliseconds(gHttpHandler->SpdyPingTimeout())); |
|
263 log.AppendPrintf(" Idle for Any Activity (ping) = %ums\n", |
|
264 PR_IntervalToMilliseconds(now - mLastReadEpoch)); |
|
265 log.AppendPrintf(" Idle for Data Activity = %ums\n", |
|
266 PR_IntervalToMilliseconds(now - mLastDataReadEpoch)); |
|
267 if (mPingSentEpoch) |
|
268 log.AppendPrintf(" Ping Outstanding (ping) = %ums, expired = %d\n", |
|
269 PR_IntervalToMilliseconds(now - mPingSentEpoch), |
|
270 now - mPingSentEpoch >= gHttpHandler->SpdyPingTimeout()); |
|
271 else |
|
272 log.AppendPrintf(" No Ping Outstanding\n"); |
|
273 } |
|
274 |
|
275 void |
|
276 nsHttpTransaction::PrintDiagnostics(nsCString &log) |
|
277 { |
|
278 if (!mRequestHead) |
|
279 return; |
|
280 |
|
281 log.AppendPrintf(" ::: uri = %s\n", |
|
282 nsAutoCString(mRequestHead->RequestURI()).get()); |
|
283 log.AppendPrintf(" caps = 0x%x\n", mCaps); |
|
284 log.AppendPrintf(" priority = %d\n", mPriority); |
|
285 log.AppendPrintf(" restart count = %u\n", mRestartCount); |
|
286 log.AppendPrintf(" classification = 0x%x\n", mClassification); |
|
287 } |
|
288 |
|
289 } // namespace mozilla::net |
|
290 } // namespace mozilla |