in ctsTraffic/ctsConfig.cpp [3482:3624]
void PrintConnectionResults(const ctSockaddr& localAddr, const ctSockaddr& remoteAddr, uint32_t error, const ctsTcpStatistics& stats) noexcept try
{
ctsConfigInitOnce();
// write even after shutdown so can print the final summaries
auto writeToConsole = false;
// ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
switch (g_consoleVerbosity) // NOLINT(hicpp-multiway-paths-covered)
{
// case 0: // nothing
// case 1: // status updates
// case 2: // error info
case 3: // connection info
case 4: // connection info + error info
case 5: // connection info + error info + status updates
case 6: // above + debug info
{
writeToConsole = true;
}
}
enum class ErrorType
{
Success,
NetworkError,
ProtocolError
} errorType = ErrorType::Success;
if (0 == error)
{
errorType = ErrorType::Success;
}
else if (ctsIoPattern::IsProtocolError(error))
{
errorType = ErrorType::ProtocolError;
}
else
{
errorType = ErrorType::NetworkError;
}
const int64_t totalTime = stats.m_endTime.GetValue() - stats.m_startTime.GetValue();
FAIL_FAST_IF_MSG(
totalTime < 0LL,
"end_time is less than start_time in this ctsTcpStatistics object (%p)", &stats);
const float currentTime = GetStatusTimeStamp();
wstring csvString;
wstring textString;
wstring errorString;
if (ErrorType::ProtocolError != errorType)
{
if (0 == error)
{
errorString = L"Succeeded";
}
else
{
errorString = wil::str_printf<std::wstring>(
L"%lu: %ws",
error,
ctString::ctFormatMessage(error).c_str());
// remove any commas from the formatted string - since that will mess up csv files
ctString::ctReplaceAll(errorString, L",", L" ");
}
}
if (g_connectionLogger && g_connectionLogger->IsCsvFormat())
{
// csv format : L"TimeSlice,LocalAddress,RemoteAddress,SendBytes,SendBps,RecvBytes,RecvBps,TimeMs,Result,ConnectionId"
static const auto* tcpResultCsvFormat = L"%.3f,%ws,%ws,%lld,%lld,%lld,%lld,%lld,%ws,%hs\r\n";
csvString = wil::str_printf<std::wstring>(
tcpResultCsvFormat,
currentTime,
localAddr.WriteCompleteAddress().c_str(),
remoteAddr.WriteCompleteAddress().c_str(),
stats.m_bytesSent.GetValue(),
totalTime > 0LL ? stats.m_bytesSent.GetValue() * 1000LL / totalTime : 0LL,
stats.m_bytesRecv.GetValue(),
totalTime > 0LL ? stats.m_bytesRecv.GetValue() * 1000LL / totalTime : 0LL,
totalTime,
ErrorType::ProtocolError == errorType ?
ctsIoPattern::BuildProtocolErrorString(error) :
errorString.c_str(),
stats.m_connectionIdentifier);
}
// we'll never write csv format to the console so we'll need a text string in that case
// - and/or in the case the g_ConnectionLogger isn't writing to csv
if (writeToConsole || g_connectionLogger && !g_connectionLogger->IsCsvFormat())
{
if (0 == error)
{
static const auto* tcpSuccessfulResultTextFormat = L"[%.3f] TCP connection succeeded : [%ws - %ws] [%hs]: SendBytes[%lld] SendBps[%lld] RecvBytes[%lld] RecvBps[%lld] Time[%lld ms]";
textString = wil::str_printf<std::wstring>(
tcpSuccessfulResultTextFormat,
currentTime,
localAddr.WriteCompleteAddress().c_str(),
remoteAddr.WriteCompleteAddress().c_str(),
stats.m_connectionIdentifier,
stats.m_bytesSent.GetValue(),
totalTime > 0LL ? stats.m_bytesSent.GetValue() * 1000LL / totalTime : 0LL,
stats.m_bytesRecv.GetValue(),
totalTime > 0LL ? stats.m_bytesRecv.GetValue() * 1000LL / totalTime : 0LL,
totalTime);
}
else
{
static const auto* tcpProtocolFailureResultTextFormat = L"[%.3f] TCP connection failed with the protocol error %ws : [%ws - %ws] [%hs] : SendBytes[%lld] SendBps[%lld] RecvBytes[%lld] RecvBps[%lld] Time[%lld ms]";
static const auto* tcpNetworkFailureResultTextFormat = L"[%.3f] TCP connection failed with the error %ws : [%ws - %ws] [%hs] : SendBytes[%lld] SendBps[%lld] RecvBytes[%lld] RecvBps[%lld] Time[%lld ms]";
textString = wil::str_printf<std::wstring>(
ErrorType::ProtocolError == errorType ? tcpProtocolFailureResultTextFormat : tcpNetworkFailureResultTextFormat,
currentTime,
ErrorType::ProtocolError == errorType ? ctsIoPattern::BuildProtocolErrorString(error) : errorString.c_str(),
localAddr.WriteCompleteAddress().c_str(),
remoteAddr.WriteCompleteAddress().c_str(),
stats.m_connectionIdentifier,
stats.m_bytesSent.GetValue(),
totalTime > 0LL ? stats.m_bytesSent.GetValue() * 1000LL / totalTime : 0LL,
stats.m_bytesRecv.GetValue(),
totalTime > 0LL ? stats.m_bytesRecv.GetValue() * 1000LL / totalTime : 0LL,
totalTime);
}
}
if (writeToConsole)
{
// text strings always go to the console
wprintf(L"%ws\n", textString.c_str());
}
if (g_connectionLogger)
{
if (g_connectionLogger->IsCsvFormat())
{
g_connectionLogger->LogMessage(csvString.c_str());
}
else
{
g_connectionLogger->LogMessage(
wil::str_printf<std::wstring>(L"%ws\r\n", textString.c_str()).c_str());
}
}
}