Skip to content

Commit

Permalink
profiler functions to engage in Matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
hkhauke committed Feb 7, 2024
1 parent 0fce9f3 commit fd7fb77
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ class CjvxMexCallsProfiler: public CjvxMexCallsMin
{
protected:
std::string varNameHdlMatlab = "hdl_profile_data";

std::string commandProfileConfig = "jvxProfileConfig";
std::string commandProfileStart = "jvxProfileStart";
std::string commandProfileStep = "jvxProfileStep";
std::string commandProfileStop = "jvxProfileStop";

jvxBool debugStartDone = false;

public:
std::map<std::string, jvx_profiler_data_entry*> registeredProfilerData;
jvxErrorType register_profiling_data(jvx_profiler_data_entry*, const std::string& nm);
jvxErrorType unregister_profiling_data(const std::string& nm);
jvxErrorType provideDataMexCall();
static jvxErrorType jvx_register_entry_profiling_data_cb(jvx_profiler_data_entry* dat, const char* name, jvxHandle* inst);
static jvxErrorType jvx_unregister_entry_profiling_data_cb(const char* name, jvxHandle* inst);

jvxErrorType profile_start_in_process();
jvxErrorType profile_step_in_process();
jvxErrorType profile_config_on_prepare();
jvxErrorType profile_stop_on_postprocess();
};

#endif
72 changes: 72 additions & 0 deletions sources/jvxLibraries/jvxLexternalCall/src/CjvxMexCallsProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,76 @@ CjvxMexCallsProfiler::jvx_unregister_entry_profiling_data_cb(const char* name, j
return JVX_ERROR_INVALID_ARGUMENT;
}

jvxErrorType
CjvxMexCallsProfiler::profile_start_in_process()
{
if (!debugStartDone)
{
std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab + "; " + CjvxMexCallsProfiler::varNameHdlMatlab +
" = " + CjvxMexCallsProfiler::commandProfileStart + "(" + CjvxMexCallsProfiler::varNameHdlMatlab + "); ";
jvxErrorType resM = _theExtCallHandler->executeExternalCommand(command.c_str());
if (resM != JVX_NO_ERROR)
{
jvxApiString astr;
_theExtCallHandler->getLastErrorReason(&astr);
_theExtCallHandler->postMessageExternal(("Last operation <" + command + "> failed, reason: <" + astr.std_str() + ">.").c_str(), true);
}
debugStartDone = true;
}
return JVX_NO_ERROR;
}

jvxErrorType
CjvxMexCallsProfiler::profile_step_in_process()
{

std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab +
"; [" + CjvxMexCallsProfiler::varNameHdlMatlab + "] = " + CjvxMexCallsProfiler::commandProfileStep + "(" + CjvxMexCallsProfiler::varNameHdlMatlab + "); ";
jvxErrorType resM = _theExtCallHandler->executeExternalCommand(command.c_str());

if (resM != JVX_NO_ERROR)
{
jvxApiString astr;
_theExtCallHandler->getLastErrorReason(&astr);
_theExtCallHandler->postMessageExternal(("Last operation <" + command + "> failed, reason: <" + astr.std_str() + ">.").c_str(), true);
}
return JVX_NO_ERROR;
}

jvxErrorType
CjvxMexCallsProfiler::profile_config_on_prepare()
{
jvxErrorType res = JVX_NO_ERROR;
jvxErrorType resM = JVX_NO_ERROR;
debugStartDone = false;
std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab + "; " + CjvxMexCallsProfiler::varNameHdlMatlab + " = " + CjvxMexCallsProfiler::commandProfileConfig + "(); ";
resM = _theExtCallHandler->executeExternalCommand(command.c_str());
if (resM != JVX_NO_ERROR)
{
jvxApiString astr;
_theExtCallHandler->getLastErrorReason(&astr);
_theExtCallHandler->postMessageExternal(("Last operation <" + command + "> failed, reason: <" + astr.std_str() + ">.").c_str(), true);

// Standard exception indicates that the debugger was detached!!
if (resM == JVX_ERROR_STANDARD_EXCEPTION)
{
res = resM;
}
}
return res;
}

jvxErrorType
CjvxMexCallsProfiler::profile_stop_on_postprocess()
{
std::string command = "global " + CjvxMexCallsProfiler::varNameHdlMatlab + " ; " + CjvxMexCallsProfiler::commandProfileStop + "(" + CjvxMexCallsProfiler::varNameHdlMatlab + "); ";
jvxErrorType resM = _theExtCallHandler->executeExternalCommand(command.c_str());
if (resM != JVX_NO_ERROR)
{
jvxApiString astr;
_theExtCallHandler->getLastErrorReason(&astr);
_theExtCallHandler->postMessageExternal(("Last operation failed, reason: <" + astr.std_str() + ">.").c_str(), true);
}
debugStartDone = false;
return JVX_NO_ERROR;
}

0 comments on commit fd7fb77

Please sign in to comment.