Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add peak mem diff for bapp #28931

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
#include "utils.hpp"
// clang-format on

#if defined _WIN32

#include <windows.h>

#include <psapi.h>

int64_t getPeakMemoryUsage() {
PROCESS_MEMORY_COUNTERS memCounters;
GetProcessMemoryInfo(GetCurrentProcess(), &memCounters, sizeof(memCounters));
return memCounters.PeakWorkingSetSize / 1000;
}

#else

#include <fstream>
#include <regex>
#include <sstream>

int64_t getPeakMemoryUsage() {
size_t peakMemUsageKB = 0;

std::ifstream statusFile("/proc/self/status");
std::string line;
std::regex vmPeakRegex("VmPeak:");
std::smatch vmMatch;
while (std::getline(statusFile, line)) {
if (std::regex_search(line, vmMatch, vmPeakRegex)) {
std::istringstream iss(vmMatch.suffix());
iss >> peakMemUsageKB;
}
}
return static_cast<int64_t>(peakMemUsageKB);
}

#endif

namespace {
bool parse_and_check_command_line(int argc, char* argv[]) {
// ---------------------------Parsing and validating input
Expand Down Expand Up @@ -762,14 +798,23 @@ int main(int argc, char* argv[]) {
auto startTime = Time::now();

std::ifstream modelStream(FLAGS_m, std::ios_base::binary | std::ios_base::in);
auto importModelMemStart = getPeakMemoryUsage();
if (!modelStream.is_open()) {
throw std::runtime_error("Cannot open model file " + FLAGS_m);
}

compiledModel = core.import_model(modelStream, device_name, device_config);
modelStream.close();

auto duration_ms = get_duration_ms_till_now(startTime);
slog::info << "Import model took " << double_to_string(duration_ms) << " ms" << slog::endl;

auto importModelMemEnd = getPeakMemoryUsage();

slog::info << "Start of compilation memory usage: Peak " << importModelMemStart << " KB" << slog::endl;
slog::info << "End of compilation memory usage: Peak " << importModelMemEnd << " KB" << slog::endl;
slog::info << "Peak diff " << importModelMemEnd - importModelMemStart << " KB" << slog::endl;

slog::info << "Original model I/O paramteters:" << slog::endl;
printInputAndOutputsInfoShort(compiledModel);

Expand Down
Loading