Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
reinago committed Sep 23, 2021
1 parent 4f9b23d commit 4a55d08
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 53 deletions.
18 changes: 12 additions & 6 deletions core/include/mmcore/Call.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,19 @@ namespace core {
return caps;
}

void SetCallbackNames(std::vector<std::string> names);

const std::string& GetCallbackName(uint32_t idx) const;

uint32_t GetCallbackCount() const {
return static_cast<uint32_t>(callback_names.size());
}

#ifdef PROFILING
const CallProfiling& GetProfiling() const { return profiling; }
#endif

private:

/** The callee connected by this call */
CalleeSlot *callee;

Expand All @@ -121,15 +128,14 @@ namespace core {
/** The function id mapping */
unsigned int *funcMap;

std::vector<std::string> 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<std::string> names) {
profiling.setProfilingInfo(std::move(names), this);
}
#endif // PROFILING
protected:
CallCapabilities caps;
Expand Down
6 changes: 1 addition & 5 deletions core/include/mmcore/CallProfiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ namespace core {
uint32_t GetNumGPUSamples(uint32_t func) const;
std::array<double, PerformanceHistory::buffer_length> GetGPUHistory(uint32_t func) const;

uint32_t GetFuncCount() const;
const std::string& GetFuncName(uint32_t i) const;
void SetParent(Call *parent);

void ShutdownProfiling() const;

Expand All @@ -43,11 +42,8 @@ namespace core {
friend class Call;
friend class PerformanceQueryManager;

void setProfilingInfo(std::vector<std::string> names, Call *parent);

std::vector<PerformanceHistory> cpu_history;
std::vector<PerformanceHistory> gpu_history;
std::vector<std::string> 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;
Expand Down
8 changes: 8 additions & 0 deletions core/include/mmcore/factories/CallAutoDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "CallDescription.h"

#include <string>
#include <vector>

namespace megamol::core::factories {

/**
Expand Down Expand Up @@ -50,6 +53,11 @@ namespace megamol::core::factories {
Call* CreateCall() const override {
T* c = new T();
c->SetClassName(this->ClassName());
std::vector<std::string> callbacks(this->FunctionCount());
for (uint32_t x = 0; x < this->FunctionCount(); ++x) {
callbacks[x] = this->FunctionName(x);
}
c->SetCallbackNames(callbacks);
return this->describeCall(c);
}

Expand Down
16 changes: 15 additions & 1 deletion core/src/Call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using namespace megamol::core;
* Call::Call
*/
Call::Call(void) : callee(nullptr), caller(nullptr), className(nullptr), funcMap(nullptr) {
// intentionally empty
}


Expand Down Expand Up @@ -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<std::string> 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;
}
}
44 changes: 15 additions & 29 deletions core/src/CallProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using namespace megamol;
using namespace core;

CallProfiling::CallProfiling() {

}

CallProfiling::~CallProfiling() {
Expand All @@ -17,72 +16,70 @@ 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;
}

std::array<double, PerformanceHistory::buffer_length> 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, PerformanceHistory::buffer_length>{};
}

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;
}

std::array<double, PerformanceHistory::buffer_length> 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<double, PerformanceHistory::buffer_length>{};
}

uint32_t CallProfiling::GetFuncCount() const {
return static_cast<uint32_t>(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);
}
}

Expand All @@ -98,17 +95,6 @@ void CallProfiling::CollectGPUPerformance() {
}
}

void CallProfiling::setProfilingInfo(std::vector<std::string> 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);
Expand Down
9 changes: 0 additions & 9 deletions core/src/MegaMolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,6 @@ bool megamol::core::MegaMolGraph::add_call(CallInstantiationRequest_t const& req
return false;
}

#ifdef PROFILING
// TODO: move to CallAutoDescription<T>::CreateCall() if possible
std::vector<std::string> 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});

Expand Down
2 changes: 1 addition & 1 deletion core/src/PerformanceQueryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions frontend/services/gui/src/graph/GraphCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gui::Call::Profiling> prof;
prof.resize(func_count);
for (uint32_t i = 0; i < func_count; i++) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 4a55d08

Please sign in to comment.