diff options
author | Wim Taymans <wtaymans@redhat.com> | 2017-04-27 18:56:59 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2017-04-27 18:56:59 +0200 |
commit | 430b749d53d1f1b8ec5ef2f1c7223b6494ee45a7 (patch) | |
tree | 982d16d888a8e06534b44d5aea2d569a54283f85 | |
parent | 214a0e27d82d73c9cfe037cfd43124f8cee2f2f8 (diff) |
fix trace logging
-rw-r--r-- | pinos/client/log.c | 20 | ||||
-rw-r--r-- | pinos/daemon/main.c | 2 | ||||
-rw-r--r-- | spa/lib/debug.c | 16 |
3 files changed, 24 insertions, 14 deletions
diff --git a/pinos/client/log.c b/pinos/client/log.c index 9bf6b712..ebd11166 100644 --- a/pinos/client/log.c +++ b/pinos/client/log.c @@ -49,14 +49,19 @@ do_logv (SpaLog *log, { DebugLog *l = SPA_CONTAINER_OF (log, DebugLog, log); char text[1024], location[1024]; - static const char *levels[] = { "-", "E", "W", "I", "D", "T", }; + static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*"}; int size; + bool do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source); vsnprintf (text, sizeof(text), fmt, args); + + if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source))) + level++; + size = snprintf (location, sizeof(location), "[%s][%s:%i %s()] %s\n", levels[level], strrchr (file, '/')+1, line, func, text); - if (SPA_UNLIKELY (level == SPA_LOG_LEVEL_TRACE && l->source)) { + if (SPA_UNLIKELY (do_trace)) { uint32_t index; uint64_t count = 1; @@ -68,7 +73,7 @@ do_logv (SpaLog *log, write (l->source->fd, &count, sizeof(uint64_t)); } else - fputs (location, stderr); + fputs (location, stdout); } static void @@ -119,20 +124,21 @@ on_trace_event (SpaSource *source) fprintf (stderr, "failed to read event fd: %s", strerror (errno)); while ((avail = spa_ringbuffer_get_read_index (&log.trace_rb, &index)) > 0) { - uint32_t offset, first, written; + uint32_t offset, first; if (avail > log.trace_rb.size) { + fprintf (stderr, "\n** trace overflow ** %d\n", avail); index += avail - log.trace_rb.size; avail = log.trace_rb.size; } offset = index & log.trace_rb.mask; first = SPA_MIN (avail, log.trace_rb.size - offset); - written = fprintf (stderr, "%*s", first, log.trace_data + offset); + fwrite (log.trace_data + offset, first, 1, stderr); if (SPA_UNLIKELY (avail > first)) { - written += fprintf (stderr, "%*s", avail - first, log.trace_data + first); + fwrite (log.trace_data, avail - first, 1, stderr); } - spa_ringbuffer_read_update (&log.trace_rb, index + written); + spa_ringbuffer_read_update (&log.trace_rb, index + avail); } } diff --git a/pinos/daemon/main.c b/pinos/daemon/main.c index d2ef377a..6b4b1ba2 100644 --- a/pinos/daemon/main.c +++ b/pinos/daemon/main.c @@ -42,7 +42,7 @@ main (int argc, char *argv[]) } loop = pinos_main_loop_new (); -#if 0 +#if 1 { SpaSource *source; source = pinos_loop_add_event (loop->loop, NULL, NULL); diff --git a/spa/lib/debug.c b/spa/lib/debug.c index 807038f4..23d43941 100644 --- a/spa/lib/debug.c +++ b/spa/lib/debug.c @@ -465,14 +465,18 @@ do_logv (SpaLog *log, { DebugLog *l = SPA_CONTAINER_OF (log, DebugLog, log); char text[512], location[1024]; - static const char *levels[] = { "-", "E", "W", "I", "D", "T", }; + static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" }; int size; + bool do_trace; + + if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source))) + level++; vsnprintf (text, sizeof(text), fmt, args); size = snprintf (location, sizeof(location), "[%s][%s:%i %s()] %s\n", levels[level], strrchr (file, '/')+1, line, func, text); - if (SPA_UNLIKELY (level == SPA_LOG_LEVEL_TRACE) && l->source) { + if (SPA_UNLIKELY (do_trace)) { uint32_t index; uint64_t count = 1; @@ -528,7 +532,7 @@ on_trace_event (SpaSource *source) fprintf (stderr, "failed to read event fd: %s", strerror (errno)); while ((avail = spa_ringbuffer_get_read_index (&log.trace_rb, &index)) > 0) { - uint32_t offset, first, written; + uint32_t offset, first; if (avail > log.trace_rb.size) { index += avail - log.trace_rb.size; @@ -537,11 +541,11 @@ on_trace_event (SpaSource *source) offset = index & log.trace_rb.mask; first = SPA_MIN (avail, log.trace_rb.size - offset); - written = fprintf (stderr, "%*s", first, log.trace_data + offset); + fwrite (log.trace_data + offset, first, 1, stderr); if (SPA_UNLIKELY (avail > first)) { - written += fprintf (stderr, "%*s", avail - first, log.trace_data + first); + fwrite (log.trace_data, avail - first, 1, stderr); } - spa_ringbuffer_read_update (&log.trace_rb, index + written); + spa_ringbuffer_read_update (&log.trace_rb, index + avail); } } |