| 39 | } |
| 40 | |
| 41 | std::string find_codegen_bin() { |
| 42 | // first check whether flex_home env exists |
| 43 | std::string flex_home; |
| 44 | std::string codegen_bin; |
| 45 | char* flex_home_char = getenv("FLEX_HOME"); |
| 46 | if (flex_home_char == nullptr) { |
| 47 | // infer flex_home from current binary' directory |
| 48 | // get the path of current binary |
| 49 | std::string flex_home_str = get_current_dir(); |
| 50 | // usr/loca/bin/ |
| 51 | flex_home_str = flex_home_str.substr(0, flex_home_str.find_last_of("/")); |
| 52 | // usr/local/ |
| 53 | |
| 54 | LOG(INFO) << "infer flex_home as installed, flex_home: " << flex_home_str; |
| 55 | // check codegen_bin path exists |
| 56 | codegen_bin = flex_home_str + "/bin/" + CODEGEN_BIN; |
| 57 | // if flex_home exists, return flex_home |
| 58 | if (std::filesystem::exists(codegen_bin)) { |
| 59 | return codegen_bin; |
| 60 | } else { |
| 61 | // if not found, try as if it is in build directory |
| 62 | // flex/build/ |
| 63 | flex_home_str = flex_home_str.substr(0, flex_home_str.find_last_of("/")); |
| 64 | // flex/ |
| 65 | LOG(INFO) << "infer flex_home as build, flex_home: " << flex_home_str; |
| 66 | codegen_bin = flex_home_str + "/bin/" + CODEGEN_BIN; |
| 67 | if (std::filesystem::exists(codegen_bin)) { |
| 68 | return codegen_bin; |
| 69 | } else { |
| 70 | LOG(FATAL) << "codegen bin not exists: "; |
| 71 | return ""; |
| 72 | } |
| 73 | } |
| 74 | } else { |
| 75 | flex_home = std::string(flex_home_char); |
| 76 | LOG(INFO) << "flex_home env exists, flex_home: " << flex_home; |
| 77 | codegen_bin = flex_home + "/bin/" + CODEGEN_BIN; |
| 78 | if (std::filesystem::exists(codegen_bin)) { |
| 79 | return codegen_bin; |
| 80 | } else { |
| 81 | LOG(FATAL) << "codegen bin not exists: "; |
| 82 | return ""; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | std::pair<uint64_t, uint64_t> get_total_physical_memory_usage() { |
| 88 | struct sysinfo memInfo; |
no test coverage detected