]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
trace log: global cleanups - introduce runtime tvhtrace_enabled() check
authorJaroslav Kysela <perex@perex.cz>
Fri, 22 May 2015 12:35:34 +0000 (14:35 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 22 May 2015 12:35:34 +0000 (14:35 +0200)
- remove all extra ENABLE_TRACE #if checks
- reduce the runtime impact when traces are disabled
- improve macros for --disable-trace configuration

22 files changed:
src/access.c
src/atomic.h
src/epggrab/module/opentv.c
src/epggrab/otamux.c
src/http.c
src/httpc.c
src/input/mpegts/dvb_psi.c
src/input/mpegts/linuxdvb/linuxdvb_ca.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/linuxdvb/linuxdvb_satconf.c
src/input/mpegts/mpegts_mux.c
src/input/mpegts/mpegts_network_dvb.c
src/input/mpegts/mpegts_table.c
src/input/mpegts/satip/satip.c
src/plumbing/globalheaders.c
src/satip/server.c
src/subscriptions.c
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_reader.c
src/tvhlog.c
src/tvhlog.h
src/upnp.c

index d67b3d8fd6b87449980ca3461509886c76968ab7..9cbd1e1e31013139529f9ed23427c1ed520d745f 100644 (file)
@@ -347,7 +347,6 @@ access_verify(const char *username, const char *password,
 /*
  *
  */
-#if ENABLE_TRACE
 static void
 access_dump_a(access_t *a)
 {
@@ -424,12 +423,6 @@ access_dump_a(access_t *a)
 
   tvhtrace("access", "%s", buf);
 }
-#else
-static inline void
-access_dump_a(access_t *a)
-{
-}
-#endif
 
 /*
  *
@@ -535,7 +528,8 @@ access_get(const char *username, const char *password, struct sockaddr *src)
       a->aa_rights = 0;
   }
 
-  access_dump_a(a);
+  if (tvhtrace_enabled())
+    access_dump_a(a);
   return a;
 }
 
@@ -614,7 +608,8 @@ access_get_hashed(const char *username, const uint8_t digest[20],
       a->aa_rights = 0;
   }
 
-  access_dump_a(a);
+  if (tvhtrace_enabled())
+    access_dump_a(a);
   return a;
 }
 
index 99fe3af79c26bf21a0abd6e69f670052af17d4c6..5b42407033a491715055bdb09820f0ff13bdf74e 100644 (file)
@@ -18,6 +18,8 @@
 
 #pragma once
 
+#include <stdint.h>
+
 static inline int
 atomic_add(volatile int *ptr, int incr)
 {
index 28ca696255988f7cde9f12686f4b8242a4399f41..371832f40323db81d95dcb744015b105faa98421 100644 (file)
@@ -479,17 +479,13 @@ opentv_desc_channels
   mpegts_service_t *svc;
   channel_t *ch;
   int sid, cid, cnum, unk;
-#if ENABLE_TRACE
   int type;
-#endif
   int save = 0;
   int i = 2;
 
   while (i < len) {
     sid  = ((int)buf[i] << 8) | buf[i+1];
-#if ENABLE_TRACE
     type = buf[2];
-#endif
     cid  = ((int)buf[i+3] << 8) | buf[i+4];
     cnum = ((int)buf[i+5] << 8) | buf[i+6];
     unk  = ((int)buf[i+7] << 8) | buf[i+8];
index 31a08ce754e45457ec4b596ec0f208e72684405b..10416c1c31e9cd11fe2037e5cef827530c79466f 100644 (file)
@@ -516,11 +516,11 @@ next_one:
   }
 
   if (epg_flag < 0 || epg_flag == MM_EPG_DISABLE) {
-#if ENABLE_TRACE
-    char name[256];
-    mpegts_mux_nice_name(mm, name, sizeof(name));
-    tvhtrace("epggrab", "epg mux %s is disabled, skipping", name);
-#endif
+    if (tvhtrace_enabled()) {
+      char name[256];
+      mpegts_mux_nice_name(mm, name, sizeof(name));
+      tvhtrace("epggrab", "epg mux %s is disabled, skipping", name);
+    }
     goto done;
   }
 
@@ -572,14 +572,14 @@ done:
   if (kick)
     epggrab_ota_kick(64); /* a random number? */
 
-#if ENABLE_TRACE
-  i = r = 0;
-  RB_FOREACH(om, &epggrab_ota_all, om_global_link)
-    i++;
-  TAILQ_FOREACH(om, &epggrab_ota_pending, om_q_link)
-    r++;
-  tvhtrace("epggrab", "mux stats - all %i pending %i", i, r);
-#endif
+  if (tvhtrace_enabled()) {
+    i = r = 0;
+    RB_FOREACH(om, &epggrab_ota_all, om_global_link)
+      i++;
+    TAILQ_FOREACH(om, &epggrab_ota_pending, om_q_link)
+      r++;
+    tvhtrace("epggrab", "mux stats - all %i pending %i", i, r);
+  }
 }
 
 /*
@@ -644,16 +644,20 @@ epggrab_ota_service_trace ( epggrab_ota_mux_t *ota,
                             epggrab_ota_svc_link_t *svcl,
                             const char *op )
 {
-#if ENABLE_TRACE
   char buf[256];
-  mpegts_mux_t *mm = mpegts_mux_find(ota->om_mux_uuid);
-  mpegts_service_t *svc = mpegts_service_find_by_uuid(svcl->uuid);
+  mpegts_mux_t *mm;
+  mpegts_service_t *svc;
+
+  if (!tvhtrace_enabled())
+    return;
+
+  mm = mpegts_mux_find(ota->om_mux_uuid);
+  svc = mpegts_service_find_by_uuid(svcl->uuid);
   if (mm && svc) {
     mpegts_mux_nice_name(mm, buf, sizeof(buf));
     tvhtrace("epggrab", "ota %s %s service %s", buf, op, svc->s_nicename);
   } else if (tvheadend_running)
     tvhtrace("epggrab", "ota %s, problem? (%p %p)", op, mm, svc);
-#endif
 }
 
 void
@@ -740,13 +744,11 @@ epggrab_ota_load_one
     hts_settings_remove("epggrab/otamux/%s", uuid);
     return;
   }
-#if ENABLE_TRACE
-  {
+  if (tvhtrace_enabled()) {
     char name[256];
     mpegts_mux_nice_name(mm, name, sizeof(name));
     tvhtrace("epggrab", "loading config for %s", name);
   }
-#endif
 
   ota = calloc(1, sizeof(epggrab_ota_mux_t));
   ota->om_mux_uuid = strdup(uuid);
index dc41751cf7fccbf8983b9ea089ccd07865ca6cb6..8d27b22c42a4d4215556afff58490648f0205db3 100644 (file)
@@ -570,7 +570,6 @@ http_exec(http_connection_t *hc, http_path_t *hp, char *remain)
 /*
  * Dump request
  */
-#if ENABLE_TRACE
 static void
 dump_request(http_connection_t *hc)
 {
@@ -595,12 +594,6 @@ dump_request(http_connection_t *hc)
   tvhtrace("http", "%s %s %s%s", http_ver2str(hc->hc_version),
            http_cmd2str(hc->hc_cmd), hc->hc_url, buf);
 }
-#else
-static inline void
-dump_request(http_connection_t *hc)
-{
-}
-#endif
 
 /**
  * HTTP GET
@@ -612,7 +605,8 @@ http_cmd_get(http_connection_t *hc)
   char *remain;
   char *args;
 
-  dump_request(hc);
+  if (tvhtrace_enabled())
+    dump_request(hc);
 
   hp = http_resolve(hc, &remain, &args);
   if(hp == NULL) {
@@ -678,7 +672,8 @@ http_cmd_post(http_connection_t *hc, htsbuf_queue_t *spill)
       http_parse_get_args(hc, hc->hc_post_data);
   }
 
-  dump_request(hc);
+  if (tvhtrace_enabled())
+    dump_request(hc);
 
   hp = http_resolve(hc, &remain, &args);
   if(hp == NULL) {
@@ -781,7 +776,8 @@ process_request(http_connection_t *hc, htsbuf_queue_t *spill)
 
   switch(hc->hc_version) {
   case RTSP_VERSION_1_0:
-    dump_request(hc);
+    if (tvhtrace_enabled())
+      dump_request(hc);
     if (hc->hc_cseq)
       rval = hc->hc_process(hc, spill);
     else
index 4bdbeb1d6a5a32000a48f7e50c36c853efd89489..f9dd15a397d30d89763ab23d52d36a78c70dc5da 100644 (file)
@@ -614,10 +614,10 @@ error:
   body = malloc(body_size);
   htsbuf_read(&q, body, body_size);
 
-#if ENABLE_TRACE
-  tvhtrace("httpc", "%04X: sending %s cmd", shortid(hc), http_ver2str(hc->hc_version));
-  tvhlog_hexdump("httpc", body, body_size);
-#endif
+  if (tvhtrace_enabled()) {
+    tvhtrace("httpc", "%04X: sending %s cmd", shortid(hc), http_ver2str(hc->hc_version));
+    tvhlog_hexdump("httpc", body, body_size);
+  }
 
   wcmd->wbuf  = body;
   wcmd->wsize = body_size;
@@ -638,12 +638,10 @@ http_client_finish( http_client_t *hc )
   http_client_wcmd_t *wcmd;
   int res;
 
-#if ENABLE_TRACE
-  if (hc->hc_data) {
+  if (hc->hc_data && tvhtrace_enabled()) {
     tvhtrace("httpc", "%04X: received %s data", shortid(hc), http_ver2str(hc->hc_version));
     tvhlog_hexdump("httpc", hc->hc_data, hc->hc_csize);
   }
-#endif
   if (hc->hc_data_complete) {
     res = hc->hc_data_complete(hc);
     if (res < 0)
@@ -921,12 +919,10 @@ retry:
       return HTTP_CON_RECEIVING;
     return http_client_flush(hc, -errno);
   }
-#if ENABLE_TRACE
-  if (r > 0) {
+  if (r > 0 && tvhtrace_enabled()) {
     tvhtrace("httpc", "%04X: received %s answer", shortid(hc), http_ver2str(hc->hc_version));
     tvhlog_hexdump("httpc", buf, r);
   }
-#endif
 
   if (hc->hc_in_data) {
     res = http_client_data_received(hc, buf, r, 0);
index 77228cabe3c5677747935d4ac93ade6c95fcc977..b2ff96cbf7a1f5f0c56e7b5c4516489103f6d07b 100644 (file)
@@ -502,25 +502,19 @@ dvb_freesat_local_channels
   ( dvb_bat_id_t *bi, const char *dstr, const uint8_t *ptr, int len )
 {
   uint16_t sid, lcn, regionid;
-#if ENABLE_TRACE
   uint16_t unk;
-#endif
   dvb_freesat_svc_t *fs;
   int len2;
 
   while (len > 4) {
     sid = (ptr[0] << 8) | ptr[1];
-#if ENABLE_TRACE
     unk = (ptr[2] << 8) | ptr[3];
-#endif
     len2 = ptr[4];
     ptr += 5;
     len -= 5;
     if (len2 > len)
       break;
-#if ENABLE_TRACE
     tvhtrace(dstr, "      sid %04X (%d) uknown %04X (%d)", sid, sid, unk, unk);
-#endif
     while (len2 > 3) {
       lcn = ((ptr[0] & 0x0f) << 8) | ptr[1];
       regionid = (ptr[2] << 8) | ptr[3];
@@ -746,9 +740,7 @@ dvb_bskyb_local_channels
     const uint8_t *ptr, int len, mpegts_mux_t *mm )
 {
   uint16_t sid, lcn, regionid;
-#if ENABLE_TRACE
   uint16_t unk, stype;
-#endif
   dvb_freesat_region_t *fr;
   dvb_freesat_svc_t *fs;
   dvb_bat_svc_t *bs;
@@ -781,17 +773,13 @@ dvb_bskyb_local_channels
   while (len > 8) {
     sid = (ptr[0] << 8) | ptr[1];
     lcn = (ptr[5] << 8) | ptr[6];
-#if ENABLE_TRACE
     stype = ptr[2];
     unk = (ptr[3] << 8) | ptr[4];
-#endif
     ptr += 9;
     len -= 9;
 
-#if ENABLE_TRACE
     tvhtrace(dstr, "      sid %04X (%d) type %02X (%d) lcn %d unknown %04X (%d)",
              sid, sid, stype, stype, lcn, unk, unk);
-#endif
 
     TAILQ_FOREACH(fs, &bi->fservices, link)
       if (fs->sid == sid && fs->regionid == regionid)
index bba998025201e417cf87d438dc40c2cf996c4b27..52914725f05a0547012653ad0b58a818d37d92e5 100644 (file)
@@ -53,7 +53,6 @@ ca_slot_state2str(ca_slot_state_t v)
   return "UNKNOWN";
 }
 
-#if ENABLE_TRACE
 const static char *
 ca_pmt_list_mgmt2str(uint8_t v)
 {
@@ -67,9 +66,7 @@ ca_pmt_list_mgmt2str(uint8_t v)
   }
   return "UNKNOWN";
 }
-#endif
 
-#if ENABLE_TRACE
 const static char *
 ca_pmt_cmd_id2str(uint8_t v)
 {
@@ -81,7 +78,6 @@ ca_pmt_cmd_id2str(uint8_t v)
   }
   return "UNKNOWN";
 }
-#endif
 
 struct linuxdvb_ca_capmt {
   TAILQ_ENTRY(linuxdvb_ca_capmt)  lcc_link;
index 4abbb67fef97410f62830f003ab8dc5357477fe4..937c715c5eb4dbafe8c0dfc78564a233f826a11c 100644 (file)
@@ -1283,13 +1283,11 @@ linuxdvb_frontend_tune0
    */
 
   dmc = &lm->lm_tuning;
-#if ENABLE_TRACE
-  {
+  if (tvhtrace_enabled()) {
     char buf2[256];
     dvb_mux_conf_str(&lm->lm_tuning, buf2, sizeof(buf2));
     tvhtrace("linuxdvb", "tuner %s tunning to %s (freq %i)", buf1, buf2, freq);
   }
-#endif
   memset(&p, 0, sizeof(p));
   p.frequency                = dmc->dmc_fe_freq;
   p.inversion                = TR(inversion, inv_tbl, INVERSION_AUTO);
@@ -1424,11 +1422,11 @@ linuxdvb_frontend_tune0
 
   /* S2 tuning */
 #if DVB_API_VERSION >= 5
-#if ENABLE_TRACE
-  int i;
-  for (i = 0; i < cmdseq.num; i++)
-    tvhtrace("linuxdvb", "S2CMD %02u => %u", cmds[i].cmd, cmds[i].u.data);
-#endif
+  if (tvhtrace_enabled()) {
+    int i;
+    for (i = 0; i < cmdseq.num; i++)
+      tvhtrace("linuxdvb", "S2CMD %02u => %u", cmds[i].cmd, cmds[i].u.data);
+  }
   r = ioctl(lfe->lfe_fe_fd, FE_SET_PROPERTY, &cmdseq);
 
   /* v3 tuning */
index 4f20e60f469f62f683db21e0aae7ee83423d6db7..05575a445b613e69dca9c8a92f4d22c59bc2c6d7 100644 (file)
@@ -1412,10 +1412,9 @@ linuxdvb_diseqc_send
   int i;
   va_list ap;
   struct dvb_diseqc_master_cmd message;
-#if ENABLE_TRACE
   char buf[256];
   size_t c = 0;
-#endif
+  int tr = tvhtrace_enabled();
 
   /* Build message */
   message.msg_len = len + 3;
@@ -1425,14 +1424,14 @@ linuxdvb_diseqc_send
   va_start(ap, len);
   for (i = 0; i < len; i++) {
     message.msg[3 + i] = (uint8_t)va_arg(ap, int);
-#if ENABLE_TRACE
-    tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[3 + i]);
-#endif
+    if (tr)
+      tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[3 + i]);
   }
   va_end(ap);
 
-  tvhtrace("diseqc", "sending diseqc (len %d) %02X %02X %02X %s",
-           len + 3, framing, addr, cmd, buf);
+  if (tr)
+    tvhtrace("diseqc", "sending diseqc (len %d) %02X %02X %02X %s",
+             len + 3, framing, addr, cmd, buf);
 
   /* Send */
   if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &message)) {
index 259167eccbdeec127ac080521757ec48056d405b..02f3909c207f4bd1b9dc87e7c1435a44d6d54ccd 100644 (file)
@@ -1113,7 +1113,6 @@ mpegts_mux_set_onid ( mpegts_mux_t *mm, uint16_t onid )
   mm->mm_onid = onid;
   mpegts_mux_nice_name(mm, buf, sizeof(buf));
   mm->mm_config_save(mm);
-  tvhtrace("mpegts", "%s - set onid %04X (%d)", buf, onid, onid);
   idnode_notify_changed(&mm->mm_id);
   return 1;
 }
@@ -1127,11 +1126,11 @@ mpegts_mux_set_tsid ( mpegts_mux_t *mm, uint16_t tsid, int force )
     return 0;
   mm->mm_tsid = tsid;
   mm->mm_config_save(mm);
-#if ENABLE_TRACE
-  char buf[256];
-  mpegts_mux_nice_name(mm, buf, sizeof(buf));
-  tvhtrace("mpegts", "%s - set tsid %04X (%d)", buf, tsid, tsid);
-#endif
+  if (tvhtrace_enabled()) {
+    char buf[256];
+    mpegts_mux_nice_name(mm, buf, sizeof(buf));
+    tvhtrace("mpegts", "%s - set tsid %04X (%d)", buf, tsid, tsid);
+  }
   idnode_notify_changed(&mm->mm_id);
   return 1;
 }
