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

Avoid allocating buffer when printing log. #851

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

likema
Copy link
Contributor

@likema likema commented Feb 28, 2019

No description provided.

@likema likema force-pushed the feature/optimize-log-record branch from 36770ac to 9468af0 Compare February 28, 2019 07:33
@jwillemsen
Copy link
Member

With small embedded systems couldn't this lead faster to a stack overflow?

@likema
Copy link
Contributor Author

likema commented Feb 28, 2019

The size of verbose buffer on stack is VERBOSE_LEN + 1 = 129.

Is it too large for embedded systems?

/// Size used by verbose mode.
/// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type)
///           + 4 (@) ... + ? (progname)
VERBOSE_LEN = 128,

@jwillemsen
Copy link
Member

I now see that you replaced MAXVERBOSELOGMSGLEN with VERBOSE_LEN which is much smaller, was that the intent?

@likema
Copy link
Contributor Author

likema commented Feb 28, 2019

Yes. I separate a line of log message into a prefix (verbose buffer) and content so that only prefix needs a small buffer on stack.

@likema
Copy link
Contributor Author

likema commented Feb 28, 2019

I find that

/// Size used by verbose mode.
/// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type)
///           + 4 (@) ... + ? (progname)
VERBOSE_LEN = 128,

progname is not formatted into verbose buffer on stack. So VERBOSE_LEN can be reduce to
20 + 15 + 10 + 10 + 4 = 59

Please see also:

  • const ACE_TCHAR *verbose_fmt = ACE_TEXT_FMT ACE_TEXT ("@")
    ACE_TEXT_FMT ACE_TEXT ("@%u@")
    ACE_TEXT_FMT ACE_TEXT ("@");

  • const ACE_TCHAR *lhost_name = ((host_name == 0)
    ? ACE_TEXT ("<local_host>")
    : host_name);
    return ACE_OS::snprintf (verbose_msg, verbose_msg_size, verbose_fmt,
    timestamp,
    lhost_name,
    this->pid_,
    ACE_Log_Record::priority_name (
    ACE_Log_Priority (this->type_)));

Am I right?

@@ -19,6 +19,14 @@

#include "ace/OS_Memory.h"

// The sprintf format needs to be different for Windows and POSIX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this part would be useful in ace_wchar.h or OS_NS_stdio.h since other callers of ACE_OS::snprintf may need it.

Copy link
Contributor Author

@likema likema Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitza-oci Which name is better for it?

  • ACE_TEXT_FORMAT_SPECIFIER
  • ACE_STRING_FORMAT_SPECIFIER
  • ACE_STR_FORMAT_SPECIFIER
  • ACE_C_STRING_FORMAT_SPECIFIER
  • ACE_C_STR_FORMAT_SPECIFIER

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in #1907

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks I remembered correctly that there was a macro already, it was just not merged yet, thanks for linking Adam

@likema likema force-pushed the feature/optimize-log-record branch 3 times, most recently from 627e2c7 to 095b109 Compare March 8, 2019 07:44
@likema likema force-pushed the feature/optimize-log-record branch from 095b109 to 71cbcb5 Compare December 11, 2019 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants