Coverage Report

Created: 2018-09-25 14:53

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