@@ -1143,11 +1142,11 @@ mpegts_mux_set_crid_authority ( mpegts_mux_t *mm, const char *defauth )
     return 0;
   tvh_str_update(&mm->mm_crid_authority, defauth);
   mm->mm_config_save(mm);
-#if ENABLE_TRACE
-  char buf[256];
-  mpegts_mux_nice_name(mm, buf, sizeof(buf));
-  tvhtrace("mpegts", "%s - set crid authority %s", buf, defauth);
-#endif
+  if (tvhtrace_enabled()) {
+    char buf[256];
+    mpegts_mux_nice_name(mm, buf, sizeof(buf));
+    tvhtrace("mpegts", "%s - set crid authority %s", buf, defauth);
+  }
   idnode_notify_changed(&mm->mm_id);
   return 1;
 }
@@ -1186,11 +1185,11 @@ void
 mpegts_mux_remove_subscriber
   ( mpegts_mux_t *mm, th_subscription_t *s, int reason )
 {
-#if ENABLE_TRACE
-  char buf[256];
-  mpegts_mux_nice_name(mm, buf, sizeof(buf));
-  tvhtrace("mpegts", "%s - remove subscriber (reason %i)", buf, reason);
-#endif
+  if (tvhtrace_enabled()) {
+    char buf[256];
+    mpegts_mux_nice_name(mm, buf, sizeof(buf));
+    tvhtrace("mpegts", "%s - remove subscriber (reason %i)", buf, reason);
+  }
   mm->mm_stop(mm, 0, reason);
 }
 
