Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
trace log: global cleanups - introduce runtime tvhtrace_enabled() check
- remove all extra ENABLE_TRACE #if checks
- reduce the runtime impact when traces are disabled
- improve macros for --disable-trace configuration
  • Loading branch information
perexg committed May 22, 2015
1 parent 4fdf0c5 commit 10e02ff
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 201 deletions.
13 changes: 4 additions & 9 deletions src/access.c
Expand Up @@ -347,7 +347,6 @@ access_verify(const char *username, const char *password,
/*
*
*/
#if ENABLE_TRACE
static void
access_dump_a(access_t *a)
{
Expand Down Expand Up @@ -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

/*
*
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/atomic.h
Expand Up @@ -18,6 +18,8 @@

#pragma once

#include <stdint.h>

static inline int
atomic_add(volatile int *ptr, int incr)
{
Expand Down
4 changes: 0 additions & 4 deletions src/epggrab/module/opentv.c
Expand Up @@ -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];
Expand Down
42 changes: 22 additions & 20 deletions src/epggrab/otamux.c
Expand Up @@ -516,11 +516,11 @@ epggrab_ota_kick_cb ( void *p )
}

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;
}

Expand Down Expand Up @@ -572,14 +572,14 @@ epggrab_ota_kick_cb ( void *p )
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);
}
}

/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions src/http.c
Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions src/httpc.c
Expand Up @@ -614,10 +614,10 @@ http_client_send( http_client_t *hc, enum http_cmd cmd,
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;
Expand All @@ -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)
Expand Down Expand Up @@ -921,12 +919,10 @@ http_client_run( http_client_t *hc )
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);
Expand Down
12 changes: 0 additions & 12 deletions src/input/mpegts/dvb_psi.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/input/mpegts/linuxdvb/linuxdvb_ca.c
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/input/mpegts/linuxdvb/linuxdvb_frontend.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
13 changes: 6 additions & 7 deletions src/input/mpegts/linuxdvb/linuxdvb_satconf.c
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit 10e02ff

Please sign in to comment.