Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetStats.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "NetStats.h"
21 
23 
24 enum
25 {
38 };
39 
41  : m_Peer(peer)
42 {
43 }
44 
46  : m_Peer(NULL)
47 {
48 }
49 
51 {
52  return "net";
53 }
54 
56 {
57  if (m_Peer)
58  return "Network client statistics";
59  else
60  return "Network host statistics";
61 }
62 
64 {
65  return NumberRows;
66 }
67 
68 const std::vector<ProfileColumn>& CNetStatsTable::GetColumns()
69 {
70  m_ColumnDescriptions.clear();
71  m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
72  if (m_Peer)
73  {
74  m_ColumnDescriptions.push_back(ProfileColumn("Value", 80));
75  }
76  else
77  {
78  CScopeLock lock(m_Mutex);
79 
80  for (size_t i = 0; i < m_LatchedData.size(); ++i)
81  m_ColumnDescriptions.push_back(ProfileColumn("Peer "+CStr::FromUInt(i), 80));
82  }
83  return m_ColumnDescriptions;
84 }
85 
86 CStr CNetStatsTable::GetCellText(size_t row, size_t col)
87 {
88  // Return latched data, if we have any
89  {
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];
93  }
94 
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 "???"
100 
101  switch(row)
102  {
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);
114 
115  default:
116  return "???";
117  }
118 
119 #undef ROW
120 }
121 
123 {
124  return 0;
125 }
126 
128 {
129  CScopeLock lock(m_Mutex);
130 
131 #define ROW(id, title, member) \
132  m_LatchedData[i].push_back(CStr::FromUInt(host->peers[i].member));
133 
134  m_LatchedData.clear();
135  m_LatchedData.resize(host->peerCount);
136 
137  for (size_t i = 0; i < host->peerCount; ++i)
138  {
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);
150  }
151 #undef ROW
152 }
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
void LatchHostState(const ENetHost *host)
Definition: NetStats.cpp:127
Class AbstractProfileTable: Profile table data model.
Definition: ProfileViewer.h:60
Locks a CMutex over this object&#39;s lifetime.
Definition: ThreadUtil.h:73
virtual size_t GetNumberRows()
GetNumberRows.
Definition: NetStats.cpp:63
struct _ENetPeer ENetPeer
Definition: NetHost.h:30
virtual CStr GetName()
GetName: Short descriptive name of this table (should be static).
Definition: NetStats.cpp:50
#define ROW(id, title, member)
CMutex m_Mutex
Definition: NetStats.h:56
virtual CStr GetTitle()
GetTitle: Longer, explanatory text (can be dynamic).
Definition: NetStats.cpp:55
virtual AbstractProfileTable * GetChild(size_t row)
GetChild: Return a row&#39;s child table if the child is expandable.
Definition: NetStats.cpp:122
std::vector< ProfileColumn > m_ColumnDescriptions
Definition: NetStats.h:54
virtual CStr GetCellText(size_t row, size_t col)
GetCellText.
Definition: NetStats.cpp:86
struct _ENetHost ENetHost
Definition: NetHost.h:32
Struct ProfileColumn: Describes one column of an AbstractProfileTable.
Definition: ProfileViewer.h:35
virtual const std::vector< ProfileColumn > & GetColumns()
GetColumnDescriptions.
Definition: NetStats.cpp:68
const ENetPeer * m_Peer
Definition: NetStats.h:53
std::vector< std::vector< CStr > > m_LatchedData
Definition: NetStats.h:57