index 1d9658a5167c658f9e1e5f5b746752151a7cb084..a7c7432a3503eaf9af6d6108c3c182247a73a435 100644 (file)
@@ -83,19 +83,19 @@ dvb_network_class_scanfile_set ( void *o, const void *s )
                            dmc, NULL, NULL);
       if (mm)
         mm->mm_config_save((mpegts_mux_t *)mm);
-#if ENABLE_TRACE
-      char buf[128];
-      dvb_mux_conf_str(dmc, buf, sizeof(buf));
-      tvhtrace("scanfile", "mux %p %s added to network %s", mm, buf, ln->mn_network_name);
-#endif
+      if (tvhtrace_enabled()) {
+        char buf[128];
+        dvb_mux_conf_str(dmc, buf, sizeof(buf));
+        tvhtrace("scanfile", "mux %p %s added to network %s", mm, buf, ln->mn_network_name);
+      }
     } else {
-#if ENABLE_TRACE
-      char buf[128];
-      dvb_mux_conf_str(dmc, buf, sizeof(buf));
-      tvhtrace("scanfile", "mux %p skipped %s in network %s", mm, buf, ln->mn_network_name);
-      dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
-      tvhtrace("scanfile", "mux %p exists %s in network %s", mm, buf, ln->mn_network_name);
-#endif
+      if (tvhtrace_enabled()) {
+        char buf[128];
+        dvb_mux_conf_str(dmc, buf, sizeof(buf));
+        tvhtrace("scanfile", "mux %p skipped %s in network %s", mm, buf, ln->mn_network_name);
+        dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
+        tvhtrace("scanfile", "mux %p exists %s in network %s", mm, buf, ln->mn_network_name);
+      }
     }
   }
   return 0;
