Skip to content

Commit 841d3f5

Browse files
committed
Add more logs
1 parent 645a43b commit 841d3f5

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

samples/cpp/benchmark_app/main.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,42 @@
3737
#include "utils.hpp"
3838
// clang-format on
3939

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+
4076
namespace {
4177
bool parse_and_check_command_line(int argc, char* argv[]) {
4278
// ---------------------------Parsing and validating input
@@ -772,14 +808,23 @@ int main(int argc, char* argv[]) {
772808
auto startTime = Time::now();
773809

774810
std::ifstream modelStream(FLAGS_m, std::ios_base::binary | std::ios_base::in);
811+
auto importModelMemStart = getPeakMemoryUsage();
775812
if (!modelStream.is_open()) {
776813
throw std::runtime_error("Cannot open model file " + FLAGS_m);
777814
}
815+
778816
compiledModel = core.import_model(modelStream, device_name, device_config);
779817
modelStream.close();
780818

781819
auto duration_ms = get_duration_ms_till_now(startTime);
782820
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+
783828
slog::info << "Original model I/O paramteters:" << slog::endl;
784829
printInputAndOutputsInfoShort(compiledModel);
785830

src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ std::vector<std::shared_ptr<IGraph>> PluginCompilerAdapter::compileWS(const std:
110110
const Config& config) const {
111111
OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "PluginCompilerAdapter", "compileWS");
112112

113+
auto compileNetBegin = std::chrono::steady_clock::now();
114+
113115
std::shared_ptr<NetworkDescription> initNetworkDescription;
114116
std::shared_ptr<NetworkDescription> mainNetworkDescription;
115117

@@ -188,6 +190,11 @@ std::vector<std::shared_ptr<IGraph>> PluginCompilerAdapter::compileWS(const std:
188190

189191
_logger.debug("compile end");
190192

193+
auto compileNetEnd = std::chrono::steady_clock::now();
194+
std::cout << "Compile net time: "
195+
<< std::chrono::duration_cast<std::chrono::milliseconds>(compileNetEnd - compileNetBegin).count() << " ms"
196+
<< std::endl;
197+
191198
ze_graph_handle_t initGraphHandle = nullptr;
192199
ze_graph_handle_t mainGraphHandle = nullptr;
193200

src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ void PluginGraph::custom_export(std::ostream& stream,
6767
} else {
6868
if (_logger.level() >= ov::log::Level::INFO) {
6969
std::stringstream str;
70-
str << "Blob size: " << _blob.size() + initBlob.size() + 4 * sizeof(size_t) + xmlSize + binSize
70+
str << "Blob size: " << _blob.size() + initBlob.size()
71+
<< std::endl;
72+
str << "Blob size with weights: " << _blob.size() + initBlob.size() + 4 * sizeof(size_t) + xmlSize + binSize
7173
<< std::endl;
7274
_logger.info(str.str().c_str());
7375
}

0 commit comments

Comments
 (0)