Fixes calls to SetVertexAttributeFormat with zero stride.
[0ad.git] / source / network / NetStats.cpp
blob883b97641ffd3a9024db80f768c6a6593f9c9544
1 /* Copyright (C) 2019 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"
20 #include "NetStats.h"
22 #include "lib/external_libraries/enet.h"
24 enum
26 Row_InData,
27 Row_OutData,
28 Row_LastSendTime,
29 Row_LastRecvTime,
30 Row_NextTimeout,
31 Row_PacketsSent,
32 Row_PacketsLost,
33 Row_LastRTT,
34 Row_RTT,
35 Row_MTU,
36 Row_ReliableInTransit,
37 NumberRows
40 CNetStatsTable::CNetStatsTable(const ENetPeer* peer)
41 : m_Peer(peer)
45 CNetStatsTable::CNetStatsTable()
46 : m_Peer(NULL)
50 CStr CNetStatsTable::GetName()
52 return "net";
55 CStr CNetStatsTable::GetTitle()
57 if (m_Peer)
58 return "Network client statistics";
59 else
60 return "Network host statistics";
63 size_t CNetStatsTable::GetNumberRows()
65 return NumberRows;
68 const std::vector<ProfileColumn>& CNetStatsTable::GetColumns()
70 m_ColumnDescriptions.clear();
71 m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
73 if (m_Peer)
74 m_ColumnDescriptions.push_back(ProfileColumn("Value", 80));
75 else
77 std::lock_guard<std::mutex> lock(m_Mutex);
79 for (size_t i = 0; i < m_LatchedData.size(); ++i)
80 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 std::lock_guard<std::mutex> 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) \
96 case id: \
97 if (col == 0) return title; \
98 if (m_Peer) return CStr::FromUInt(m_Peer->member); \
99 return "???"
101 switch(row)
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);
115 default:
116 return "???";
119 #undef ROW
122 AbstractProfileTable* CNetStatsTable::GetChild(size_t UNUSED(row))
124 return 0;
127 void CNetStatsTable::LatchHostState(const ENetHost* host)
129 std::lock_guard<std::mutex> 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);
151 #undef ROW