-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
115 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <ostream> | ||
#include <string> | ||
#include <arpa/inet.h> | ||
#include <ifaddrs.h> | ||
#include <netinet/in.h> | ||
#include <sys/socket.h> | ||
|
||
|
||
std::string getLocalIP() { | ||
struct ifaddrs *ifAddrStruct = NULL; | ||
void *tmpAddrPtr = NULL; | ||
std::string localIP; | ||
getifaddrs(&ifAddrStruct); | ||
while (ifAddrStruct != NULL) { | ||
if (ifAddrStruct->ifa_addr->sa_family == AF_INET) { | ||
tmpAddrPtr = &((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr; | ||
char addressBuffer[INET_ADDRSTRLEN]; | ||
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); | ||
std::string interfaceName(ifAddrStruct->ifa_name); | ||
if (interfaceName == "en0" || interfaceName == "eth0") { | ||
return addressBuffer; | ||
} | ||
} | ||
ifAddrStruct = ifAddrStruct->ifa_next; | ||
} | ||
return ""; | ||
} | ||
|
||
struct Options { | ||
int node_id; | ||
int node_num; | ||
int cpu; | ||
uint64_t mempry; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, Options& options) { | ||
os << "node information: {" << std::endl; | ||
os << '\t' << "node_id: " << options.node_id << std::endl | ||
<< '\t' << "node_num: " << options.node_num << std::endl | ||
<< '\t' << "mempry: " << options.mempry << std::endl | ||
<< '\t' << "cpu: " << options.cpu << std::endl; | ||
os << "}"<< std::endl; | ||
return os; | ||
} | ||
|
||
Options loadENV() { | ||
Options options; | ||
const char* env_p = std::getenv("NODE_ID"); | ||
if(env_p) | ||
options.node_id = std::stoi(env_p) - 1; | ||
else{ | ||
options.node_id = 0; | ||
} | ||
// std::cout<< "NODE_ID: " << options.node_id << std::endl; | ||
env_p = std::getenv("NODE_NUM"); | ||
if(env_p) | ||
options.node_num = std::stoi(env_p); | ||
else{ | ||
options.node_num = 1; | ||
} | ||
// std::cout<< "NODE_NUM: " << options.node_num << std::endl; | ||
env_p = std::getenv("MEMORY"); | ||
if(env_p) | ||
options.mempry = std::stoull(env_p) << 30; //4G | ||
else{ | ||
options.mempry = 2 << 30; //2G | ||
} | ||
// std::cout<< "MEMORY: " << options.mempry << std::endl; | ||
env_p = std::getenv("CPU"); | ||
if(env_p != nullptr) | ||
options.cpu = std::stoi(env_p); | ||
else{ | ||
options.cpu = 2; | ||
} | ||
// std::cout<< "CPU: " << options.cpu << std::endl; | ||
return options; | ||
} | ||
|
||
// void parserRawData() { | ||
|
||
// } |