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