Skip to content
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

More logging utility #105

Open
AODQ opened this issue May 10, 2019 · 0 comments
Open

More logging utility #105

AODQ opened this issue May 10, 2019 · 0 comments

Comments

@AODQ
Copy link

AODQ commented May 10, 2019

Here are a few logging utility functions that would be useful:

string format support
Allows formatting of string, automatically converting each member of variadic list to string. So only format character would be %s .
Example:
LOG_W("Index: %s , Value: %s", idx, val)
Impl:

template <typename... Args> void LogWarning(Args&&... args) {
  std::stringstream toString;
  (toString << ... << args) << '\n';
  std::string str = toString.str();
  // ...
}

Assertions
Allows conditions to be held at either debug or release time.
Example usage:

void* data = glMapNamedBuffer(myBuffer, ...);
// Done during release, since it's inexpensive & the condition must hold
// for the following code to work
// The expression returns non-zero if the assertion failed
if (!LOG_RA(data, "Could not map buffer '%s'", myBuffer)) {
  memcpy(data, someOtherData, 100);
  glUnmapNamedBuffer(myBuffer);
}
std::view<size_t> sortedNodes = rootNode.GetSortedNodes();
// In this case, checking if the nodes are sorted is expensive & redundant in release.
// So this would only be checked in debug mode.
LOG_DA(IsSorted(sortedNodes), "Nodes are not sorted");

Modern OpenGL Debug Callback
Disable all of OSG's OpenGL error checkings.

for (auto& graphicsContext : allGraphicsContexts) {
  graphicsContext
    ->getState()
    ->setCheckForGLErrors(osg::State::CheckForGLErrors::NEVER_CHECK_GL_ERRORS);
}

OSG uses the old OpenGL error checking (glGetError), which is a performance hit & gives little to no actual debugging value. Furthermore, it doesn't catch performance issues or warnings. Instead the modern OpenGL error checking should be implemented & toggled on/off as a runtime flag. https://www.khronos.org/opengl/wiki/Debug_Output . Should also allow to enable GL_DEBUG_OUTPUT_SYNCHRONOUS at runtime. With Back trace, this gives all the information necessary to track errors/warnings/performance issues & fix them immediately.

Back Trace
Allows the back trace to be emitted. Very useful for callbacks that can happen anywhere in the code. For example, with OpenGL Debug Callback, it does not describe which OpenGL function emitted the error. Printing backtrace solves this issue. Not sure how to implement this in Windows, but it's relatively simple to implement in Linux.

Pipe to locations other than files
Outputting to files is nice but it might be useful to allow users to output elsewhere. Big example is outputting out to a GUI. Could be as simple as allowing a user implementable callback, similar to how OpenGL Debug Callback works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants