💄 NumOfUsers() & NumOfLogs() for loading output

This commit is contained in:
EntireTwix 2021-07-04 03:33:17 -07:00
parent c9562d26c7
commit b6344da31d
3 changed files with 37 additions and 18 deletions

View file

@ -41,6 +41,9 @@ private:
public: public:
std::string admin_account; std::string admin_account;
size_t NumOfUsers() const noexcept;
uint64_t NumOfLogs() const noexcept;
#if CONSERVATIVE_DISK_SAVE #if CONSERVATIVE_DISK_SAVE
bool GetChangeState() const noexcept; bool GetChangeState() const noexcept;
#endif #endif

View file

@ -28,21 +28,6 @@ void SaveSig(int s)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
std::cout
<< "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled")
<< "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled")
<< "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled")
<< "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled")
<< "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled")
<< "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled")
#if MULTI_THREADED
<< "\n\nThreads : " << get_nprocs() + 1
<< "\nMulti threading : enabled"
#else
<< "\n\nThreads : " << 2
<< "\nMulti threading : disabled"
#endif
<< std::endl; //flushing before EventLoop
static_assert(bool(MAX_LOG_SIZE) == bool(PRE_LOG_SIZE), "You must either utilize both or neither logging variables.\n"); static_assert(bool(MAX_LOG_SIZE) == bool(PRE_LOG_SIZE), "You must either utilize both or neither logging variables.\n");
static_assert(MAX_LOG_SIZE >= PRE_LOG_SIZE, "The maximum log size must be larger than or equal to the amount preallocated.\n"); static_assert(MAX_LOG_SIZE >= PRE_LOG_SIZE, "The maximum log size must be larger than or equal to the amount preallocated.\n");
@ -58,10 +43,28 @@ int main(int argc, char **argv)
std::cerr << "ERROR: CCash MUST be ran as root\n"; std::cerr << "ERROR: CCash MUST be ran as root\n";
return 0; return 0;
} }
std::cout
<< "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled")
<< "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled")
<< "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled")
<< "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled")
<< "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled")
<< "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled")
#if MULTI_THREADED
<< "\n\nThreads : " << get_nprocs() + 1
<< "\nMulti threading : enabled";
#else
<< "\n\nThreads : " << 2
<< "\nMulti threading : disabled";
#endif
//Loading users from users.json //Loading users from users.json
bank.Load(); bank.Load();
std::cout << "\n\nLoaded " << bank.NumOfUsers() << " Users"
<< "\nLoaded " << bank.NumOfLogs() << " Logs"
<< std::endl; //flushing before EventLoop
//Sig handling //Sig handling
struct sigaction sigIntHandler; struct sigaction sigIntHandler;

View file

@ -1,5 +1,7 @@
#include "bank.h" #include "bank.h"
using namespace drogon;
__attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) noexcept __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) noexcept
{ {
if (name.size() < min_name_size || name.size() > max_name_size) if (name.size() < min_name_size || name.size() > max_name_size)
@ -16,7 +18,19 @@ __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name)
return true; return true;
} }
using namespace drogon; //NOT THREAD SAFE
size_t Bank::NumOfUsers() const noexcept { return users.size(); }
//NOT THREAD SAFE
uint64_t Bank::NumOfLogs() const noexcept
{
uint64_t res;
for (const auto &u : users)
{
res += u.second.log.data.size();
}
return res;
}
#if CONSERVATIVE_DISK_SAVE #if CONSERVATIVE_DISK_SAVE
bool Bank::GetChangeState() const noexcept bool Bank::GetChangeState() const noexcept
@ -29,8 +43,7 @@ bool Bank::GetChangeState() const noexcept
} }
#endif #endif
BankResponse BankResponse Bank::GetBal(const std::string &name) const noexcept
Bank::GetBal(const std::string &name) const noexcept
{ {
uint64_t res = 0; uint64_t res = 0;
users.if_contains(name, [&res](const User &u) { res = u.balance + 1; }); users.if_contains(name, [&res](const User &u) { res = u.balance + 1; });