@@ -456,12 +456,12 @@ dvb_network_create_mux
     }
     if (save) {
       mm = dvb_mux_create0(ln, onid, tsid, dmc, NULL, NULL);
-#if ENABLE_TRACE
-      char buf[128];
-      dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
-      tvhtrace("mpegts", "mux %p %s onid %i tsid %i added to network %s (autodiscovery)",
-               mm, buf, onid, tsid, mm->mm_network->mn_network_name);
-#endif      
+      if (tvhtrace_enabled()) {
+        char buf[128];
+        dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
+        tvhtrace("mpegts", "mux %p %s onid %i tsid %i added to network %s (autodiscovery)",
+                 mm, buf, onid, tsid, mm->mm_network->mn_network_name);
+      }
     }
   } else if (mm) {
     dvb_mux_t *lm = (dvb_mux_t*)mm;
@@ -469,7 +469,6 @@ dvb_network_create_mux
     /* accept information only from one origin mux */
     if (mm->mm_dmc_origin_expire > dispatch_clock && mm->mm_dmc_origin && mm->mm_dmc_origin != origin)
       goto noop;
-#if ENABLE_TRACE
     #define COMPARE(x) ({ \
       int xr = dmc->x != lm->lm_tuning.x; \
       if (xr) { \
@@ -484,17 +483,6 @@ dvb_network_create_mux
                  " (%li)", (long)dmc->x, (long)lm->lm_tuning.x); \
         lm->lm_tuning.x = dmc->x; \
       } xr; })
-#else
-    #define COMPARE(x) ({ \
-      int xr = dmc->x != lm->lm_tuning.x; \
-      if (xr) lm->lm_tuning.x = dmc->x; \
-      xr; })
-    /* note - zero means NONE, one means AUTO */
-    #define COMPAREN(x) ({ \
-      int xr = dmc->x != 0 && dmc->x != 1 && dmc->x != lm->lm_tuning.x; \
-      if (xr) lm->lm_tuning.x = dmc->x; \
-      xr; })
-#endif
     dvb_mux_conf_t tuning_old;
     char buf[128];
     tuning_old = lm->lm_tuning;
