X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=utils%2FUtils.cpp;h=a5c6a95a2a105eba064559588b2d23c5e915fd4e;hb=HEAD;hp=f6aff6f92dadea153b77fc8e596827d7f8c5b1c2;hpb=8140e1e155d3430992fa46e04ef8938ff09ffd2d;p=platform%2Fupstream%2Farmcl.git diff --git a/utils/Utils.cpp b/utils/Utils.cpp index f6aff6f..a5c6a95 100644 --- a/utils/Utils.cpp +++ b/utils/Utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -66,14 +66,17 @@ void discard_comments_and_spaces(std::ifstream &fs) } } // namespace -int run_example(int argc, const char **argv, example &func) +#ifndef BENCHMARK_EXAMPLES +int run_example(int argc, char **argv, std::unique_ptr example) { std::cout << "\n" << argv[0] << "\n\n"; try { - func(argc, argv); + example->do_setup(argc, argv); + example->do_run(); + example->do_teardown(); std::cout << "\nTest passed\n"; return 0; @@ -99,6 +102,7 @@ int run_example(int argc, const char **argv, example &func) return -1; } +#endif /* BENCHMARK_EXAMPLES */ void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b) { @@ -187,5 +191,39 @@ std::tuple, bool, std::string> parse_npy_header(std:: return std::make_tuple(shape, fortran_order, typestr); } + +/** This function returns the amount of memory free reading from /proc/meminfo + * + * @return The free memory in kB + */ +uint64_t get_mem_free_from_meminfo() +{ + std::string line_attribute; + std::ifstream file_meminfo("/proc/meminfo"); + + if(file_meminfo.is_open()) + { + while(!(file_meminfo >> line_attribute).fail()) + { + //Test if is the line containing MemFree + if(line_attribute == "MemFree:") + { + uint64_t mem_available; + if(!(file_meminfo >> mem_available).fail()) + { + return mem_available; + } + else + { + return 0; + } + } + // if it's not MemFree ignore rest of the line + file_meminfo.ignore(std::numeric_limits::max(), '\n'); + } + } + // Nothing found or an error during opening the file + return 0; +} } // namespace utils } // namespace arm_compute