[PATCH 1/4] os/log: Pull LogMessageTypeVerbString out of LogVMessageVerb

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 26 22:32:46 PDT 2011


On Wed, Jul 27, 2011 at 12:03:33PM +0800, Daniel Kurtz wrote:
> Also, optimize how the type and format strings are combined.
> 
> Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
> ---
>  os/log.c |  111 ++++++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 62 insertions(+), 49 deletions(-)
> 
> diff --git a/os/log.c b/os/log.c
> index 4a310e6..93d4763 100644
> --- a/os/log.c
> +++ b/os/log.c
> @@ -165,6 +165,9 @@ asm (".desc ___crashreporter_info__, 0x10");
>  #ifndef X_NOT_IMPLEMENTED_STRING
>  #define X_NOT_IMPLEMENTED_STRING	"(NI)"
>  #endif
> +#ifndef X_NONE_STRING
> +#define X_NONE_STRING                   ""
> +#endif
>  
>  /*
>   * LogInit is called to start logging to a file.  It is also called (with
> @@ -323,58 +326,68 @@ LogWrite(int verb, const char *f, ...)
>      va_end(args);
>  }
>  
> -void
> -LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
> +/* Returns the Message Type string to prepend to a logging message, or NULL
> + * if the message will not be dropped due to insufficient verbosity. */

s/not// I guess?

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> for the series
otherwise

Cheers,
  Peter

> +const char*
> +LogMessageTypeVerbString(MessageType type, int verb)
>  {
> -    const char *s  = X_UNKNOWN_STRING;
> -    char tmpBuf[1024];
> -
> -    /* Ignore verbosity for X_ERROR */
> -    if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) {
> -	switch (type) {
> -	case X_PROBED:
> -	    s = X_PROBE_STRING;
> -	    break;
> -	case X_CONFIG:
> -	    s = X_CONFIG_STRING;
> -	    break;
> -	case X_DEFAULT:
> -	    s = X_DEFAULT_STRING;
> -	    break;
> -	case X_CMDLINE:
> -	    s = X_CMDLINE_STRING;
> -	    break;
> -	case X_NOTICE:
> -	    s = X_NOTICE_STRING;
> -	    break;
> -	case X_ERROR:
> -	    s = X_ERROR_STRING;
> -	    if (verb > 0)
> -		verb = 0;
> -	    break;
> -	case X_WARNING:
> -	    s = X_WARNING_STRING;
> -	    break;
> -	case X_INFO:
> -	    s = X_INFO_STRING;
> -	    break;
> -	case X_NOT_IMPLEMENTED:
> -	    s = X_NOT_IMPLEMENTED_STRING;
> -	    break;
> -	case X_UNKNOWN:
> -	    s = X_UNKNOWN_STRING;
> -	    break;
> -	case X_NONE:
> -	    s = NULL;
> -	    break;
> -	}
> +    if (type == X_ERROR)
> +	verb = 0;
> +
> +    if (logVerbosity < verb && logFileVerbosity < verb)
> +	return NULL;
>  
> -        /* if s is not NULL we need a space before format */
> -        snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "",
> -                                                   s ? " " : "",
> -                                                   format);
> -        LogVWrite(verb, tmpBuf, args);
> +    switch (type) {
> +    case X_PROBED:
> +	return X_PROBE_STRING;
> +    case X_CONFIG:
> +	return  X_CONFIG_STRING;
> +    case X_DEFAULT:
> +	return  X_DEFAULT_STRING;
> +    case X_CMDLINE:
> +	return X_CMDLINE_STRING;
> +    case X_NOTICE:
> +	return X_NOTICE_STRING;
> +    case X_ERROR:
> +	return X_ERROR_STRING;
> +    case X_WARNING:
> +	return X_WARNING_STRING;
> +    case X_INFO:
> +	return X_INFO_STRING;
> +    case X_NOT_IMPLEMENTED:
> +	return X_NOT_IMPLEMENTED_STRING;
> +    case X_UNKNOWN:
> +	return X_UNKNOWN_STRING;
> +    case X_NONE:
> +	return X_NONE_STRING;
>      }
> +    return X_UNKNOWN_STRING;
> +}
> +
> +void
> +LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
> +{
> +    const char *type_str;
> +    char tmpFormat[1024];
> +    char *tmpFormat_end = &tmpFormat[sizeof(tmpFormat)];
> +    char *p = tmpFormat;
> +    int left;
> +
> +    type_str = LogMessageTypeVerbString(type, verb);
> +    if (!type_str)
> +	return;
> +
> +    /* if type_str is not "", prepend it, and ' ', to format */
> +    left = tmpFormat_end - p;
> +    if (strlen(type_str))
> +	p += snprintf(p, left, "%s ", type_str);
> +
> +    /* if still room in tmpBuf copy as much of format as will fit */
> +    left = tmpFormat_end - p;
> +    if (left > 1)
> +	snprintf(p, left, "%s", format);
> +
> +    LogVWrite(verb, tmpFormat, args);
>  }
>  
>  /* Log message with verbosity level specified. */
> -- 
> 1.7.3.1



More information about the xorg-devel mailing list