Skip to content

Commit ece4b88

Browse files
Matt Jorasmeta-codesync[bot]
authored andcommitted
Add QLOG macro for mobile binary size reduction
Summary: This change introduces a QLOG() macro that wraps all QLogger calls. On mobile builds (Android, iOS, macOS), this macro compiles to a no-op via Buck's select() mechanism, eliminating the function call overhead and associated code. The key changes are: - New QLoggerMacros.h with QLOG macro for non-mobile builds - New QLoggerMacrosMobile.h with no-op macro for mobile builds - Updated ~200 call sites across client, server, congestion control, loss, and state files - BUCK files updated with platform-conditional header selection - Removed unnecessary qLogger parameter from QuicStreamManager::setStreamPriority Reviewed By: jbeshay Differential Revision: D89485388 fbshipit-source-id: 34fb59157788b36ed8bcc6663eb0f094eaf6013e
1 parent b3119e1 commit ece4b88

29 files changed

Lines changed: 721 additions & 705 deletions

quic/api/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mvfst_cpp_library(
8686
"//quic/common:mvfst_logging",
8787
"//quic/common:time_util",
8888
"//quic/logging:qlogger_constants",
89+
"//quic/logging:qlogger_macros",
8990
"//quic/loss:loss",
9091
"//quic/observer:socket_observer_macros",
9192
"//quic/state:pacing_functions",
@@ -144,6 +145,7 @@ mvfst_cpp_library(
144145
"//quic/congestion_control:ecn_l4s_tracker",
145146
"//quic/congestion_control:pacer_factory",
146147
"//quic/flowcontrol:flow_control",
148+
"//quic/logging:qlogger_macros",
147149
"//quic/loss:loss",
148150
"//quic/observer:socket_observer_macros",
149151
"//quic/state:pacing_functions",
@@ -199,6 +201,7 @@ mvfst_cpp_library(
199201
"//quic/common:socket_util",
200202
"//quic/common:string_utils",
201203
"//quic/happyeyeballs:happyeyeballs",
204+
"//quic/logging:qlogger_macros",
202205
"//quic/state:ack_frequency_functions",
203206
"//quic/state:ack_handler",
204207
"//quic/state:simple_frame_functions",

quic/api/QuicTransportBase.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <quic/common/Optional.h>
1515
#include <quic/common/TimeUtil.h>
1616
#include <quic/logging/QLoggerConstants.h>
17+
#include <quic/logging/QLoggerMacros.h>
1718
#include <quic/loss/QuicLossFunctions.h>
1819
#include <quic/observer/SocketObserverMacros.h>
1920
#include <quic/state/QuicPacingFunctions.h>
@@ -91,9 +92,7 @@ void QuicTransportBase::closeGracefully() {
9192
resetConnectionCallbacks();
9293
closeState_ = CloseState::GRACEFUL_CLOSING;
9394
updatePacingOnClose(*conn_);
94-
if (conn_->qLogger) {
95-
conn_->qLogger->addConnectionClose(kNoError, kGracefulExit, true, false);
96-
}
95+
QLOG(*conn_, addConnectionClose, kNoError, kGracefulExit, true, false);
9796

9897
// Stop reads and cancel all the app callbacks.
9998
MVVLOG(10) << "Stopping read and peek loopers due to graceful close "

quic/api/QuicTransportBaseLite.cpp

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <quic/congestion_control/EcnL4sTracker.h>
1414
#include <quic/congestion_control/PacerFactory.h>
1515
#include <quic/flowcontrol/QuicFlowController.h>
16+
#include <quic/logging/QLoggerMacros.h>
1617
#include <quic/loss/QuicLossFunctions.h>
1718
#include <quic/observer/SocketObserverMacros.h>
1819
#include <quic/state/QuicPacingFunctions.h>
@@ -831,10 +832,7 @@ quic::Expected<void, LocalErrorCode> QuicTransportBaseLite::setStreamPriority(
831832
// It's not an error to prioritize a stream after it's sent its FIN - this
832833
// can reprioritize retransmissions.
833834
conn_->streamManager->setStreamPriority(
834-
id,
835-
priority,
836-
getSendConnFlowControlBytesWire(*conn_) > 0,
837-
conn_->qLogger);
835+
id, priority, getSendConnFlowControlBytesWire(*conn_) > 0);
838836
return {};
839837
}
840838

@@ -1397,8 +1395,8 @@ void QuicTransportBaseLite::closeImpl(
13971395

13981396
drainConnection = drainConnection & conn_->transportSettings.shouldDrain;
13991397

1400-
uint64_t totalCryptoDataWritten = 0;
1401-
uint64_t totalCryptoDataRecvd = 0;
1398+
uint64_t totalCryptoDataWritten [[maybe_unused]] = 0;
1399+
uint64_t totalCryptoDataRecvd [[maybe_unused]] = 0;
14021400
auto timeUntilLastInitialCryptoFrameReceived = std::chrono::milliseconds(0);
14031401
if (conn_->cryptoState) {
14041402
totalCryptoDataWritten +=
@@ -1418,36 +1416,36 @@ void QuicTransportBaseLite::closeImpl(
14181416
conn_->connectionTime);
14191417
}
14201418

1421-
if (conn_->qLogger) {
1422-
auto tlsSummary = conn_->handshakeLayer->getTLSSummary();
1423-
conn_->qLogger->addTransportSummary(
1424-
{conn_->lossState.totalBytesSent,
1425-
conn_->lossState.totalBytesRecvd,
1426-
conn_->flowControlState.sumCurWriteOffset,
1427-
conn_->flowControlState.sumMaxObservedOffset,
1428-
conn_->flowControlState.sumCurStreamBufferLen,
1429-
conn_->lossState.totalBytesRetransmitted,
1430-
conn_->lossState.totalStreamBytesCloned,
1431-
conn_->lossState.totalBytesCloned,
1432-
totalCryptoDataWritten,
1433-
totalCryptoDataRecvd,
1434-
conn_->congestionController
1435-
? conn_->congestionController->getWritableBytes()
1436-
: std::numeric_limits<uint64_t>::max(),
1437-
getSendConnFlowControlBytesWire(*conn_),
1438-
conn_->lossState.totalPacketsSpuriouslyMarkedLost,
1439-
conn_->lossState.reorderingThreshold,
1440-
uint64_t(conn_->transportSettings.timeReorderingThreshDividend),
1441-
conn_->usedZeroRtt,
1442-
conn_->version.value_or(QuicVersion::MVFST_INVALID),
1443-
conn_->initialPacketsReceived,
1444-
conn_->uniqueInitialCryptoFramesReceived,
1445-
timeUntilLastInitialCryptoFrameReceived,
1446-
tlsSummary.alpn,
1447-
tlsSummary.namedGroup,
1448-
tlsSummary.pskType,
1449-
tlsSummary.echStatus});
1450-
}
1419+
[[maybe_unused]] auto tlsSummary = conn_->handshakeLayer->getTLSSummary();
1420+
QLOG(
1421+
*conn_,
1422+
addTransportSummary,
1423+
{conn_->lossState.totalBytesSent,
1424+
conn_->lossState.totalBytesRecvd,
1425+
conn_->flowControlState.sumCurWriteOffset,
1426+
conn_->flowControlState.sumMaxObservedOffset,
1427+
conn_->flowControlState.sumCurStreamBufferLen,
1428+
conn_->lossState.totalBytesRetransmitted,
1429+
conn_->lossState.totalStreamBytesCloned,
1430+
conn_->lossState.totalBytesCloned,
1431+
totalCryptoDataWritten,
1432+
totalCryptoDataRecvd,
1433+
conn_->congestionController
1434+
? conn_->congestionController->getWritableBytes()
1435+
: std::numeric_limits<uint64_t>::max(),
1436+
getSendConnFlowControlBytesWire(*conn_),
1437+
conn_->lossState.totalPacketsSpuriouslyMarkedLost,
1438+
conn_->lossState.reorderingThreshold,
1439+
uint64_t(conn_->transportSettings.timeReorderingThreshDividend),
1440+
conn_->usedZeroRtt,
1441+
conn_->version.value_or(QuicVersion::MVFST_INVALID),
1442+
conn_->initialPacketsReceived,
1443+
conn_->uniqueInitialCryptoFramesReceived,
1444+
timeUntilLastInitialCryptoFrameReceived,
1445+
tlsSummary.alpn,
1446+
tlsSummary.namedGroup,
1447+
tlsSummary.pskType,
1448+
tlsSummary.echStatus});
14511449

14521450
// TODO: truncate the error code string to be 1MSS only.
14531451
closeState_ = CloseState::CLOSED;
@@ -1483,21 +1481,26 @@ void QuicTransportBaseLite::closeImpl(
14831481
<< *this;
14841482
if (errorCode) {
14851483
conn_->localConnectionError = errorCode;
1486-
if (conn_->qLogger) {
1487-
conn_->qLogger->addConnectionClose(
1488-
conn_->localConnectionError->message,
1489-
errorCode->message,
1490-
drainConnection,
1491-
sendCloseImmediately);
1492-
}
1493-
} else if (conn_->qLogger) {
1494-
auto reason = fmt::format(
1484+
QLOG(
1485+
*conn_,
1486+
addConnectionClose,
1487+
conn_->localConnectionError->message,
1488+
errorCode->message,
1489+
drainConnection,
1490+
sendCloseImmediately);
1491+
} else {
1492+
[[maybe_unused]] auto reason = fmt::format(
14951493
"Server: {}, Peer: isReset: {}, Peer: isAbandon: {}",
14961494
kNoError,
14971495
isReset,
14981496
isAbandon);
1499-
conn_->qLogger->addConnectionClose(
1500-
kNoError, std::move(reason), drainConnection, sendCloseImmediately);
1497+
QLOG(
1498+
*conn_,
1499+
addConnectionClose,
1500+
kNoError,
1501+
std::move(reason),
1502+
drainConnection,
1503+
sendCloseImmediately);
15011504
}
15021505
cancelLossTimeout();
15031506
cancelTimeout(&ackTimeout_);
@@ -2941,11 +2944,9 @@ void QuicTransportBaseLite::setCongestionControl(CongestionControlType type) {
29412944
conn_->congestionController =
29422945
conn_->congestionControllerFactory->makeCongestionController(
29432946
*conn_, type);
2944-
if (conn_->qLogger) {
2945-
std::stringstream s;
2946-
s << "CCA set to " << congestionControlTypeToString(type);
2947-
conn_->qLogger->addTransportStateUpdate(s.str());
2948-
}
2947+
[[maybe_unused]] std::stringstream s;
2948+
s << "CCA set to " << congestionControlTypeToString(type);
2949+
QLOG(*conn_, addTransportStateUpdate, s.str());
29492950
}
29502951
}
29512952

quic/api/QuicTransportFunctions.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <quic/common/StringUtils.h>
2020
#include <quic/flowcontrol/QuicFlowController.h>
2121
#include <quic/happyeyeballs/QuicHappyEyeballsFunctions.h>
22+
#include <quic/logging/QLoggerMacros.h>
2223

2324
#include <quic/state/AckHandlers.h>
2425
#include <quic/state/QuicAckFrequencyFunctions.h>
@@ -722,9 +723,7 @@ quic::Expected<void, QuicError> updateConnection(
722723
MVVLOG(10) << nodeToString(conn.nodeType) << " sent packetNum=" << packetNum
723724
<< " in space=" << packetNumberSpace << " size=" << encodedSize
724725
<< " bodySize: " << encodedBodySize << " " << conn;
725-
if (conn.qLogger) {
726-
conn.qLogger->addPacket(packet, encodedSize);
727-
}
726+
QLOG(conn, addPacket, packet, encodedSize);
728727
FOLLY_SDT(quic, update_connection_num_frames, packet.frames.size());
729728
for (const auto& frame : packet.frames) {
730729
switch (frame.type()) {
@@ -1487,9 +1486,7 @@ void writeCloseCommon(
14871486
Buf packetBuf(std::move(packet.header));
14881487
packetBuf.appendToChain(std::move(bufUniquePtr));
14891488
auto packetSize = packetBuf.computeChainDataLength();
1490-
if (connection.qLogger) {
1491-
connection.qLogger->addPacket(packet.packet, packetSize);
1492-
}
1489+
QLOG(connection, addPacket, packet.packet, packetSize);
14931490
MVVLOG(10) << nodeToString(connection.nodeType)
14941491
<< " sent close packetNum=" << packetNum << " in space=" << pnSpace
14951492
<< " " << connection;

quic/client/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mvfst_cpp_library(
4343
"//quic/handshake:handshake",
4444
"//quic/happyeyeballs:happyeyeballs",
4545
"//quic/logging:qlogger_constants",
46+
"//quic/logging:qlogger_macros",
4647
"//quic/loss:loss",
4748
"//quic/state:ack_handler",
4849
"//quic/state:datagram_handler",
@@ -84,6 +85,7 @@ mvfst_cpp_library(
8485
"//quic/common:mvfst_logging",
8586
"//quic/common:time_util",
8687
"//quic/congestion_control:congestion_controller_factory",
88+
"//quic/logging:qlogger_macros",
8789
"//quic/loss:loss",
8890
"//quic/state:quic_stream_utilities",
8991
"//quic/state:stream_functions",

quic/client/QuicClientTransportLite.cpp

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <quic/handshake/CryptoFactory.h>
2323
#include <quic/happyeyeballs/QuicHappyEyeballsFunctions.h>
2424
#include <quic/logging/QLoggerConstants.h>
25+
#include <quic/logging/QLoggerMacros.h>
2526
#include <quic/loss/QuicLossFunctions.h>
2627
#include <quic/state/AckHandlers.h>
2728
#include <quic/state/DatagramHandlers.h>
@@ -92,9 +93,7 @@ QuicClientTransportLite::QuicClientTransportLite(
9293
clientConn_->initialDestinationConnectionId;
9394
MVVLOG(4) << "initial dcid: "
9495
<< clientConn_->initialDestinationConnectionId->hex();
95-
if (conn_->qLogger) {
96-
conn_->qLogger->setDcid(conn_->clientChosenDestConnectionId);
97-
}
96+
QLOG(*conn_, setDcid, conn_->clientChosenDestConnectionId);
9897

9998
conn_->readCodec->setCodecParameters(CodecParameters(
10099
conn_->peerAckDelayExponent,
@@ -251,9 +250,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
251250

252251
RetryPacket* retryPacket = parsedPacket.retryPacket();
253252
if (retryPacket) {
254-
if (conn_->qLogger) {
255-
conn_->qLogger->addPacket(*retryPacket, packetSize, true);
256-
}
253+
QLOG(*conn_, addPacket, *retryPacket, packetSize, true);
257254

258255
// we reject retry packet if our initial has been processed or we've rx'd a
259256
// prior retry packet; note that initialAckState is reset to nullptr only
@@ -325,10 +322,11 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
325322
udpPacket.timings,
326323
udpPacket.tosValue),
327324
peerAddress);
328-
if (conn_->qLogger) {
329-
conn_->qLogger->addPacketBuffered(
330-
cipherUnavailable->protectionType, packetSize);
331-
}
325+
QLOG(
326+
*conn_,
327+
addPacketBuffered,
328+
cipherUnavailable->protectionType,
329+
packetSize);
332330
// Packet buffered, not an error
333331
return {};
334332
}
@@ -358,9 +356,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
358356
MVVLOG(4) << "Packet parse error for " << *this;
359357
QUIC_STATS(
360358
statsCallback_, onPacketDropped, PacketDropReason::PARSE_ERROR_CLIENT);
361-
if (conn_->qLogger) {
362-
conn_->qLogger->addPacketDrop(packetSize, kParse);
363-
}
359+
QLOG(*conn_, addPacketDrop, packetSize, kParse);
364360
// If this was a protocol violation, we would return a codec error instead.
365361
// Ignore this case as something that caused a non-codec parse error.
366362
return {};
@@ -375,11 +371,11 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
375371
conn_->statsCallback,
376372
onPacketDropped,
377373
PacketDropReason::PROTOCOL_VIOLATION);
378-
if (conn_->qLogger) {
379-
conn_->qLogger->addPacketDrop(
380-
packetSize,
381-
PacketDropReason(PacketDropReason::PROTOCOL_VIOLATION)._to_string());
382-
}
374+
QLOG(
375+
*conn_,
376+
addPacketDrop,
377+
packetSize,
378+
PacketDropReason(PacketDropReason::PROTOCOL_VIOLATION)._to_string());
383379
return quic::make_unexpected(QuicError(
384380
TransportErrorCode::PROTOCOL_VIOLATION, "Packet has no frames"));
385381
}
@@ -399,9 +395,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
399395
protectionLevel == ProtectionType::KeyPhaseOne;
400396

401397
auto& regularPacket = *regularOptional;
402-
if (conn_->qLogger) {
403-
conn_->qLogger->addPacket(regularPacket, packetSize);
404-
}
398+
QLOG(*conn_, addPacket, regularPacket, packetSize);
405399
if (!isProtectedPacket) {
406400
for (auto& quicFrame : regularPacket.frames) {
407401
auto isPadding = quicFrame.asPaddingFrame();
@@ -853,9 +847,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
853847
clientConn_->zeroRttRejected = handshakeLayer->getZeroRttRejected();
854848
if (clientConn_->zeroRttRejected.has_value() &&
855849
*clientConn_->zeroRttRejected) {
856-
if (conn_->qLogger) {
857-
conn_->qLogger->addTransportStateUpdate(kZeroRttRejected);
858-
}
850+
QLOG(*conn_, addTransportStateUpdate, kZeroRttRejected);
859851
QUIC_STATS(conn_->statsCallback, onZeroRttRejected);
860852
handshakeLayer->removePsk(hostname_);
861853
if (!handshakeLayer->getCanResendZeroRtt().value_or(false)) {
@@ -864,9 +856,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::processUdpPacketData(
864856
"Zero-rtt attempted but the early parameters do not match the handshake parameters"));
865857
}
866858
} else if (clientConn_->zeroRttRejected.has_value()) {
867-
if (conn_->qLogger) {
868-
conn_->qLogger->addTransportStateUpdate(kZeroRttAccepted);
869-
}
859+
QLOG(*conn_, addTransportStateUpdate, kZeroRttAccepted);
870860
QUIC_STATS(conn_->statsCallback, onZeroRttAccepted);
871861
conn_->usedZeroRtt = true;
872862
}
@@ -1048,9 +1038,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::onReadData(
10481038
// If we are closed, then we shouldn't process new network data.
10491039
QUIC_STATS(
10501040
statsCallback_, onPacketDropped, PacketDropReason::CLIENT_STATE_CLOSED);
1051-
if (conn_->qLogger) {
1052-
conn_->qLogger->addPacketDrop(0, kAlreadyClosed);
1053-
}
1041+
QLOG(*conn_, addPacketDrop, 0, kAlreadyClosed);
10541042
return {};
10551043
}
10561044
bool waitingForFirstPacket = !hasReceivedUdpPackets(*conn_);
@@ -1964,9 +1952,7 @@ void QuicClientTransportLite::start(
19641952

19651953
CHECK(conn_->peerAddress.isInitialized());
19661954

1967-
if (conn_->qLogger) {
1968-
conn_->qLogger->addTransportStateUpdate(kStart);
1969-
}
1955+
QLOG(*conn_, addTransportStateUpdate, kStart);
19701956

19711957
setConnectionSetupCallback(connSetupCb);
19721958
setConnectionCallback(connCb);
@@ -2267,9 +2253,7 @@ quic::Expected<void, QuicError> QuicClientTransportLite::migrateConnection(
22672253
return quic::make_unexpected(adjustResult.error());
22682254
}
22692255

2270-
if (conn_->qLogger) {
2271-
conn_->qLogger->addConnectionMigrationUpdate(true);
2272-
}
2256+
QLOG(*conn_, addConnectionMigrationUpdate, true);
22732257

22742258
QUIC_STATS(conn_->statsCallback, onConnectionMigration);
22752259

@@ -2307,9 +2291,7 @@ void QuicClientTransportLite::setTransportStatsCallback(
23072291
}
23082292

23092293
void QuicClientTransportLite::maybeQlogDatagram(size_t len) {
2310-
if (conn_->qLogger) {
2311-
conn_->qLogger->addDatagramReceived(len);
2312-
}
2294+
QLOG(*conn_, addDatagramReceived, len);
23132295
}
23142296

23152297
void QuicClientTransportLite::trackDatagramsReceived(

0 commit comments

Comments
 (0)