diff options
Diffstat (limited to 'src/runtime/MEMUtils.cpp')
-rw-r--r-- | src/runtime/MEMUtils.cpp | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/src/runtime/MEMUtils.cpp b/src/runtime/MEMUtils.cpp index be6a3b690d..5ae1c2abef 100644 --- a/src/runtime/MEMUtils.cpp +++ b/src/runtime/MEMUtils.cpp @@ -27,7 +27,7 @@ #ifndef BARE_METAL #include <fstream> -#include <regex> +#include <iterator> #include <sstream> #endif // ifndef BARE_METAL @@ -43,45 +43,33 @@ void parse_mem_info(size_t &total, size_t &free, size_t &buffer) size_t memfree = 0; std::ifstream meminfo_f; meminfo_f.open("/proc/meminfo", std::ios::in); + if(meminfo_f.is_open()) { - std::stringstream str_stream; - str_stream << meminfo_f.rdbuf(); - const std::string str = str_stream.str(); -#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED - try + std::string line; + while(bool(getline(meminfo_f, line))) { -#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ - std::smatch match; - if(std::regex_search(str, match, std::regex("MemTotal: (.*)kB")) && match.size() > 1) + std::istringstream iss(line); + std::vector<std::string> tokens((std::istream_iterator<std::string>(iss)), + std::istream_iterator<std::string>()); + if(tokens[0] == "MemTotal:") { - const std::string result = match.str(1); - total = arm_compute::support::cpp11::stoul(result, nullptr); + total = arm_compute::support::cpp11::stoul(tokens[1], nullptr); } - if(std::regex_search(str, match, std::regex("MemFree: (.*)kB")) && match.size() > 1) + else if(tokens[0] == "MemFree:") { - const std::string result = match.str(1); - memfree = arm_compute::support::cpp11::stoul(result, nullptr); + memfree = arm_compute::support::cpp11::stoul(tokens[1], nullptr); } - if(std::regex_search(str, match, std::regex("Buffers: (.*)kB")) && match.size() > 1) + else if(tokens[0] == "Buffers:") { - const std::string result = match.str(1); - buffer = arm_compute::support::cpp11::stoul(result, nullptr); + buffer = arm_compute::support::cpp11::stoul(tokens[1], nullptr); } - if(std::regex_search(str, match, std::regex("Cached: (.*)kB")) && match.size() > 1) + else if(tokens[0] == "Cached:") { - const std::string result = match.str(1); - memcache = arm_compute::support::cpp11::stoul(result, nullptr); + memcache = arm_compute::support::cpp11::stoul(tokens[1], nullptr); } - free = memfree + (buffer + memcache); -#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED - } - catch(std::regex_error &e) - { - // failed parsing /proc/meminfo - // return 0s on all fields } -#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ + free = memfree + (buffer + memcache); } #endif // ifndef BARE_METAL } |