index 67526d2a7a386c875f7633b61cc2f0b2f459a1ef..41218a1e663b8b3530e78cb1dd2502dab8f54c9b 100644 (file)
 void
 mpegts_table_consistency_check ( mpegts_mux_t *mm )
 {
-#if ENABLE_TRACE
-  int i, c = 0;
+  int i, c;
   mpegts_table_t *mt;
 
+  if (!tvhtrace_enabled())
+    return;
+
+  c = 0;
+
   lock_assert(&mm->mm_tables_lock);
 
   i = mm->mm_num_tables;
@@ -38,7 +42,6 @@ mpegts_table_consistency_check ( mpegts_mux_t *mm )
     tvherror("mpegts", "table: mux %p count inconsistency (num %d, list %d)", mm, i, c);
     abort();
   }
-#endif
 }
 
 static void
@@ -120,10 +123,10 @@ mpegts_table_release_ ( mpegts_table_t *mt )
   if (mt->mt_destroy)
     mt->mt_destroy(mt);
   free(mt->mt_name);
-#if ENABLE_TRACE
-  /* poison */
-  memset(mt, 0xa5, sizeof(*mt));
-#endif
+  if (tvhtrace_enabled()) {
+    /* poison */
+    memset(mt, 0xa5, sizeof(*mt));
+  }
   free(mt);
 }
 
index 3fa7a3cf5aa4c5820880cea675b97157d512e1c2..a29ae035b4afdb6c3c3f50a9606e9c5bac71394d 100644 (file)
@@ -792,10 +792,10 @@ satip_discovery_http_closed(http_client_t *hc, int errn)
     return;
   }
 
-#if ENABLE_TRACE
-  tvhtrace("satip", "received XML description from %s", hc->hc_host);
-  tvhlog_hexdump("satip", hc->hc_data, hc->hc_data_size);
-#endif
+  if (tvhtrace_enabled()) {
+    tvhtrace("satip", "received XML description from %s", hc->hc_host);
+    tvhlog_hexdump("satip", hc->hc_data, hc->hc_data_size);
+  }
 
   if (d->myaddr == NULL || d->myaddr[0] == '\0') {
     struct sockaddr_storage ip;
index d21bf9ee31564408d642fd604164f7fe84c5e808..4de2ff1daea8628d95f2c04c8a1ea9fd672902ab 100644 (file)
@@ -240,16 +240,16 @@ headers_complete(globalheaders_t *gh)
     }
   }
 
-#if ENABLE_TRACE
-  for(i = 0; i < ss->ss_num_components; i++) {
-    ssc = &ss->ss_components[i];
-    tvhtrace("parser", "stream %d %s%s%s (PID %i) complete time %"PRId64"%s",
-             ssc->ssc_index, streaming_component_type2txt(ssc->ssc_type),
-             ssc->ssc_lang[0] ? " " : "", ssc->ssc_lang, ssc->ssc_pid,
-             gh_queue_delay(gh, ssc->ssc_index),
-             ssc->ssc_disabled ? " disabled" : "");
+  if (tvhtrace_enabled()) {
+    for(i = 0; i < ss->ss_num_components; i++) {
+      ssc = &ss->ss_components[i];
+      tvhtrace("parser", "stream %d %s%s%s (PID %i) complete time %"PRId64"%s",
+               ssc->ssc_index, streaming_component_type2txt(ssc->ssc_type),
+               ssc->ssc_lang[0] ? " " : "", ssc->ssc_lang, ssc->ssc_pid,
+               gh_queue_delay(gh, ssc->ssc_index),
+               ssc->ssc_disabled ? " disabled" : "");
+    }
   }
-#endif
 
   return 1;
 }
index 2749c43a59cec9b6a08e80293e7ac557b371e142..62ea072774716ca827cacb4f5e610cc26cee2df4 100644 (file)
@@ -347,11 +347,11 @@ CONFIGID.UPNP.ORG: 0\r\n"
   if (satips_upnp_discovery == NULL || satip_server_rtsp_port <= 0)
     return;
 
