From: Adam Dickmeiss Date: Fri, 12 Mar 2010 16:23:35 +0000 (+0100) Subject: Logging channels and mutexes + a few other things X-Git-Tag: v1.4.0~96 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=b73890ede1ee6eeb8a07937733871077df6f15b9;p=pazpar2-moved-to-github.git Logging channels and mutexes + a few other things --- diff --git a/src/client.c b/src/client.c index 00e72d2..01267cd 100644 --- a/src/client.c +++ b/src/client.c @@ -476,6 +476,7 @@ void client_record_response(struct client *cl) NMEM nmem = nmem_create(); const char *xmlrec; char type[80]; + yaz_log(YLOG_LOG, "Record ingest begin client=%p session=%p", cl, cl->session); if (nativesyntax_to_type(sdb, type, rec)) yaz_log(YLOG_WARN, "Failed to determine record type"); xmlrec = ZOOM_record_get(rec, type, NULL); @@ -489,6 +490,7 @@ void client_record_response(struct client *cl) client_get_url(cl)); } nmem_destroy(nmem); + yaz_log(YLOG_LOG, "Record ingest end client=%p session=%p", cl, cl->session); } } else @@ -594,6 +596,8 @@ struct client *client_create(void) r->next = 0; r->mutex = 0; yaz_mutex_create(&r->mutex); + yaz_mutex_set_name(r->mutex, "client"); + r->ref_count = 1; return r; diff --git a/src/connection.c b/src/connection.c index cfa1146..fecf51b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -414,7 +414,7 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man) ZOOM_connection_connect(link, host->ipport, 0); con->link = link; - con->iochan = iochan_create(0, connection_handler, 0); + con->iochan = iochan_create(0, connection_handler, 0, "connection_socket"); con->state = Conn_Connecting; iochan_settimeout(con->iochan, con->operation_timeout); iochan_setdata(con->iochan, con); diff --git a/src/database.c b/src/database.c index 42b3c3a..8ab626e 100644 --- a/src/database.c +++ b/src/database.c @@ -110,6 +110,7 @@ static struct host *create_host(const char *hostport, iochan_man_t iochan_man) return 0; } yaz_mutex_create(&host->mutex); + yaz_mutex_set_name(host->mutex, "host"); return host; } @@ -411,6 +412,7 @@ database_hosts_t database_hosts_create(void) p->hosts = 0; p->mutex = 0; yaz_mutex_create(&p->mutex); + yaz_mutex_set_name(p->mutex, "database"); return p; } diff --git a/src/eventl.c b/src/eventl.c index 40f7a69..3b57d64 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -86,6 +86,7 @@ void iochan_man_destroy(iochan_man_t *mp) while (c) { IOCHAN c_next = c->next; + xfree(c->name); xfree(c); c = c_next; } @@ -101,7 +102,8 @@ void iochan_add(iochan_man_t man, IOCHAN chan) man->channel_list = chan; } -IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) +IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, + const char *name) { IOCHAN new_iochan; @@ -118,12 +120,17 @@ IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) new_iochan->next = NULL; new_iochan->man = 0; new_iochan->thread_users = 0; + new_iochan->name = name ? xstrdup(name) : 0; return new_iochan; } static void work_handler(void *work_data) { IOCHAN p = work_data; + + yaz_log(p->man->log_level, "eventl: work begin chan=%p name=%s event=%d", + p, p->name ? p->name : "", p->this_event); + if (!p->destroyed && (p->this_event & EVENT_TIMEOUT)) (*p->fun)(p, EVENT_TIMEOUT); if (!p->destroyed && (p->this_event & EVENT_INPUT)) @@ -132,6 +139,9 @@ static void work_handler(void *work_data) (*p->fun)(p, EVENT_OUTPUT); if (!p->destroyed && (p->this_event & EVENT_EXCEPT)) (*p->fun)(p, EVENT_EXCEPT); + + yaz_log(p->man->log_level, "eventl: work end chan=%p name=%s event=%d", + p, p->name ? p->name : "", p->this_event); } static void run_fun(iochan_man_t man, IOCHAN p) @@ -140,8 +150,8 @@ static void run_fun(iochan_man_t man, IOCHAN p) { if (man->sel_thread) { - yaz_log(man->log_level, "eventl: add fun chan=%p event=%d", - p, p->this_event); + yaz_log(man->log_level, "eventl: add fun chan=%p name=%s event=%d", + p, p->name ? p->name : "", p->this_event); p->thread_users++; sel_thread_add(man->sel_thread, p); } @@ -194,10 +204,9 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) { if (man->sel_fd > max) max = man->sel_fd; - yaz_log(man->log_level, "select on sel fd=%d", man->sel_fd); FD_SET(man->sel_fd, &in); } - yaz_log(man->log_level, "select begin"); + yaz_log(man->log_level, "select begin nofds=%d", max); res = select(max + 1, &in, &out, &except, timeout); yaz_log(man->log_level, "select returned res=%d", res); if (res < 0) @@ -220,8 +229,8 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) man->sel_fd); while ((chan = sel_thread_result(man->sel_thread))) { - yaz_log(man->log_level, "eventl: got thread result p=%p", - chan); + yaz_log(man->log_level, "eventl: got thread result chan=%p name=%s", + chan, chan->name ? chan->name : ""); chan->thread_users--; } } @@ -231,9 +240,14 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) int force_event = p->force_event; time_t now = time(0); - if (p->thread_users > 0 || p->destroyed) + if (p->destroyed) + { + yaz_log(man->log_level, "eventl: skip destroyed chan=%p name=%s", p, p->name ? p->name : ""); + continue; + } + if (p->thread_users > 0) { - yaz_log(man->log_level, "eventl: skip chan=%p users=%d", p, p->thread_users); + yaz_log(man->log_level, "eventl: skip chan=%p name=%s users=%d", p, p->name ? p->name : "", p->thread_users); continue; } p->this_event = 0; @@ -273,6 +287,7 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) if (p->destroyed && p->thread_users == 0) { *nextp = p->next; + xfree(p->name); xfree(p); } else diff --git a/src/eventl.h b/src/eventl.h index e53776c..e4d8b6b 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -50,7 +50,7 @@ typedef struct iochan int thread_users; iochan_man_t man; - + char *name; struct iochan *next; } *IOCHAN; @@ -80,7 +80,7 @@ void iochan_man_destroy(iochan_man_t *mp); #define iochan_setmaskfun(i, f) ((i)->maskfun = (f)) #define iochan_getmaskfun(i) ((i)->maskfun) -IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags); +IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name); #endif /* diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c index 12807b3..6632b90 100644 --- a/src/getaddrinfo.c +++ b/src/getaddrinfo.c @@ -179,7 +179,8 @@ static void getaddrinfo_start(iochan_man_t iochan_man) } else { - IOCHAN chan = iochan_create(fd, iochan_handler, EVENT_INPUT); + IOCHAN chan = iochan_create(fd, iochan_handler, EVENT_INPUT, + "getaddrinfo_socket"); iochan_setdata(chan, p); iochan_add(iochan_man, chan); } @@ -191,7 +192,7 @@ static void getaddrinfo_start(iochan_man_t iochan_man) int host_getaddrinfo(struct host *host, iochan_man_t iochan_man) { struct work *w = xmalloc(sizeof(*w)); - int use_thread = 1; /* =0 to disable threading entirely */ + int use_thread = 0; /* =0 to disable threading entirely */ w->hostport = host->hostport; w->ipport = 0; diff --git a/src/http.c b/src/http.c index c383cba..59d0050 100644 --- a/src/http.c +++ b/src/http.c @@ -797,7 +797,7 @@ static int http_proxy(struct http_request *rq) p->first_response = 1; c->proxy = p; // We will add EVENT_OUTPUT below - p->iochan = iochan_create(sock, proxy_io, EVENT_INPUT); + p->iochan = iochan_create(sock, proxy_io, EVENT_INPUT, "http_proxy"); iochan_setdata(p->iochan, p); iochan_add(ser->iochan_man, p->iochan); @@ -1170,7 +1170,7 @@ static void http_accept(IOCHAN i, int event) enable_nonblock(s); yaz_log(YLOG_DEBUG, "New command connection"); - c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT); + c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT, "http_session_socket"); ch = http_channel_create(server->http_server, inet_ntoa(addr.sin_addr), server); @@ -1245,7 +1245,7 @@ int http_init(const char *addr, struct conf_server *server) server->http_server->listener_socket = l; - c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT); + c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT, "http_server"); iochan_setdata(c, server); iochan_add(server->iochan_man, c); diff --git a/src/http_command.c b/src/http_command.c index cf9be94..3d4df77 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -115,7 +115,7 @@ struct http_session *http_session_create(struct conf_service *service, http_sessions->session_list = r; yaz_mutex_leave(http_sessions->mutex); - r->timeout_iochan = iochan_create(-1, session_timeout, 0); + r->timeout_iochan = iochan_create(-1, session_timeout, 0, "http_session_timeout"); iochan_setdata(r->timeout_iochan, r); yaz_log(YLOG_LOG, "timeout=%d", service->session_timeout); iochan_settimeout(r->timeout_iochan, service->session_timeout); diff --git a/src/normalize_cache.c b/src/normalize_cache.c index 4b69668..a863fc3 100644 --- a/src/normalize_cache.c +++ b/src/normalize_cache.c @@ -51,6 +51,7 @@ normalize_cache_t normalize_cache_create(void) nc->items = 0; nc->mutex = 0; yaz_mutex_create(&nc->mutex); + yaz_mutex_set_name(nc->mutex, "normalize_cache"); return nc; } diff --git a/src/reclists.c b/src/reclists.c index a621d89..1221b2b 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -250,6 +250,7 @@ struct reclist *reclist_create(NMEM nmem) res->num_records = 0; res->mutex = 0; yaz_mutex_create(&res->mutex); + yaz_mutex_set_name(res->mutex, "reclist"); return res; } diff --git a/src/session.c b/src/session.c index e2c66d3..5672536 100644 --- a/src/session.c +++ b/src/session.c @@ -686,6 +686,7 @@ struct session *new_session(NMEM nmem, struct conf_service *service) session->normalize_cache = normalize_cache_create(); session->mutex = 0; yaz_mutex_create(&session->mutex); + yaz_mutex_set_name(session->mutex, "session"); return session; }