From 8e5174c1b9531e8e9c457c2b976cf2c929825e73 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Tue, 4 Dec 2018 11:43:23 +0000 Subject: COMPMID-1817 Replace std::regex with POSIX C regex in runtime Change-Id: I6066cfc8c1bc16e212171cc9eb4bd6a3ab003485 Reviewed-on: https://review.mlplatform.org/318 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Reviewed-by: Anthony Barbier --- src/runtime/MEMUtils.cpp | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'src/runtime/MEMUtils.cpp') 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 -#include +#include #include #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 tokens((std::istream_iterator(iss)), + std::istream_iterator()); + 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 } -- cgit v1.2.1