From: Dirk Lemstra Date: Tue, 31 Oct 2017 20:39:58 +0000 (+0100) Subject: Optimized checking if event logging is enabled. X-Git-Tag: 7.0.7-10~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8dd7e1f0939599cc3558306b632f5b8dd7adf0e0;p=imagemagick Optimized checking if event logging is enabled. --- diff --git a/MagickCore/log.c b/MagickCore/log.c index 764b51848..eaf48eb2b 100644 --- a/MagickCore/log.c +++ b/MagickCore/log.c @@ -212,6 +212,9 @@ static LinkedListInfo static SemaphoreInfo *event_semaphore = (SemaphoreInfo *) NULL, *log_semaphore = (SemaphoreInfo *) NULL; + +static MagickBooleanType + log_enabled = MagickFalse; /* Forward declarations. @@ -227,6 +230,22 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *,const char *,const char *,const size_t, ExceptionInfo *); +static void CheckLogEnabled() +{ + /* We don't need locks because we only call this inside log_semaphore */ + if (IsLinkedListEmpty(log_cache) != MagickFalse) + log_enabled=MagickFalse; + else + { + LogInfo + *p; + + ResetLinkedListIterator(log_cache); + p=(LogInfo *) GetNextValueInLinkedList(log_cache); + log_enabled=p->event_mask != NoEvents ? MagickTrue: MagickFalse; + } +} + /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -663,7 +682,10 @@ static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception) ActivateSemaphoreInfo(&log_semaphore); LockSemaphoreInfo(log_semaphore); if (log_cache == (LinkedListInfo *) NULL) - log_cache=AcquireLogCache(LogFilename,exception); + { + log_cache=AcquireLogCache(LogFilename,exception); + CheckLogEnabled(); + } UnlockSemaphoreInfo(log_semaphore); } return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); @@ -690,19 +712,7 @@ static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception) */ MagickExport MagickBooleanType IsEventLogging(void) { - const LogInfo - *log_info; - - ExceptionInfo - *exception; - - if ((log_cache == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(log_cache) != MagickFalse)) - return(MagickFalse); - exception=AcquireExceptionInfo(); - log_info=GetLogInfo("*",exception); - exception=DestroyExceptionInfo(exception); - return(log_info->event_mask != NoEvents ? MagickTrue : MagickFalse); + return(log_enabled); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -891,6 +901,7 @@ MagickPrivate void LogComponentTerminus(void) LockSemaphoreInfo(log_semaphore); if (log_cache != (LinkedListInfo *) NULL) log_cache=DestroyLinkedList(log_cache,DestroyLogElement); + log_enabled=MagickFalse; UnlockSemaphoreInfo(log_semaphore); RelinquishSemaphoreInfo(&log_semaphore); } @@ -1251,8 +1262,9 @@ static char *TranslateFilename(const LogInfo *log_info) return(filename); } -MagickBooleanType LogMagickEventList(const LogEventType type,const char *module, - const char *function,const size_t line,const char *format,va_list operands) +MagickExport MagickBooleanType LogMagickEventList(const LogEventType type, + const char *module,const char *function,const size_t line,const char *format, + va_list operands) { char event[MagickPathExtent], @@ -1270,8 +1282,6 @@ MagickBooleanType LogMagickEventList(const LogEventType type,const char *module, LogInfo *log_info; - if (IsEventLogging() == MagickFalse) - return(MagickFalse); exception=AcquireExceptionInfo(); log_info=(LogInfo *) GetLogInfo("*",exception); exception=DestroyExceptionInfo(exception); @@ -1380,8 +1390,9 @@ MagickBooleanType LogMagickEventList(const LogEventType type,const char *module, return(MagickTrue); } -MagickBooleanType LogMagickEvent(const LogEventType type,const char *module, - const char *function,const size_t line,const char *format,...) +MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, + const char *module,const char *function,const size_t line, + const char *format,...) { va_list operands; @@ -1389,6 +1400,8 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module, MagickBooleanType status; + if (IsEventLogging() == MagickFalse) + return(MagickFalse); va_start(operands,format); status=LogMagickEventList(type,module,function,line,format,operands); va_end(operands); @@ -1737,6 +1750,7 @@ MagickExport LogEventType SetLogEventMask(const char *events) log_info->event_mask=(LogEventType) option; if (option == -1) log_info->event_mask=UndefinedEvents; + CheckLogEnabled(); UnlockSemaphoreInfo(log_semaphore); return(log_info->event_mask); } diff --git a/MagickCore/log.h b/MagickCore/log.h index 46c5e211c..fa2b8a12a 100644 --- a/MagickCore/log.h +++ b/MagickCore/log.h @@ -81,8 +81,7 @@ extern MagickExport MagickBooleanType IsEventLogging(void), ListLogInfo(FILE *,ExceptionInfo *), LogMagickEvent(const LogEventType,const char *,const char *,const size_t, - const char *,...) - magick_attribute((__format__ (__printf__,5,6))), + const char *,...) magick_attribute((__format__ (__printf__,5,6))), LogMagickEventList(const LogEventType,const char *,const char *,const size_t, const char *,va_list) magick_attribute((__format__ (__printf__,5,0))); diff --git a/MagickWand/wandcli.c b/MagickWand/wandcli.c index 1884d8417..3dddc52a7 100644 --- a/MagickWand/wandcli.c +++ b/MagickWand/wandcli.c @@ -281,6 +281,9 @@ WandExport MagickBooleanType CLILogEvent(MagickCLI *cli_wand, va_list operands; + if (IsEventLogging() == MagickFalse) + return(MagickFalse); + /* HACK - prepend the CLI location to format string. The better way would be add more arguments to to the 'va' oparands list, but that does not appear to be possible! So we do some