aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/MEMUtils.cpp
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-12-04 11:43:23 +0000
committerMichalis Spyrou <michalis.spyrou@arm.com>2018-12-20 17:32:41 +0000
commit8e5174c1b9531e8e9c457c2b976cf2c929825e73 (patch)
treea23a489b2c5c03754fabcf678224a7ea54c68b91 /src/runtime/MEMUtils.cpp
parent89124346020553068abc66a8f083193fbbdac03e (diff)
downloadComputeLibrary-8e5174c1b9531e8e9c457c2b976cf2c929825e73.tar.gz
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 <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Anthony Barbier <Anthony.barbier@arm.com>
Diffstat (limited to 'src/runtime/MEMUtils.cpp')
-rw-r--r--src/runtime/MEMUtils.cpp44
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
}