log: add pw_log_topic_custom_enabled()

Add a function to check if a specfic custom log level has been defined
for a topic.

We can use this to dynamically check if we need to do the connection debug
messages.

We can also get rid of the conn.* pattern hack to disable connection
messages by default.
This commit is contained in:
Wim Taymans 2024-01-04 17:40:57 +01:00
parent 5152c98789
commit a3c6b3acae
8 changed files with 14 additions and 22 deletions

View file

@ -157,8 +157,6 @@ static const struct spa_dict_item module_props[] = {
#define SO_PEERSEC 31 #define SO_PEERSEC 31
#endif #endif
static bool debug_messages = 0;
#define LOCK_SUFFIX ".lock" #define LOCK_SUFFIX ".lock"
#define LOCK_SUFFIXLEN 5 #define LOCK_SUFFIXLEN 5
@ -341,7 +339,7 @@ process_messages(struct client_data *data)
pw_log_trace("%p: got message %d from %u", client->protocol, pw_log_trace("%p: got message %d from %u", client->protocol,
msg->opcode, msg->id); msg->opcode, msg->id);
if (debug_messages) if (pw_log_topic_custom_enabled(SPA_LOG_LEVEL_DEBUG, mod_topic_connection))
debug_msg("<<<<<< in", msg, false); debug_msg("<<<<<< in", msg, false);
pre_demarshal(conn, msg, client, footer_client_demarshal, pre_demarshal(conn, msg, client, footer_client_demarshal,
@ -995,7 +993,7 @@ process_remote(struct client *impl)
this->recv_seq = msg->seq; this->recv_seq = msg->seq;
if (debug_messages) if (pw_log_topic_custom_enabled(SPA_LOG_LEVEL_DEBUG, mod_topic_connection))
debug_msg("<<<<<< in", msg, false); debug_msg("<<<<<< in", msg, false);
pre_demarshal(conn, msg, this, footer_core_demarshal, pre_demarshal(conn, msg, this, footer_core_demarshal,
@ -1709,15 +1707,13 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args_str)
if (this == NULL) if (this == NULL)
return -errno; return -errno;
debug_messages = mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG;
this->implementation = &protocol_impl; this->implementation = &protocol_impl;
this->extension = &protocol_ext_impl; this->extension = &protocol_ext_impl;
pw_protocol_native_init(this); pw_protocol_native_init(this);
pw_protocol_native0_init(this); pw_protocol_native0_init(this);
pw_log_debug("%p: new debug:%d", this, debug_messages); pw_log_debug("%p: new", this);
d = pw_protocol_get_user_data(this); d = pw_protocol_get_user_data(this);
d->protocol = this; d->protocol = this;

View file

@ -718,7 +718,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
else else
buf->n_fds = buf->msg.n_fds; buf->n_fds = buf->msg.n_fds;
if (mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG) { if (pw_log_topic_custom_enabled(SPA_LOG_LEVEL_DEBUG, mod_topic_connection)) {
pw_logt_debug(mod_topic_connection, pw_logt_debug(mod_topic_connection,
">>>>>>>>> out: id:%d op:%d size:%d seq:%d fds:%d", ">>>>>>>>> out: id:%d op:%d size:%d seq:%d fds:%d",
buf->msg.id, buf->msg.opcode, size, buf->msg.seq, buf->msg.id, buf->msg.opcode, size, buf->msg.seq,

View file

@ -29,6 +29,8 @@
#include "server.h" #include "server.h"
#include "stream.h" #include "stream.h"
PW_LOG_TOPIC_EXTERN(pulse_conn);
#define client_emit_disconnect(c) spa_hook_list_call(&(c)->listener_list, struct client_events, disconnect, 0) #define client_emit_disconnect(c) spa_hook_list_call(&(c)->listener_list, struct client_events, disconnect, 0)
struct client *client_new(struct server *server) struct client *client_new(struct server *server)
@ -232,7 +234,8 @@ static int client_try_flush_messages(struct client *client)
data = m->data + idx; data = m->data + idx;
size = m->length - idx; size = m->length - idx;
} else { } else {
if (debug_messages && m->channel == SPA_ID_INVALID) if (m->channel == SPA_ID_INVALID &&
pw_log_topic_custom_enabled(SPA_LOG_LEVEL_INFO, pulse_conn))
message_dump(SPA_LOG_LEVEL_INFO, m); message_dump(SPA_LOG_LEVEL_INFO, m);
message_free(m, true, false); message_free(m, true, false);
client->out_index = 0; client->out_index = 0;

View file

@ -82,8 +82,6 @@ void impl_add_listener(struct impl *impl,
struct spa_hook *listener, struct spa_hook *listener,
const struct impl_events *events, void *data); const struct impl_events *events, void *data);
extern bool debug_messages;
void broadcast_subscribe_event(struct impl *impl, uint32_t mask, uint32_t event, uint32_t id); void broadcast_subscribe_event(struct impl *impl, uint32_t mask, uint32_t event, uint32_t id);
#endif #endif

View file

@ -73,10 +73,6 @@
#define TEMPORARY_MOVE_TIMEOUT (SPA_NSEC_PER_SEC) #define TEMPORARY_MOVE_TIMEOUT (SPA_NSEC_PER_SEC)
PW_LOG_TOPIC_EXTERN(pulse_conn);
bool debug_messages = false;
struct latency_offset_data { struct latency_offset_data {
int64_t prev_latency_offset; int64_t prev_latency_offset;
uint8_t initialized:1; uint8_t initialized:1;
@ -5476,8 +5472,6 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
const char *str; const char *str;
int res = 0; int res = 0;
debug_messages = pw_log_topic_enabled(SPA_LOG_LEVEL_INFO, pulse_conn);
impl = calloc(1, sizeof(*impl) + user_data_size); impl = calloc(1, sizeof(*impl) + user_data_size);
if (impl == NULL) if (impl == NULL)
goto error_free_props; goto error_free_props;

View file

@ -46,6 +46,8 @@
#define LISTEN_BACKLOG 32 #define LISTEN_BACKLOG 32
#define MAX_CLIENTS 64 #define MAX_CLIENTS 64
PW_LOG_TOPIC_EXTERN(pulse_conn);
static int handle_packet(struct client *client, struct message *msg) static int handle_packet(struct client *client, struct message *msg)
{ {
uint32_t command, tag; uint32_t command, tag;
@ -67,7 +69,7 @@ static int handle_packet(struct client *client, struct message *msg)
goto finish; goto finish;
} }
if (debug_messages) { if (pw_log_topic_custom_enabled(SPA_LOG_LEVEL_INFO, pulse_conn)) {
pw_log_debug("client %p: command:%s", client, commands[command].name); pw_log_debug("client %p: command:%s", client, commands[command].name);
message_dump(SPA_LOG_LEVEL_INFO, msg); message_dump(SPA_LOG_LEVEL_INFO, msg);
} }

View file

@ -310,10 +310,6 @@ parse_log_string(const char *str, struct spa_list *list, enum spa_log_level *lev
} }
} }
} }
/* Connection namespace disabled by default */
add_pattern(&new_patterns, "conn.*", SPA_LOG_LEVEL_NONE);
spa_list_insert_list(list, &new_patterns); spa_list_insert_list(list, &new_patterns);
return 0; return 0;
} }

View file

@ -153,6 +153,9 @@ void pw_log_topic_unregister(struct spa_log_topic *t);
#define pw_log_level_enabled(lev) (pw_log_level >= (lev)) #define pw_log_level_enabled(lev) (pw_log_level >= (lev))
#define pw_log_topic_enabled(lev,t) ((t) && (t)->has_custom_level ? (t)->level >= (lev) : pw_log_level_enabled((lev))) #define pw_log_topic_enabled(lev,t) ((t) && (t)->has_custom_level ? (t)->level >= (lev) : pw_log_level_enabled((lev)))
/* check is a custom level was assigned to a topic. \since 1.1.0 */
#define pw_log_topic_custom_enabled(lev,t) ((t) && (t)->has_custom_level && (t)->level >= (lev))
#define pw_logtv(lev,topic,fmt,ap) \ #define pw_logtv(lev,topic,fmt,ap) \
({ \ ({ \
if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \ if (SPA_UNLIKELY(pw_log_topic_enabled(lev,topic))) \