qulonglong freeMemory() { // Retrieve and return in bytes the available amount of physical memory qulonglong res = 0; #if defined(Q_OS_WIN) MEMORYSTATUSEX memoryStatus; memoryStatus.dwLength = sizeof(memoryStatus); GlobalMemoryStatusEx(&memoryStatus); res = qulonglong(memoryStatus.ullAvailPhys); #elif defined(Q_OS_LINUX) res = qulonglong(sysconf(_SC_AVPHYS_PAGES))*qulonglong(sysconf(_SC_PAGESIZE)); #elif defined(Q_OS_MAC) vm_statistics_data_t vmStats; mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT; host_statistics(mach_host_self(), HOST_VM_INFO, host_info_t(&vmStats), &infoCount); res = (qulonglong(vmStats.free_count)+qulonglong(vmStats.inactive_count))*qulonglong(vm_page_size); #else #error Unsupported platform #endif return res; }
View::View(node_id_t node_id, std::string cf) : node_id_(node_id), master_id_(0), period_(500) { LOG_INFO("loading config file %s ...", cf.c_str()); YAML::Node config; if (cf.empty()) { // default only one node config = YAML::LoadFile("config/localhost-1.yaml"); node_id_ = 0; } else { config = YAML::LoadFile(cf); } if (config == NULL) { printf("cannot open config file: %s.", cf.c_str()); } YAML::Node nodes = config["host"]; YAML::Node lease = config["lease"]; for (std::size_t i = 0; i < nodes.size(); i++) { YAML::Node node = nodes[i]; std::string name = node["name"].as<std::string>(); std::string addr = node["addr"].as<std::string>(); uint32_t port = node["port"].as<int>(); // set a node in view host_info_t host_info = host_info_t(name, addr, port); host_nodes_.push_back(host_info); } size_ = host_nodes_.size(); if (lease) { master_id_ = lease["master_id"].as<int>(); period_ = lease["period"].as<int>(); } else { LOG_INFO("No lease Node Found, using default master_id/0 period/500"); } #if MODE_TYPE == 1 YAML::Node rs = config["rs"]; if (rs) { rs_x_ = rs["x"].as<int>(); rs_n_ = rs["n"].as<int>(); rs_qr_ = rs["qr"].as<int>(); rs_qw_ = rs["qw"].as<int>(); rs_f_ = rs["f"].as<int>(); } else { LOG_INFO("No RS Node Found!!, using Default function to compute"); rs_n_ = size_; if (rs_n_ == 1) { rs_x_ = 1; } else { if (rs_n_ % 2 == 0) { rs_x_ = 2; } else { rs_x_ = 3; } } rs_qr_ = (rs_n_ + rs_x_) / 2; rs_qw_ = rs_qr_; rs_f_ = rs_n_ - rs_qr_; } #endif if (node_id_ >= size_) { std::cout << "Node_Id " << node_id_ << " > host_nodes_.size " << size_ << "Invalid!" << std::endl; std::cout << "Set Node_Id = 0" << std::endl; node_id_ = 0; } LOG_INFO("config file loaded"); }