Commit cbcff19c authored by Pekka Pessi's avatar Pekka Pessi

tport: collecting statistics

darcs-hash:20071129171740-88462-33724a96db36afb7ac6d070bafe3f27ff88d1c53.gz
parent 796141c9
......@@ -405,7 +405,8 @@ static int
tport_base_wakeup(tport_t *self, int events),
tport_connected(su_root_magic_t *m, su_wait_t *w, tport_t *self),
tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn),
tport_send_error(tport_t *, msg_t *, tp_name_t const *),
tport_send_error(tport_t *, msg_t *, tp_name_t const *, char const *who),
tport_send_fatal(tport_t *, msg_t *, tp_name_t const *, char const *who),
tport_queue(tport_t *self, msg_t *msg),
tport_queue_rest(tport_t *self, msg_t *msg, msg_iovec_t iov[], size_t iovused),
tport_pending_error(tport_t *self, su_sockaddr_t const *dst, int error),
......@@ -2990,6 +2991,7 @@ void tport_deliver(tport_t *self,
ref = tport_incref(self);
if (self->tp_pri->pri_vtable->vtp_deliver) {
self->tp_pri->pri_vtable->vtp_deliver(self, msg, now);
}
......@@ -3410,28 +3412,28 @@ int tport_send_msg(tport_t *self, msg_t *msg,
if (tport_is_connection_oriented(self)) {
iov[i].mv_len -= (su_ioveclen_t)(n - total);
iov[i].mv_base = (char *)iov[i].mv_base + (n - total);
if (tport_queue_rest(self, msg, &iov[i], iovused - i) >= 0)
if (tport_queue_rest(self, msg, &iov[i], iovused - i) < 0)
return tport_send_fatal(self, msg, tpn, "tport_queue_rest");
else
return 0;
}
else {
char const *comp = tpn->tpn_comp;
SU_DEBUG_1(("tport(%p): send truncated for %s/%s:%s%s%s\n",
(void *)self, tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port,
SU_DEBUG_1(("%s(%p): send truncated for %s/%s:%s%s%s\n",
"tport_vsend", (void *)self, tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port,
comp ? ";comp=" : "", comp ? comp : ""));
su_seterrno(EIO);
msg_set_errno(msg, EIO);
return /* tport_send_fatal(self, msg, tpn, "tport_send") */ -1;
}
return -1;
}
total += iov[i].mv_len;
}
/* We have sent a complete message */
self->tp_slogged = NULL;
self->tp_stats.sent_msgs ++;
tport_sent_message(self, msg, 0);
if (!tport_is_secondary(self))
return 0;
......@@ -3470,9 +3472,9 @@ ssize_t tport_vsend(tport_t *self,
return 0;
if (n == -1)
return tport_send_error(self, msg, tpn);
return tport_send_error(self, msg, tpn, "tport_vsend");
self->tp_stats.sent_bytes += n;
tport_sent_bytes(self, n, n); /* Sigcomp will decrease on_line accodingly */
if (n > 0 && self->tp_master->mr_dump_file)
tport_dump_iovec(self, msg, n, iov, iovused, "sent", "to");
......@@ -3486,8 +3488,8 @@ ssize_t tport_vsend(tport_t *self,
if (tpn == NULL || tport_is_connection_oriented(self))
tpn = self->tp_name;
SU_DEBUG_7(("tport_vsend(%p): "MOD_ZU" bytes of "MOD_ZU" to %s/%s:%s%s\n",
(void *)self, n, m, tpn->tpn_proto, tpn->tpn_host,
SU_DEBUG_7(("%s(%p): "MOD_ZU" bytes of "MOD_ZU" to %s/%s:%s%s\n",
"tport_vsend", (void *)self, n, m, tpn->tpn_proto, tpn->tpn_host,
tpn->tpn_port,
(ai->ai_flags & TP_AI_COMPRESSED) ? ";comp=sigcomp" : ""));
}
......@@ -3496,45 +3498,56 @@ ssize_t tport_vsend(tport_t *self,
}
static
int tport_send_error(tport_t *self, msg_t *msg,
tp_name_t const *tpn)
int tport_send_error(tport_t *self, msg_t *msg, tp_name_t const *tpn,
char const *who)
{
int error = su_errno();
su_addrinfo_t *ai = msg_addrinfo(msg);
char const *comp = (ai->ai_flags & TP_AI_COMPRESSED) ? ";comp=sigcomp" : "";
if (error == EPIPE) {
/*Xyzzy*/
}
if (su_is_blocking(error)) {
SU_DEBUG_5(("tport_vsend(%p): %s with (s=%d %s/%s:%s%s)\n",
(void *)self, "EAGAIN", (int)self->tp_socket,
su_addrinfo_t *ai = msg_addrinfo(msg);
char const *comp = (ai->ai_flags & TP_AI_COMPRESSED) ? ";comp=sigcomp" : "";
SU_DEBUG_5(("%s(%p): %s with (s=%d %s/%s:%s%s)\n",
who, (void *)self, "EAGAIN", (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp));
return 0;
}
msg_set_errno(msg, error);
return tport_send_fatal(self, msg, tpn, who);
}
static
int tport_send_fatal(tport_t *self, msg_t *msg, tp_name_t const *tpn,
char const *who)
{
su_addrinfo_t *ai = msg_addrinfo(msg);
char const *comp = (ai->ai_flags & TP_AI_COMPRESSED) ? ";comp=sigcomp" : "";
int error = msg_errno(msg);
if (self->tp_addrinfo->ai_family == AF_INET) {
SU_DEBUG_3(("tport_vsend(%p): %s with (s=%d %s/%s:%s%s)\n",
(void *)self, su_strerror(error), (int)self->tp_socket,
SU_DEBUG_3(("%s(%p): %s with (s=%d %s/%s:%s%s)\n",
who, (void *)self, su_strerror(error), (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp));
}
#if SU_HAVE_IN6
else if (self->tp_addrinfo->ai_family == AF_INET6) {
su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr;
SU_DEBUG_3(("tport_vsend(%p): %s with "
"(s=%d, IP6=%s/%s:%s%s (scope=%i) addrlen=%u)\n",
(void *)self, su_strerror(error), (int)self->tp_socket,
SU_DEBUG_3(("%s(%p): %s with (s=%d, IP6=%s/%s:%s%s"
" (scope=%i) addrlen=%u)\n",
who, (void *)self, su_strerror(error), (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp,
su->su_scope_id, (unsigned)ai->ai_addrlen));
}
#endif
else {
SU_DEBUG_3(("\ttport_vsend(%p): %s with "
"(s=%d, AF=%u addrlen=%u)%s\n",
(void *)self, su_strerror(error),
SU_DEBUG_3(("%s(%p): %s with (s=%d, AF=%u addrlen=%u)%s\n",
who, (void *)self, su_strerror(error),
(int)self->tp_socket, ai->ai_family, (unsigned)ai->ai_addrlen, comp));
}
......@@ -3861,9 +3874,8 @@ void tport_send_queue(tport_t *self)
/* We have sent a complete message */
self->tp_queue[qhead] = NULL;
tport_sent_message(self, msg, 0);
msg_destroy(msg);
self->tp_stats.sent_msgs++;
self->tp_slogged = NULL;
qhead = (qhead + 1) % N;
}
......@@ -4730,3 +4742,79 @@ char *tport_hostport(char buf[], isize_t bufsize,
return buf;
}
/** @internal Update receive statistics. */
void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line)
{
self->tp_stats.recv_bytes += bytes;
self->tp_stats.recv_on_line += on_line;
if (self != self->tp_pri->pri_primary) {
self = self->tp_pri->pri_primary;
self->tp_stats.recv_bytes += bytes;
self->tp_stats.recv_on_line += on_line;
}
self = self->tp_master->mr_master;
self->tp_stats.recv_bytes += bytes;
self->tp_stats.recv_on_line += on_line;
}
/** @internal Update message-based receive statistics. */
void tport_recv_message(tport_t *self, msg_t *msg, int error)
{
error = error != 0;
self->tp_stats.recv_msgs++;
self->tp_stats.recv_errors += error;
if (self != self->tp_pri->pri_primary) {
self = self->tp_pri->pri_primary;
self->tp_stats.recv_msgs++;
self->tp_stats.recv_errors += error;
}
self = self->tp_master->mr_master;
self->tp_stats.recv_msgs++;
self->tp_stats.recv_errors += error;
}
/** @internal Update send statistics. */
void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line)
{
self->tp_stats.sent_bytes += bytes;
self->tp_stats.sent_on_line += on_line;
if (self != self->tp_pri->pri_primary) {
self = self->tp_pri->pri_primary;
self->tp_stats.sent_bytes += bytes;
self->tp_stats.sent_on_line += on_line;
}
self = self->tp_master->mr_master;
self->tp_stats.sent_bytes += bytes;
self->tp_stats.sent_on_line += on_line;
}
/** @internal Update message-based send statistics. */
void tport_sent_message(tport_t *self, msg_t *msg, int error)
{
self->tp_slogged = NULL;
error = error != 0;
self->tp_stats.sent_msgs++;
self->tp_stats.sent_errors += error;
if (self != self->tp_pri->pri_primary) {
self = self->tp_pri->pri_primary;
self->tp_stats.sent_msgs++;
self->tp_stats.sent_errors += error;
}
self = self->tp_master->mr_master;
self->tp_stats.sent_msgs++;
self->tp_stats.sent_errors += error;
}
......@@ -221,8 +221,8 @@ struct tport_s {
/* ==== Statistics ===================================================== */
struct {
uint64_t sent_bytes, sent_on_line, recv_bytes, recv_on_line;
uint64_t sent_msgs, recv_msgs;
uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
} tp_stats;
};
......@@ -528,6 +528,12 @@ int tport_recv_stun_dgram(tport_t const *self, msg_t **in_out_msg,
int tport_stun_server_add_socket(tport_t *tp);
int tport_stun_server_remove_socket(tport_t *tp);
void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
void tport_recv_message(tport_t *self, msg_t *msg, int error);
void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
void tport_sent_message(tport_t *self, msg_t *msg, int error);
/* ---------------------------------------------------------------------- */
/* Compressor plugin */
extern tport_comp_vtable_t const *tport_comp_vtable;
......
......@@ -34,6 +34,7 @@
#include "tport_internal.h"
#include <string.h>
#include <sofia-sip/string0.h>
tport_comp_vtable_t const *tport_comp_vtable = NULL;
......
......@@ -242,6 +242,8 @@ int tport_recv_sctp(tport_t *self)
return 0; /* End of stream */
}
tport_recv_bytes(self, n, n);
veclen = tport_recv_iovec(self, &self->tp_msg, iovec, N, 0);
if (veclen < 0)
return -1;
......
......@@ -281,6 +281,8 @@ int tport_recv_stream(tport_t *self)
N -= n, self->tp_ping += n;
tport_recv_bytes(self, n, n);
if (N == 0) {
/* outbound-10 section 3.5.1 - send pong */
if (self->tp_ping >= 4)
......@@ -305,6 +307,8 @@ int tport_recv_stream(tport_t *self)
assert(n <= N);
tport_recv_bytes(self, n, n);
/* Check if message contains only whitespace */
/* This can happen if multiple PINGs are received at once */
if (initial) {
......
......@@ -46,6 +46,7 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <sofia-sip/string0.h>
/* ---------------------------------------------------------------------- */
/* TLS */
......
......@@ -293,6 +293,8 @@ int tport_recv_dgram(tport_t *self)
return 0;
}
tport_recv_bytes(self, n, n);
SU_CANONIZE_SOCKADDR(from);
if (self->tp_master->mr_dump_file)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment