]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Change allocation of InspIRCd::stats to be physically part of the object containing it
authorAttila Molnar <attilamolnar@hush.com>
Fri, 13 Jun 2014 13:03:56 +0000 (15:03 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 13 Jun 2014 13:03:56 +0000 (15:03 +0200)
While at it, remove "stats" from all field names

include/inspircd.h
src/command_parse.cpp
src/coremods/core_dns.cpp
src/coremods/core_hostname_lookup.cpp
src/coremods/core_stats.cpp
src/inspircd.cpp
src/listensocket.cpp
src/users.cpp

index 633a0d58d3c8e28c50737527637f6d0e277f5ee6..30625c42a1513b0627ef6fb7c5c503781f3fbd42 100644 (file)
@@ -174,38 +174,38 @@ class serverstats
   public:
        /** Number of accepted connections
         */
-       unsigned long statsAccept;
+       unsigned long Accept;
        /** Number of failed accepts
         */
-       unsigned long statsRefused;
+       unsigned long Refused;
        /** Number of unknown commands seen
         */
-       unsigned long statsUnknown;
+       unsigned long Unknown;
        /** Number of nickname collisions handled
         */
-       unsigned long statsCollisions;
+       unsigned long Collisions;
        /** Number of DNS queries sent out
         */
-       unsigned long statsDns;
+       unsigned long Dns;
        /** Number of good DNS replies received
         * NOTE: This may not tally to the number sent out,
         * due to timeouts and other latency issues.
         */
-       unsigned long statsDnsGood;
+       unsigned long DnsGood;
        /** Number of bad (negative) DNS replies received
         * NOTE: This may not tally to the number sent out,
         * due to timeouts and other latency issues.
         */
-       unsigned long statsDnsBad;
+       unsigned long DnsBad;
        /** Number of inbound connections seen
         */
-       unsigned long statsConnects;
+       unsigned long Connects;
        /** Total bytes of data transmitted
         */
-       unsigned long statsSent;
+       unsigned long Sent;
        /** Total bytes of data received
         */
-       unsigned long statsRecv;
+       unsigned long Recv;
 #ifdef _WIN32
        /** Cpu usage at last sample
        */
@@ -227,8 +227,8 @@ class serverstats
        /** The constructor initializes all the counts to zero
         */
        serverstats()
-               : statsAccept(0), statsRefused(0), statsUnknown(0), statsCollisions(0), statsDns(0),
-               statsDnsGood(0), statsDnsBad(0), statsConnects(0), statsSent(0), statsRecv(0)
+               : Accept(0), Refused(0), Unknown(0), Collisions(0), Dns(0),
+               DnsGood(0), DnsBad(0), Connects(0), Sent(0), Recv(0)
        {
        }
 };
@@ -368,7 +368,7 @@ class CoreExport InspIRCd
 
        /** Stats class, holds miscellaneous stats counters
         */
-       serverstats* stats;
+       serverstats stats;
 
        /**  Server Config class, holds configuration file data
         */
index d89d7cbb597097568a781d3f96ec9db7a2f1a4fb..0669c89ada50e9f1cbd7da3afa59a13b9c893697 100644 (file)
@@ -208,7 +208,7 @@ void CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
                {
                        if (user->registered == REG_ALL)
                                user->WriteNumeric(ERR_UNKNOWNCOMMAND, "%s :Unknown command",command.c_str());
-                       ServerInstance->stats->statsUnknown++;
+                       ServerInstance->stats.Unknown++;
                        return;
                }
        }
index 30c736757468c94a6b7c9d8f471c921c8fd70966..17e4897947b986a8fc0775ac943f3f15c9f888e2 100644 (file)
@@ -603,7 +603,7 @@ class MyManager : public Manager, public Timer, public EventHandler
                if (recv_packet.flags & QUERYFLAGS_OPCODE)
                {
                        ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Received a nonstandard query");
-                       ServerInstance->stats->statsDnsBad++;
+                       ServerInstance->stats.DnsBad++;
                        recv_packet.error = ERROR_NONSTANDARD_QUERY;
                        request->OnError(&recv_packet);
                }
@@ -637,26 +637,26 @@ class MyManager : public Manager, public Timer, public EventHandler
                                        break;
                        }
 
