ManaPlus
packetcounters.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "net/packetcounters.h"
25 
26 #include "utils/cast.h"
27 
28 #include "debug.h"
29 
30 extern volatile time_t cur_time;
31 extern volatile bool runCounters;
32 
43 
44 void PacketCounters::incInBytes(const int cnt)
45 {
46  if (!runCounters)
47  return;
48 
51 
53 }
54 
56 {
57  if (!runCounters)
58  return;
59 
62 
64 }
65 
67 {
69 }
70 
72 {
74 }
75 
76 void PacketCounters::incOutBytes(const int cnt)
77 {
78  if (!runCounters)
79  return;
80 
83 
85 }
86 
88 {
89  if (!runCounters)
90  return;
91 
95 
97 }
98 
100 {
102 }
103 
105 {
107 }
108 
109 
111  int &restrict calc,
112  int &restrict counter)
113 {
114  const int idx = CAST_S32(cur_time % 60);
115  if (currentSec != idx)
116  {
117  currentSec = idx;
118  calc = counter;
119  counter = 0;
120  }
121 }
122 
124 {
125  if (!runCounters)
126  return;
127 
128  BLOCK_START("PacketCounters::update")
137  BLOCK_END("PacketCounters::update")
138 }
#define CAST_S32
Definition: cast.h:30
static int mOutBytesCalc
static int getOutBytes()
static void incInBytes(const int cnt)
static void update()
static int mOutPacketsCalc
static int mInBytesCalc
static int mOutPackets
static void updateCounter(int &currentSec, int &calc, int &counter)
static int getInPackets()
static void incInPackets()
static int mOutBytes
static int mInPackets
static int getInBytes()
static int getOutPackets()
static void incOutBytes(const int cnt)
static int mInPacketsCalc
static int mOutCurrentSec
static int mInBytes
static int mInCurrentSec
static void incOutPackets()
#define restrict
Definition: localconsts.h:165
volatile bool runCounters
Definition: client.cpp:122
volatile time_t cur_time
Definition: timer.cpp:58
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79