From a8b81fdcdecd9f22c38dc18de31403705889bcf8 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Fri, 20 Mar 2020 13:20:33 +0100 Subject: [PATCH] Unify C/Python query module logging Summary: Make logging for operations with C/Python query modules (loading, closing, reloading) consistent. Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2734 --- src/query/plan/operator.cpp | 4 ++-- src/query/procedure/module.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 0e60d8aaf..45b7f3444 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -3836,8 +3836,8 @@ void CallCustomProcedure(const std::string_view &fully_qualified_procedure_name, proc_args.elems.emplace_back(std::get<2>(proc.opt_args[i]), &graph); } if (memory_limit) { - LOG(INFO) << "Running '" << fully_qualified_procedure_name - << "' with memory limit of " << *memory_limit << " bytes"; + DLOG(INFO) << "Running '" << fully_qualified_procedure_name + << "' with memory limit of " << *memory_limit << " bytes"; utils::LimitedMemoryResource limited_mem(memory, *memory_limit); mgp_memory proc_memory{&limited_mem}; CHECK(result->signature == &proc.results); diff --git a/src/query/procedure/module.cpp b/src/query/procedure/module.cpp index 899517f41..2a8d459bb 100644 --- a/src/query/procedure/module.cpp +++ b/src/query/procedure/module.cpp @@ -331,6 +331,7 @@ class PythonModule final : public Module { const override; private: + std::filesystem::path file_path_; py::Object py_module_; std::map> procedures_; }; @@ -344,6 +345,7 @@ PythonModule::~PythonModule() { bool PythonModule::Load(std::filesystem::path file_path) { CHECK(!py_module_) << "Attempting to load an already loaded module..."; LOG(INFO) << "Loading module " << file_path << " ..."; + file_path_ = file_path; auto gil = py::EnsureGIL(); auto maybe_exc = py::AppendToSysPath(file_path.parent_path().c_str()); if (maybe_exc) { @@ -354,7 +356,10 @@ bool PythonModule::Load(std::filesystem::path file_path) { WithModuleRegistration(&procedures_, [&](auto *module_def, auto *memory) { return ImportPyModule(file_path.stem().c_str(), module_def); }); - if (py_module_) return true; + if (py_module_) { + LOG(INFO) << "Loaded module " << file_path; + return true; + } auto exc_info = py::FetchError().value(); LOG(ERROR) << "Unable to load module " << file_path << "; " << exc_info; return false; @@ -363,11 +368,13 @@ bool PythonModule::Load(std::filesystem::path file_path) { bool PythonModule::Close() { CHECK(py_module_) << "Attempting to close a module that has not been loaded..."; + LOG(INFO) << "Closing module " << file_path_ << " ..."; // Deleting procedures will probably release PyObject closures, so we need to // take the GIL. auto gil = py::EnsureGIL(); procedures_.clear(); py_module_ = py::Object(nullptr); + LOG(INFO) << "Closed module " << file_path_; return true; } @@ -450,6 +457,7 @@ bool ModuleRegistry::ReloadModuleNamed(const std::string_view &name) { modules_.erase(found_it); return false; } + LOG(INFO) << "Reloaded module '" << name << "'"; return true; } @@ -461,6 +469,7 @@ bool ModuleRegistry::ReloadAllModules() { modules_.erase(name); return false; } + LOG(INFO) << "Reloaded module '" << name << "'"; } return true; }