-#if ENABLE_TRACE
-  tcp_get_str_from_ip((struct sockaddr *)dst, buf, sizeof(buf));
-  tvhtrace("satips", "sending discover reply to %s:%d%s%s",
-           buf, IP_PORT(*dst), deviceid ? " device: " : "", deviceid ?: "");
-#endif
+  if (tvhtrace_enabled()) {
+    tcp_get_str_from_ip((struct sockaddr *)dst, buf, sizeof(buf));
+    tvhtrace("satips", "sending discover reply to %s:%d%s%s",
+             buf, IP_PORT(*dst), deviceid ? " device: " : "", deviceid ?: "");
+  }
 
   snprintf(buf, sizeof(buf), MSG, UPNP_MAX_AGE,
            http_server_ip, http_server_port, tvheadend_version,
@@ -452,12 +452,12 @@ satips_upnp_discovery_received
   if (!conn->multicast && strcmp(argv[0], http_server_ip))
     return;
 
-#if ENABLE_TRACE
-  tcp_get_str_from_ip((struct sockaddr *)storage, buf2, sizeof(buf2));
-  tvhtrace("satips", "received %s M-SEARCH from %s:%d",
-           conn->multicast ? "multicast" : "unicast",
-           buf2, ntohs(IP_PORT(*storage)));
-#endif
+  if (tvhtrace_enabled()) {
+    tcp_get_str_from_ip((struct sockaddr *)storage, buf2, sizeof(buf2));
+    tvhtrace("satips", "received %s M-SEARCH from %s:%d",
+             conn->multicast ? "multicast" : "unicast",
+             buf2, ntohs(IP_PORT(*storage)));
+  }
 
   /* Check for deviceid collision */
   if (!conn->multicast) {
index fb8bbc5deac31122986aadaac9c1d5d9bb9aabe6..dcedda2ca9a0edde9ab67f16286263779e74e62d 100644 (file)
@@ -721,15 +721,15 @@ subscription_create_from_channel_or_service(profile_chain_t *prch,
 
   s = subscription_create(prch, weight, name, flags, subscription_input,
                           hostname, username, client);
-#if ENABLE_TRACE
-  const char *pro_name = prch->prch_pro ? (prch->prch_pro->pro_name ?: "") : "<none>";
-  if (ch)
-    tvhtrace("subscription", "%04X: creating subscription for %s weight %d using profile %s",
-             shortid(s), channel_get_name(ch), weight, pro_name);
-  else
-    tvhtrace("subscription", "%04X: creating subscription for service %s weight %d using profile %s",
-             shortid(s), service->s_nicename, weight, pro_name);
-#endif
+  if (tvhtrace_enabled()) {
+    const char *pro_name = prch->prch_pro ? (prch->prch_pro->pro_name ?: "") : "<none>";
+    if (ch)
+      tvhtrace("subscription", "%04X: creating subscription for %s weight %d using profile %s",
+               shortid(s), channel_get_name(ch), weight, pro_name);
+    else
+      tvhtrace("subscription", "%04X: creating subscription for service %s weight %d using profile %s",
+               shortid(s), service->s_nicename, weight, pro_name);
+  }
   s->ths_channel = ch;
   s->ths_service = service;
   s->ths_source  = ti;
index de4e21f45e8ca0a085beb97e6e2027bb794a23b4..776a25bee4c65a12897d985934385575316c83d4 100644 (file)
@@ -102,12 +102,12 @@ static void* timeshift_reaper_callback ( void *p )
 
 static void timeshift_reaper_remove ( timeshift_file_t *tsf )
 {
-#if ENABLE_TRACE
-  if (tsf->path)
-    tvhtrace("timeshift", "queue file for removal %s", tsf->path);
-  else
-    tvhtrace("timeshift", "queue file for removal - RAM segment time %li", (long)tsf->time);
-#endif
+  if (tvhtrace_enabled()) {
+    if (tsf->path)
+      tvhtrace("timeshift", "queue file for removal %s", tsf->path);
+    else
+      tvhtrace("timeshift", "queue file for removal - RAM segment time %li", (long)tsf->time);
+  }
   pthread_mutex_lock(&timeshift_reaper_lock);
   TAILQ_INSERT_TAIL(&timeshift_reaper_list, tsf, link);
   pthread_cond_signal(&timeshift_reaper_cond);
@@ -173,12 +173,12 @@ void timeshift_filemgr_remove
   if (tsf->wfd >= 0)
     close(tsf->wfd);
   assert(tsf->rfd < 0);
-#if ENABLE_TRACE
-  if (tsf->path)
-    tvhdebug("timeshift", "ts %d remove %s", ts->id, tsf->path);
-  else
-    tvhdebug("timeshift", "ts %d RAM segment remove time %li", ts->id, (long)tsf->time);
-#endif
+  if (tvhtrace_enabled()) {
+    if (tsf->path)
+      tvhdebug("timeshift", "ts %d remove %s", ts->id, tsf->path);
+    else
+      tvhdebug("timeshift", "ts %d RAM segment remove time %li", ts->id, (long)tsf->time);
+  }
   TAILQ_REMOVE(&ts->files, tsf, link);
   atomic_dec_u64(&timeshift_total_size, tsf->size);
   if (tsf->ram)
index cd46140cd6affc96ceaae1c37b457eb9312f3602..9a1a1bbd73ecf4a0b3b5e8dd6ed07075b6117702 100644 (file)
@@ -768,8 +768,7 @@ void *timeshift_reader ( void *p )
                (((cur_speed < 0) && (sm->sm_time >= deliver)) ||
                ((cur_speed > 0) && (sm->sm_time <= deliver))))) {
 
-      if (sm->sm_type == SMT_PACKET) {
-#if ENABLE_TRACE
+      if (sm->sm_type == SMT_PACKET && tvhtrace_enabled()) {
         th_pkt_t *pkt = sm->sm_data;
         tvhtrace("timeshift",
                  "ts %d pkt out - stream %d type %c pts %10"PRId64
@@ -781,7 +780,6 @@ void *timeshift_reader ( void *p )
                  ts_rescale(pkt->pkt_dts, 1000000),
                  pkt->pkt_duration,
                  pktbuf_len(pkt->pkt_payload), sm->sm_time);
-#endif
       }
       last_time = sm->sm_time;
       streaming_target_deliver2(ts->output, sm);
index c393eeb10a906eea82a1a552bdace3fab2aa5f6b..7056310c5826271c0c4b9c25cbe1e7f033c60cb3 100644 (file)
@@ -367,15 +367,11 @@ _tvhlog_hexdump(const char *file, int line,
                 const char *subsys,
                 const uint8_t *data, ssize_t len )
 {
-  int i, c, skip;
+  int i, c;
   char str[1024];
 
-  /* Don't process if trace is OFF */
-  pthread_mutex_lock(&tvhlog_mutex);
-  skip = (severity > tvhlog_level);
-  pthread_mutex_unlock(&tvhlog_mutex);
-  if (skip) return;
+  /* Assume that severify was validated before call */
+
   /* Build and log output */
   while (len > 0) {
     c = 0;
index c6b1acf7c57666ec4009d66e2eed2ecef93f5128..eae2f5e1bd5dd3be8acb8de571b7f2c4e02620ff 100644 (file)
@@ -28,6 +28,7 @@
 #include <pthread.h>
 #include <stdarg.h>
 
+#include "atomic.h"
 #include "htsmsg.h"
 
 typedef struct {
@@ -96,13 +97,22 @@ static inline int tvhlog_limit ( tvhlog_limit_t *limit, uint32_t delay )
 #define tvhlog_spawn(severity, subsys, fmt, ...)\
   _tvhlog(__FILE__, __LINE__, 0, severity, subsys, fmt, ##__VA_ARGS__)
 #if ENABLE_TRACE
-#define tvhtrace(subsys, fmt, ...)\
-  _tvhlog(__FILE__, __LINE__, 0, LOG_TRACE, subsys, fmt, ##__VA_ARGS__)
-#define tvhlog_hexdump(subsys, data, len)\
-  _tvhlog_hexdump(__FILE__, __LINE__, 0, LOG_TRACE, subsys, (uint8_t*)data, len)
+#define tvhtrace_enabled() LOG_TRACE <= atomic_add(&tvhlog_level, 0)
+#define tvhtrace(subsys, fmt, ...) \
+  do { \
+    if (tvhtrace_enabled()) \
+      _tvhlog(__FILE__, __LINE__, 0, LOG_TRACE, subsys, fmt, ##__VA_ARGS__); \
+  } while (0)
+#define tvhlog_hexdump(subsys, data, len) \
+  do { \
+    if (tvhtrace_enabled()) \
+      _tvhlog_hexdump(__FILE__, __LINE__, 0, LOG_TRACE, subsys, (uint8_t*)data, len); \
+  } while (0)
 #else
-#define tvhtrace(...) (void)0
-#define tvhlog_hexdump(...) (void)0
+static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; }
+#define tvhtrace_enabled() 0
+#define tvhtrace(subsys, fmt, ...) do { tvhtrace_no_warnings(NULL, subsys, fmt, ##__VA_ARGS__); } while (0)
+#define tvhlog_hexdump(subsys, data, len) do { tvhtrace_no_warnings(NULL, subsys, data, len); } while (0)
 #endif
 
 #define tvhftrace(subsys, fcn) do { \
index 6d832d3ae1da712bfc346d36e316c2aea63d60f4..137322c7d3bb88bdd9743f8ab020f51c8ff77b74 100644 (file)
@@ -166,8 +166,7 @@ upnp_thread( void *aux )
         iplen = sizeof(ip);
         size = recvfrom(conn->fd, buf, sizeof(buf), 0,
                                            (struct sockaddr *)&ip, &iplen);
-#if ENABLE_TRACE
-        if (size > 0) {
+        if (size > 0 && tvhtrace_enabled()) {
           char tbuf[256];
           inet_ntop(ip.ss_family, IP_IN_ADDR(ip), tbuf, sizeof(tbuf));
           tvhtrace("upnp", "%s - received data from %s:%hu [size=%zi]",
@@ -175,7 +174,6 @@ upnp_thread( void *aux )
                    tbuf, (unsigned short) IP_PORT(ip), size);
           tvhlog_hexdump("upnp", buf, size);
         }
-#endif
         /* TODO: a filter */
         TAILQ_FOREACH(us, &upnp_services, us_link)
           us->us_received(buf, size, conn, &ip);