|
37 | 37 | #include "utils.hpp"
|
38 | 38 | // clang-format on
|
39 | 39 |
|
| 40 | +#if defined _WIN32 |
| 41 | + |
| 42 | +#include <windows.h> |
| 43 | + |
| 44 | +#include <psapi.h> |
| 45 | + |
| 46 | +int64_t getPeakMemoryUsage() { |
| 47 | + PROCESS_MEMORY_COUNTERS memCounters; |
| 48 | + GetProcessMemoryInfo(GetCurrentProcess(), &memCounters, sizeof(memCounters)); |
| 49 | + return memCounters.PeakWorkingSetSize / 1000; |
| 50 | +} |
| 51 | + |
| 52 | +#else |
| 53 | + |
| 54 | +#include <fstream> |
| 55 | +#include <regex> |
| 56 | +#include <sstream> |
| 57 | + |
| 58 | +int64_t getPeakMemoryUsage() { |
| 59 | + size_t peakMemUsageKB = 0; |
| 60 | + |
| 61 | + std::ifstream statusFile("/proc/self/status"); |
| 62 | + std::string line; |
| 63 | + std::regex vmPeakRegex("VmPeak:"); |
| 64 | + std::smatch vmMatch; |
| 65 | + while (std::getline(statusFile, line)) { |
| 66 | + if (std::regex_search(line, vmMatch, vmPeakRegex)) { |
| 67 | + std::istringstream iss(vmMatch.suffix()); |
| 68 | + iss >> peakMemUsageKB; |
| 69 | + } |
| 70 | + } |
| 71 | + return static_cast<int64_t>(peakMemUsageKB); |
| 72 | +} |
| 73 | + |
| 74 | +#endif |
| 75 | + |
40 | 76 | namespace {
|
41 | 77 | bool parse_and_check_command_line(int argc, char* argv[]) {
|
42 | 78 | // ---------------------------Parsing and validating input
|
@@ -772,14 +808,23 @@ int main(int argc, char* argv[]) {
|
772 | 808 | auto startTime = Time::now();
|
773 | 809 |
|
774 | 810 | std::ifstream modelStream(FLAGS_m, std::ios_base::binary | std::ios_base::in);
|
| 811 | + auto importModelMemStart = getPeakMemoryUsage(); |
775 | 812 | if (!modelStream.is_open()) {
|
776 | 813 | throw std::runtime_error("Cannot open model file " + FLAGS_m);
|
777 | 814 | }
|
| 815 | + |
778 | 816 | compiledModel = core.import_model(modelStream, device_name, device_config);
|
779 | 817 | modelStream.close();
|
780 | 818 |
|
781 | 819 | auto duration_ms = get_duration_ms_till_now(startTime);
|
782 | 820 | slog::info << "Import model took " << double_to_string(duration_ms) << " ms" << slog::endl;
|
| 821 | + |
| 822 | + auto importModelMemEnd = getPeakMemoryUsage(); |
| 823 | + |
| 824 | + slog::info << "Start of compilation memory usage: Peak " << importModelMemStart << " KB\n"; |
| 825 | + slog::info << "End of compilation memory usage: Peak " << importModelMemEnd << " KB\n"; |
| 826 | + slog::info << "Peak diff " << importModelMemStart - importModelMemEnd << " KB\n"; |
| 827 | + |
783 | 828 | slog::info << "Original model I/O paramteters:" << slog::endl;
|
784 | 829 | printInputAndOutputsInfoShort(compiledModel);
|
785 | 830 |
|
|
0 commit comments