-                       ServerInstance->stats->statsDnsBad++;
+                       ServerInstance->stats.DnsBad++;
                        recv_packet.error = error;
                        request->OnError(&recv_packet);
                }
                else if (recv_packet.questions.empty() || recv_packet.answers.empty())
                {
                        ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: No resource records returned");
-                       ServerInstance->stats->statsDnsBad++;
+                       ServerInstance->stats.DnsBad++;
                        recv_packet.error = ERROR_NO_RECORDS;
                        request->OnError(&recv_packet);
                }
                else
                {
                        ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Resolver: Lookup complete for " + request->name);
-                       ServerInstance->stats->statsDnsGood++;
+                       ServerInstance->stats.DnsGood++;
                        request->OnLookupComplete(&recv_packet);
                        this->AddCache(recv_packet);
                }
 
-               ServerInstance->stats->statsDns++;
+               ServerInstance->stats.Dns++;
 
                /* Request's destructor removes it from the request map */
                delete request;
index 3d3e9703ae2c6e5ab4a5cfa818de582e3d549980..7f3f2314960062763364430966ea1b963a7f8345 100644 (file)
@@ -170,7 +170,7 @@ class UserResolver : public DNS::Request
                {
                        bound_user->WriteNotice("*** Could not resolve your hostname: " + this->manager->GetErrorStr(query->error) + "; using your IP address (" + bound_user->GetIPString() + ") instead.");
                        dl->set(bound_user, 0);
-                       ServerInstance->stats->statsDnsBad++;
+                       ServerInstance->stats.DnsBad++;
                }
        }
 };
@@ -215,7 +215,7 @@ class ModuleHostnameLookup : public Module
                        this->dnsLookup.set(user, 0);
                        delete res_reverse;
                        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error in resolver: " + e.GetReason());
-                       ServerInstance->stats->statsDnsBad++;
+                       ServerInstance->stats.DnsBad++;
                }
        }
 
index e0e5b3a0feaedf9403f4eb7aabd977b48478fc09..b8ea21731a85d3149e49ba4a3f844cc479e2c23e 100644 (file)
@@ -236,9 +236,9 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
 
                                char percent[30];
 
-                               float n_elapsed = (ServerInstance->Time() - ServerInstance->stats->LastSampled.tv_sec) * 1000000
-                                       + (ServerInstance->Time_ns() - ServerInstance->stats->LastSampled.tv_nsec) / 1000;
-                               float n_eaten = ((R.ru_utime.tv_sec - ServerInstance->stats->LastCPU.tv_sec) * 1000000 + R.ru_utime.tv_usec - ServerInstance->stats->LastCPU.tv_usec);
+                               float n_elapsed = (ServerInstance->Time() - ServerInstance->stats.LastSampled.tv_sec) * 1000000
+                                       + (ServerInstance->Time_ns() - ServerInstance->stats.LastSampled.tv_nsec) / 1000;
+                               float n_eaten = ((R.ru_utime.tv_sec - ServerInstance->stats.LastCPU.tv_sec) * 1000000 + R.ru_utime.tv_usec - ServerInstance->stats.LastCPU.tv_usec);
                                float per = (n_eaten / n_elapsed) * 100;
 
                                snprintf(percent, 30, "%03.5f%%", per);
@@ -269,8 +269,8 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                        {
                                KernelTime.dwHighDateTime += UserTime.dwHighDateTime;
                                KernelTime.dwLowDateTime += UserTime.dwLowDateTime;
-                               double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
-                               double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
+                               double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats.LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats.LastCPU.dwLowDateTime) )/100000;
+                               double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats.LastSampled.QuadPart) / ServerInstance->stats.QPFrequency.QuadPart;
                                double per = (n_eaten/n_elapsed);
 
                                char percent[30];
