From 4a55d0841b3025432ee3150d429df733d9b6c994 Mon Sep 17 00:00:00 2001 From: Guido Reina Date: Thu, 23 Sep 2021 18:00:37 +0200 Subject: [PATCH] cleanup --- core/include/mmcore/Call.h | 18 +++++--- core/include/mmcore/CallProfiling.h | 6 +-- .../mmcore/factories/CallAutoDescription.h | 8 ++++ core/src/Call.cpp | 16 ++++++- core/src/CallProfiling.cpp | 44 +++++++------------ core/src/MegaMolGraph.cpp | 9 ---- core/src/PerformanceQueryManager.cpp | 2 +- .../gui/src/graph/GraphCollection.cpp | 4 +- 8 files changed, 54 insertions(+), 53 deletions(-) diff --git a/core/include/mmcore/Call.h b/core/include/mmcore/Call.h index d600e5b269..0bbcc90dde 100644 --- a/core/include/mmcore/Call.h +++ b/core/include/mmcore/Call.h @@ -104,12 +104,19 @@ namespace core { return caps; } + void SetCallbackNames(std::vector names); + + const std::string& GetCallbackName(uint32_t idx) const; + + uint32_t GetCallbackCount() const { + return static_cast(callback_names.size()); + } + #ifdef PROFILING const CallProfiling& GetProfiling() const { return profiling; } #endif private: - /** The callee connected by this call */ CalleeSlot *callee; @@ -121,15 +128,14 @@ namespace core { /** The function id mapping */ unsigned int *funcMap; + std::vector callback_names; + + inline static std::string err_out_of_bounds = "index out of bounds"; + #ifdef PROFILING - friend class MegaMolGraph; friend class PerformanceQueryManager; CallProfiling profiling; - - void setProfilingInfo(std::vector names) { - profiling.setProfilingInfo(std::move(names), this); - } #endif // PROFILING protected: CallCapabilities caps; diff --git a/core/include/mmcore/CallProfiling.h b/core/include/mmcore/CallProfiling.h index 128d474482..0e594f554b 100644 --- a/core/include/mmcore/CallProfiling.h +++ b/core/include/mmcore/CallProfiling.h @@ -31,8 +31,7 @@ namespace core { uint32_t GetNumGPUSamples(uint32_t func) const; std::array GetGPUHistory(uint32_t func) const; - uint32_t GetFuncCount() const; - const std::string& GetFuncName(uint32_t i) const; + void SetParent(Call *parent); void ShutdownProfiling() const; @@ -43,11 +42,8 @@ namespace core { friend class Call; friend class PerformanceQueryManager; - void setProfilingInfo(std::vector names, Call *parent); - std::vector cpu_history; std::vector gpu_history; - std::vector callback_names; Call *parent_call = nullptr; // this only works since the MegaMol build is static, otherwise a global round-robin could be a problem... inline static PerformanceQueryManager *qm = nullptr; diff --git a/core/include/mmcore/factories/CallAutoDescription.h b/core/include/mmcore/factories/CallAutoDescription.h index 2e5e8129a0..d5bc0f03d6 100644 --- a/core/include/mmcore/factories/CallAutoDescription.h +++ b/core/include/mmcore/factories/CallAutoDescription.h @@ -10,6 +10,9 @@ #include "CallDescription.h" +#include +#include + namespace megamol::core::factories { /** @@ -50,6 +53,11 @@ namespace megamol::core::factories { Call* CreateCall() const override { T* c = new T(); c->SetClassName(this->ClassName()); + std::vector callbacks(this->FunctionCount()); + for (uint32_t x = 0; x < this->FunctionCount(); ++x) { + callbacks[x] = this->FunctionName(x); + } + c->SetCallbackNames(callbacks); return this->describeCall(c); } diff --git a/core/src/Call.cpp b/core/src/Call.cpp index 80b8319b98..97a7f018c7 100644 --- a/core/src/Call.cpp +++ b/core/src/Call.cpp @@ -24,7 +24,6 @@ using namespace megamol::core; * Call::Call */ Call::Call(void) : callee(nullptr), caller(nullptr), className(nullptr), funcMap(nullptr) { - // intentionally empty } @@ -93,3 +92,18 @@ bool Call::operator()(unsigned int func) { // res ? "true" : "false", this->callee == nullptr ? "no callee" : "from callee"); return res; } + +void Call::SetCallbackNames(std::vector names) { + callback_names = std::move(names); +#ifdef PROFILING + profiling.SetParent(this); +#endif +} + +const std::string& Call::GetCallbackName(uint32_t idx) const { + if (idx < callback_names.size()) { + return callback_names[idx]; + } else { + return err_out_of_bounds; + } +} diff --git a/core/src/CallProfiling.cpp b/core/src/CallProfiling.cpp index ef7fe4ad91..8c07094473 100644 --- a/core/src/CallProfiling.cpp +++ b/core/src/CallProfiling.cpp @@ -5,7 +5,6 @@ using namespace megamol; using namespace core; CallProfiling::CallProfiling() { - } CallProfiling::~CallProfiling() { @@ -17,21 +16,21 @@ uint32_t CallProfiling::GetSampleHistoryLength() { } double CallProfiling::GetLastCPUTime(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return cpu_history[func].last_value(); else return -1.0; } double CallProfiling::GetAverageCPUTime(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return cpu_history[func].average(); else return -1.0; } uint32_t CallProfiling::GetNumCPUSamples(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return cpu_history[func].samples(); else return 0; @@ -39,28 +38,28 @@ uint32_t CallProfiling::GetNumCPUSamples(uint32_t func) const { std::array CallProfiling::GetCPUHistory( uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return cpu_history[func].copyHistory(); else return std::array{}; } double CallProfiling::GetLastGPUTime(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return gpu_history[func].last_value(); else return -1.0; } double CallProfiling::GetAverageGPUTime(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return gpu_history[func].average(); else return -1.0; } uint32_t CallProfiling::GetNumGPUSamples(uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return gpu_history[func].samples(); else return 0; @@ -68,21 +67,19 @@ uint32_t CallProfiling::GetNumGPUSamples(uint32_t func) const { std::array CallProfiling::GetGPUHistory( uint32_t func) const { - if (func < callback_names.size()) + if (func < parent_call->GetCallbackCount()) return gpu_history[func].copyHistory(); else return std::array{}; } -uint32_t CallProfiling::GetFuncCount() const { - return static_cast(callback_names.size()); -} - -const std::string& CallProfiling::GetFuncName(uint32_t i) const { - if (i < callback_names.size()) { - return callback_names[i]; - } else { - return err_oob; +void CallProfiling::SetParent(Call* parent) { + cpu_history.resize(parent->GetCallbackCount()); + gpu_history.resize(parent->GetCallbackCount()); + parent_call = parent; + if (parent_call->GetCapabilities().OpenGLRequired()) { + InitializeQueryManager(); + qm->AddCall(parent_call); } } @@ -98,17 +95,6 @@ void CallProfiling::CollectGPUPerformance() { } } -void CallProfiling::setProfilingInfo(std::vector names, Call* parent) { - callback_names = std::move(names); - cpu_history.resize(callback_names.size()); - gpu_history.resize(callback_names.size()); - parent_call = parent; - if (parent_call->GetCapabilities().OpenGLRequired()) { - InitializeQueryManager(); - qm->AddCall(parent_call); - } -} - void CallProfiling::ShutdownProfiling() const { if (qm != nullptr) { qm->RemoveCall(parent_call); diff --git a/core/src/MegaMolGraph.cpp b/core/src/MegaMolGraph.cpp index d8d7e76265..2d86ff173d 100644 --- a/core/src/MegaMolGraph.cpp +++ b/core/src/MegaMolGraph.cpp @@ -633,15 +633,6 @@ bool megamol::core::MegaMolGraph::add_call(CallInstantiationRequest_t const& req return false; } -#ifdef PROFILING - // TODO: move to CallAutoDescription::CreateCall() if possible - std::vector callbacks(call_description->FunctionCount()); - for (uint32_t x = 0; x < call_description->FunctionCount(); ++x) { - callbacks[x] = call_description->FunctionName(x); - } - call->setProfilingInfo(callbacks); -#endif - log("create call: " + request.from + " -> " + request.to + " (" + std::string(call_description->ClassName()) + ")"); this->call_list_.emplace_front(CallInstance_t{call, request}); diff --git a/core/src/PerformanceQueryManager.cpp b/core/src/PerformanceQueryManager.cpp index 099e58f9c4..1b9a3624e3 100644 --- a/core/src/PerformanceQueryManager.cpp +++ b/core/src/PerformanceQueryManager.cpp @@ -43,7 +43,7 @@ void PerformanceQueryManager::ResetGLProfiling() { void PerformanceQueryManager::AdvanceGLProfiling() { if (all_calls.empty()) return; - starting_func = (starting_func + 1) % all_calls[starting_call]->profiling.GetFuncCount(); + starting_func = (starting_func + 1) % all_calls[starting_call]->GetCallbackCount(); if (starting_func == 0) { // we wrapped, advance to next call! starting_call = (starting_call + 1) % all_calls.size(); diff --git a/frontend/services/gui/src/graph/GraphCollection.cpp b/frontend/services/gui/src/graph/GraphCollection.cpp index cfa06f75ed..85290d9458 100644 --- a/frontend/services/gui/src/graph/GraphCollection.cpp +++ b/frontend/services/gui/src/graph/GraphCollection.cpp @@ -647,7 +647,7 @@ bool megamol::gui::GraphCollection::add_update_project_from_core( gui_utils::CaseInsensitiveStringCompare(gcall.from, ccall.request.from) && gui_utils::CaseInsensitiveStringCompare(gcall.to, ccall.request.to)) { const auto& profiling = ccall.callPtr->GetProfiling(); - auto func_count = profiling.GetFuncCount(); + auto func_count = ccall.callPtr->GetCallbackCount(); std::vector prof; prof.resize(func_count); for (uint32_t i = 0; i < func_count; i++) { @@ -659,7 +659,7 @@ bool megamol::gui::GraphCollection::add_update_project_from_core( prof[i].agput = profiling.GetAverageGPUTime(i); prof[i].ngpus = profiling.GetNumGPUSamples(i); prof[i].hgpu = profiling.GetGPUHistory(i); - prof[i].name = profiling.GetFuncName(i); + prof[i].name = ccall.callPtr->GetCallbackName(i); } gcall.ptr.lock()->SetProfilingValues(prof); }