1 /* Copyright (C) 2010 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
22 #include "lib/external_libraries/enet.h"
36 Row_ReliableInTransit
,
40 CNetStatsTable::CNetStatsTable(const ENetPeer
* peer
)
45 CNetStatsTable::CNetStatsTable()
50 CStr
CNetStatsTable::GetName()
55 CStr
CNetStatsTable::GetTitle()
58 return "Network client statistics";
60 return "Network host statistics";
63 size_t CNetStatsTable::GetNumberRows()
68 const std::vector
<ProfileColumn
>& CNetStatsTable::GetColumns()
70 m_ColumnDescriptions
.clear();
71 m_ColumnDescriptions
.push_back(ProfileColumn("Name", 200));
74 m_ColumnDescriptions
.push_back(ProfileColumn("Value", 80));
78 CScopeLock
lock(m_Mutex
);
80 for (size_t i
= 0; i
< m_LatchedData
.size(); ++i
)
81 m_ColumnDescriptions
.push_back(ProfileColumn("Peer "+CStr::FromUInt(i
), 80));
83 return m_ColumnDescriptions
;
86 CStr
CNetStatsTable::GetCellText(size_t row
, size_t col
)
88 // Return latched data, if we have any
90 CScopeLock
lock(m_Mutex
);
91 if (col
> 0 && m_LatchedData
.size() > col
-1 && m_LatchedData
[col
-1].size() > row
)
92 return m_LatchedData
[col
-1][row
];
95 #define ROW(id, title, member) \
97 if (col == 0) return title; \
98 if (m_Peer) return CStr::FromUInt(m_Peer->member); \
103 ROW(Row_InData
, "incoming bytes", incomingDataTotal
);
104 ROW(Row_OutData
, "outgoing bytes", outgoingDataTotal
);
105 ROW(Row_LastSendTime
, "last send time", lastSendTime
);
106 ROW(Row_LastRecvTime
, "last receive time", lastReceiveTime
);
107 ROW(Row_NextTimeout
, "next timeout", nextTimeout
);
108 ROW(Row_PacketsSent
, "packets sent", packetsSent
);
109 ROW(Row_PacketsLost
, "packets lost", packetsLost
);
110 ROW(Row_LastRTT
, "last RTT", lastRoundTripTime
);
111 ROW(Row_RTT
, "mean RTT", roundTripTime
);
112 ROW(Row_MTU
, "MTU", mtu
);
113 ROW(Row_ReliableInTransit
, "reliable data in transit", reliableDataInTransit
);
122 AbstractProfileTable
* CNetStatsTable::GetChild(size_t UNUSED(row
))
127 void CNetStatsTable::LatchHostState(const ENetHost
* host
)
129 CScopeLock
lock(m_Mutex
);
131 #define ROW(id, title, member) \
132 m_LatchedData[i].push_back(CStr::FromUInt(host->peers[i].member));
134 m_LatchedData
.clear();
135 m_LatchedData
.resize(host
->peerCount
);
137 for (size_t i
= 0; i
< host
->peerCount
; ++i
)
139 ROW(Row_InData
, "incoming bytes", incomingDataTotal
);
140 ROW(Row_OutData
, "outgoing bytes", outgoingDataTotal
);
141 ROW(Row_LastSendTime
, "last send time", lastSendTime
);
142 ROW(Row_LastRecvTime
, "last receive time", lastReceiveTime
);
143 ROW(Row_NextTimeout
, "next timeout", nextTimeout
);
144 ROW(Row_PacketsSent
, "packets sent", packetsSent
);
145 ROW(Row_PacketsLost
, "packets lost", packetsLost
);
146 ROW(Row_LastRTT
, "last RTT", lastRoundTripTime
);
147 ROW(Row_RTT
, "mean RTT", roundTripTime
);
148 ROW(Row_MTU
, "MTU", mtu
);
149 ROW(Row_ReliableInTransit
, "reliable data in transit", reliableDataInTransit
);