Optimized indentation for systemd journal

When you run irqbalance with systemd on debug mode it produces
really bad logs in to yournal 'because journalctl will strip your
indentation and result looks like that:

burlak@borg ~ $ journalctl -u irqbalance -n 100 -o cat
Package 0:  numa_node is 0 cpu mask is 0000000f (load 0)
Cache domain 0:  numa_node is 0 cpu mask is 0000000f  (load 0)
CPU number 0  numa_node is 0 (load 0)
Interrupt 32 node_num is -1 (ethernet/1)
CPU number 1  numa_node is 0 (load 0)
Interrupt 30 node_num is -1 (timer/1)
CPU number 2  numa_node is 0 (load 0)
Interrupt 29 node_num is -1 (ethernet/1)
CPU number 3  numa_node is 0 (load 0)
Interrupt 26 node_num is -1 (storage/1)
Interrupt 23 node_num is -1 (legacy/1)
Interrupt 18 node_num is -1 (legacy/1)
Interrupt 16 node_num is -1 (legacy/1)

instead of:

burlak@borg ~ $ irqbalance --debug
Package 0:  numa_node is -1 cpu mask is 0000000f (load 0)
        Cache domain 0:  numa_node is -1 cpu mask is 00000003  (load 0)
                CPU number 0  numa_node is -1 (load 0)
                  Interrupt 32 node_num is -1 (ethernet/1)
                CPU number 1  numa_node is -1 (load 0)
          Interrupt 23 node_num is -1 (legacy/1)
          Interrupt 16 node_num is -1 (legacy/1)
          Interrupt 27 node_num is -1 (legacy/1)
        Cache domain 1:  numa_node is -1 cpu mask is 0000000c  (load 0)
                CPU number 2  numa_node is -1 (load 0)
                  Interrupt 26 node_num is -1 (storage/1)
                  Interrupt 30 node_num is -1 (video/1)
                CPU number 3  numa_node is -1 (load 0)
                  Interrupt 29 node_num is -1 (ethernet/1)
          Interrupt 18 node_num is -1 (legacy/1)
  Interrupt 25 node_num is -1 (other/1)
  Interrupt 24 node_num is -1 (other/1)
  Interrupt 12 node_num is -1 (other/1)

This patch add support with different characters in indentation
when you compile irqbalance with ./configure --with-systemd

Signed-off-by: Andrej Manduch <amanduch@gmail.com>
Reported-by: Peter Holasek <pholasek@redhat.com>
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
This commit is contained in:
Andrej Manduch 2015-03-03 12:51:43 -05:00 committed by Neil Horman
parent 95b72fb9c9
commit 2c98d43cb5
3 changed files with 20 additions and 4 deletions

View file

@ -294,7 +294,9 @@ static void dump_irq(struct irq_info *info, void *data)
{
int spaces = (long int)data;
int i;
for (i=0; i<spaces; i++) log(TO_CONSOLE, LOG_INFO, " ");
char indent_char[2] = {log_indent[0], '\0'};
for (i=0; i<spaces; i++) log(TO_CONSOLE, LOG_INFO, indent_char);
log(TO_CONSOLE, LOG_INFO, "Interrupt %i node_num is %d (%s/%u) \n",
info->irq, irq_numa_node(info)->number, classes[info->class], (unsigned int)info->load);
}
@ -302,7 +304,8 @@ static void dump_irq(struct irq_info *info, void *data)
static void dump_topo_obj(struct topo_obj *d, void *data __attribute__((unused)))
{
struct topo_obj *c = (struct topo_obj *)d;
log(TO_CONSOLE, LOG_INFO, " CPU number %i numa_node is %d (load %lu)\n",
log(TO_CONSOLE, LOG_INFO, "%s%s%s%sCPU number %i numa_node is %d (load %lu)\n",
log_indent, log_indent, log_indent, log_indent,
c->number, cpu_numa_node(c)->number , (unsigned long)c->load);
if (c->interrupts)
for_each_irq(c->interrupts, dump_irq, (void *)18);
@ -312,7 +315,8 @@ static void dump_cache_domain(struct topo_obj *d, void *data)
{
char *buffer = data;
cpumask_scnprintf(buffer, 4095, d->mask);
log(TO_CONSOLE, LOG_INFO, " Cache domain %i: numa_node is %d cpu mask is %s (load %lu) \n",
log(TO_CONSOLE, LOG_INFO, "%s%sCache domain %i: numa_node is %d cpu mask is %s (load %lu) \n",
log_indent, log_indent,
d->number, cache_domain_numa_node(d)->number, buffer, (unsigned long)d->load);
if (d->children)
for_each_object(d->children, dump_topo_obj, NULL);

View file

@ -49,6 +49,7 @@ int numa_avail;
int journal_logging = 0;
int need_rescan;
unsigned int log_mask = TO_ALL;
char * log_indent;
enum hp_e global_hint_policy = HINT_POLICY_IGNORE;
unsigned long power_thresh = ULONG_MAX;
unsigned long deepest_cache = 2;
@ -180,6 +181,8 @@ static void parse_command_line(int argc, char **argv)
#ifdef HAVE_SYSTEMD
case 'j':
journal_logging=1;
foreground_mode=1;
debug_mode=1;
break;
#endif /* HAVE_SYSTEMD */
}
@ -269,8 +272,11 @@ int main(int argc, char** argv)
if (argc>1 && strstr(argv[1],"--oneshot"))
one_shot_mode=1;
# ifdef HAVE_SYSTEMD
if (argc>1 && strstr(argv[1],"--journal"))
if (argc>1 && strstr(argv[1],"--journal")) {
journal_logging=1;
foreground_mode=1;
debug_mode=1;
}
# endif /* HAVE_SYSTEMD */
#endif /* HAVE_GETOPT_LONG */
@ -293,6 +299,11 @@ int main(int argc, char** argv)
* If we are't in debug mode, don't dump anything to the console
* note that everything goes to the console before we check this
*/
if (journal_logging)
log_indent = strdup("....");
else
log_indent = strdup(" ");
if (!debug_mode)
log_mask &= ~TO_CONSOLE;

View file

@ -134,6 +134,7 @@ static inline void for_each_object(GList *list, void (*cb)(struct topo_obj *obj,
#define TO_CONSOLE (1 << 1)
#define TO_ALL (TO_SYSLOG | TO_CONSOLE)
extern char * log_indent;
extern unsigned int log_mask;
#define log(mask, lvl, fmt, args...) do {\
if (log_mask & mask & TO_SYSLOG)\