-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a macro to remove fmi logging code in the callback function. #679
Conversation
This reverts commit cb4a3d3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good, just some comments about naming and defaults.
CMakeLists.txt
Outdated
|
||
# ============================================================================== | ||
# Global internal configuration | ||
# ============================================================================== | ||
|
||
# Configure logging in the fmi callback function | ||
if(LIBCOSIM_FMI_LOGGING) | ||
add_compile_definitions(LIBCOSIM_FMI_LOGGING=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the C++ preprocessor macro should be called LIBCOSIM_NO_FMI_LOGGING
instead, so that logging is enabled by default. (Practically, this just means that the #ifdef
tests should be replaced with #ifndef
.)
Note that I think it's fine that the CMake variable is called LIBCOSIM_FMI_LOGGING
, since its default value is defined by the option()
command. That's not the case for macros, they are undefined by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are updated.
conanfile.py
Outdated
@@ -29,10 +29,12 @@ class LibcosimConan(ConanFile): | |||
|
|||
options = { | |||
"shared": [True, False], | |||
"proxyfmu": [True, False]} | |||
"proxyfmu": [True, False], | |||
"fmi_log": [True, False]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this fmi_logging
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to no_fmi_logging
with a default False
2f42592
to
864a894
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Before merging, should we discuss how this can be used in practice? Would it be better to use a runtime option, so that everyone can make use of the feature? |
I made an update to pass an argument to |
I'm not sure I agree that it should be a runtime thing or, if it is, that this is the right way to do it. But I don't have time to re-review right now, so I'll just retract my approval for now and try to get back to it later.
|
Disabling logging by passing a no-op logger function looks like a good solution. However, as a general rule, I don't think libraries should take their settings from environment variables. We don't know which applications libcosim will be embedded in, and this could potentially cause user environment variables to break third-party applications. The library should be under full control of the application that uses it, which means that this setting must be controllable via the library API—if it's really needed, that is. (See my question at the end.) So then the question is where to put it. In the FMI subsystem ( virtual std::shared_ptr<slave_instance> instantiate_slave(
std::string_view instanceName,
bool disable_logging = false) = 0; This could be easily implemented in terms of @davidhjp01's no-op logger function. But our current applications typically don't use this API directly, they use the orchestration layer (in There are other ways to deal with this, though. For example, (and I think I would prefer this,) it could be limited to the FMI subsystem by a modification to class fmu_file_uri_sub_resolver : public model_uri_sub_resolver
{
public:
fmu_file_uri_sub_resolver(disable_logging = false);
... From there, it could be transferred on to each particular But I still don't feel like we've really discussed the necessity of all this. @markaren only asked the question, he didn't say it was 100% necessary. Do anyone else have opinions? |
Anyone has further opinion on this? I am fine with either approach but do think the runtime option would be more flexible to use. |
2b7d120
to
f854df0
Compare
I reverted the commits back to use the macro for disabling logging. If no one has other opinions I will merge this version when @kyllingstad accepts. |
I will merge this branch soon if no-one has further comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The current fmi logging callback function is slowing down the simulation (even if it is not printing anything) for high frequency sampling applications. For example, the logging function uses 16% of cpu times in a particular simulation (without proxyfmu):
This update provides an option to remove the logging code using the macro option (via conan).