@@ -290,13 +290,13 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
 
                case 'T':
                {
-                       results.push_back("249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused));
-                       results.push_back("249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown));
-                       results.push_back("249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions));
-                       results.push_back("249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad));
-                       results.push_back("249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects));
+                       results.push_back("249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats.Accept)+" refused "+ConvToStr(ServerInstance->stats.Refused));
+                       results.push_back("249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats.Unknown));
+                       results.push_back("249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats.Collisions));
+                       results.push_back("249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats.DnsGood+ServerInstance->stats.DnsBad)+" succeeded "+ConvToStr(ServerInstance->stats.DnsGood)+" failed "+ConvToStr(ServerInstance->stats.DnsBad));
+                       results.push_back("249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats.Connects));
                        results.push_back(InspIRCd::Format("249 %s :bytes sent %5.2fK recv %5.2fK", user->nick.c_str(),
-                               ServerInstance->stats->statsSent / 1024.0, ServerInstance->stats->statsRecv / 1024.0));
+                               ServerInstance->stats.Sent / 1024.0, ServerInstance->stats.Recv / 1024.0));
                }
                break;
 
index efbb013cad13cb29adedc0d5557e0f62c7644a84..ff28be6c1a36fe34a19c2e3cfa19061b4f18d05a 100644 (file)
@@ -133,7 +133,6 @@ void InspIRCd::Cleanup()
        DeleteZero(this->Modes);
        DeleteZero(this->XLines);
        DeleteZero(this->Parser);
-       DeleteZero(this->stats);
        DeleteZero(this->Modules);
        DeleteZero(this->BanCache);
        DeleteZero(this->SNO);
@@ -268,7 +267,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->SNO = 0;
        this->BanCache = 0;
        this->Modules = 0;
-       this->stats = 0;
        this->Parser = 0;
        this->XLines = 0;
        this->Modes = 0;
@@ -296,7 +294,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->BanCache = new BanCacheManager;
        this->Modules = new ModuleManager();
        dynamic_reference_base::reset_all();
-       this->stats = new serverstats();
        this->Parser = new CommandParser;
        this->XLines = new XLineManager;
 
@@ -549,7 +546,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                FreeConsole();
        }
 
-       QueryPerformanceFrequency(&stats->QPFrequency);
+       QueryPerformanceFrequency(&stats.QPFrequency);
 #endif
 
        Logs->Log("STARTUP", LOG_DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SocketEngine::GetMaxFds());
@@ -683,18 +680,18 @@ void InspIRCd::Run()
                {
 #ifndef _WIN32
                        getrusage(RUSAGE_SELF, &ru);
-                       stats->LastSampled = TIME;
-                       stats->LastCPU = ru.ru_utime;
+                       stats.LastSampled = TIME;
+                       stats.LastCPU = ru.ru_utime;
 #else
-                       if(QueryPerformanceCounter(&stats->LastSampled))
+                       if(QueryPerformanceCounter(&stats.LastSampled))
                        {
                                FILETIME CreationTime;
                                FILETIME ExitTime;
                                FILETIME KernelTime;
                                FILETIME UserTime;
                                GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
-                               stats->LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
-                               stats->LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
+                               stats.LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
+                               stats.LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
                        }
 #endif
 
index cb4bfd2db4a01bd06fa6f177bce17e4b8e4e2ef3..2a74c0b683b1a848c7f4b78cb91668dde699dcc1 100644 (file)
@@ -114,7 +114,7 @@ void ListenSocket::AcceptInternal()
        ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "HandleEvent for Listensocket %s nfd=%d", bind_desc.c_str(), incomingSockfd);
        if (incomingSockfd < 0)
        {
-               ServerInstance->stats->statsRefused++;
+               ServerInstance->stats.Refused++;
                return;
        }
 
@@ -170,11 +170,11 @@ void ListenSocket::AcceptInternal()
        }
        if (res == MOD_RES_ALLOW)
        {
-               ServerInstance->stats->statsAccept++;
+               ServerInstance->stats.Accept++;
        }
        else
        {
-               ServerInstance->stats->statsRefused++;
+               ServerInstance->stats.Refused++;
                ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Refusing connection on %s - %s",
                        bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
                SocketEngine::Close(incomingSockfd);
index 6e9e8202e811490534b5498f2f289b365bdce5c8..4acf80395f18cb81c41ff5876b7aae2c88610d5e 100644 (file)
@@ -285,7 +285,7 @@ eol_found:
                recvq = recvq.substr(qpos);
 
                // TODO should this be moved to when it was inserted in recvq?
-               ServerInstance->stats->statsRecv += qpos;
+               ServerInstance->stats.Recv += qpos;
                user->bytes_in += qpos;
                user->cmds_in++;
 
@@ -540,7 +540,7 @@ bool LocalUser::CheckLines(bool doZline)
 
 void LocalUser::FullConnect()
 {
-       ServerInstance->stats->statsConnects++;
+       ServerInstance->stats.Connects++;
        this->idle_lastmsg = ServerInstance->Time();
 
        /*
@@ -629,7 +629,7 @@ bool User::ChangeNick(const std::string& newnick, bool force, time_t newts)
 
                if (MOD_RESULT == MOD_RES_DENY)
                {
-                       ServerInstance->stats->statsCollisions++;
+                       ServerInstance->stats.Collisions++;
                        return false;
                }
        }
@@ -837,7 +837,7 @@ void LocalUser::Write(const std::string& text)
        eh.AddWriteBuf(text);
        eh.AddWriteBuf(wide_newline);
 
-       ServerInstance->stats->statsSent += text.length() + 2;
+       ServerInstance->stats.Sent += text.length() + 2;
        this->bytes_out += text.length() + 2;
        this->cmds_out++;
 }