提交 cbb0fd3c 编写于 作者: D Daniel P. Berrangé

log: support logging using shell wildcard syntax

Rather than specialcasing handling of the '*' character, use fnmatch()
to get normal shell wildcard syntax, as described in 'man glob(7)'.

To get an indication of the performance impact of using globs instead
of plain string matches, a test program was written. The list of all
260 log categories was extracted from the source. Then a typical log
filters setup was picked by creating an array of the strings "qemu",
"security", "util", "cgroup", "event", "object". Every filter string
was matched against every log category. Timing information showed that
using strstr() this took 8 microseconds, while fnmatch() took 114
microseconds.

IOW, fnmatch is 14 times slower than our existing strstr check. These
numbers show a worst case scenario that will never be hit, because it
is rare that every log category would have data output. The log category
matches are cached, so each category is only checked once no matter how
many log statements are emitted. IOW despite being slower, this will
be lost in the noise and have no consequence on real world logging
performance.
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 4a239d15
......@@ -40,6 +40,7 @@
#if HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#include <fnmatch.h>
#include "virerror.h"
#include "virlog.h"
......@@ -508,7 +509,7 @@ virLogSourceUpdate(virLogSourcePtr source)
size_t i;
for (i = 0; i < virLogNbFilters; i++) {
if (strstr(source->name, virLogFilters[i]->match)) {
if (fnmatch(virLogFilters[i]->match, source->name, 0) == 0) {
priority = virLogFilters[i]->priority;
flags = virLogFilters[i]->flags;
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册