Skip to content

Commit

Permalink
Added some functions for dumping internal state
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Dec 7, 2012
1 parent 7d2dc45 commit 7ec775c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 7 deletions.
2 changes: 2 additions & 0 deletions httpkite.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Note: For alternate license terms, see the file COPYING.md.
#include "pkerror.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"
#include "utils.h"

Expand Down
2 changes: 1 addition & 1 deletion pagekite.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Note: For alternate license terms, see the file COPYING.md.
#include "pkerror.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pklogging.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"
#include "version.h"

#include "pagekite_net.h"
Expand Down
3 changes: 3 additions & 0 deletions pkconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Note: For alternate license terms, see the file COPYING.md.
#include "pkerror.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pkstate.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"


Expand Down
3 changes: 3 additions & 0 deletions pkerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Note: For alternate license terms, see the file COPYING.md.
#include "pkerror.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pkstate.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"


Expand Down
100 changes: 99 additions & 1 deletion pklogging.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ Note: For alternate license terms, see the file COPYING.md.
#include <android/log.h>
#endif

#include "utils.h"
#include "pkstate.h"
#include "pkerror.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"

static int logged_lines = 0;


int pk_log(int level, const char* fmt, ...)
{
va_list args;
Expand Down Expand Up @@ -105,3 +108,98 @@ int pk_log_chunk(struct pk_chunk* chnk) {
}
return r;
}


void pk_dump_parser(char* prefix, struct pk_parser* p)
{
int i;

pk_log(PK_LOG_MANAGER_DEBUG, "%s/buffer_bytes_left: %d", prefix, p->buffer_bytes_left);
if (NULL == p->chunk) return;

for (i = 0; i < p->chunk->header_count; i++) {
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/header_%d: %s", prefix, i, p->chunk->headers[i]);
}
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/length: %d", prefix, p->chunk->length);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/length: %d", prefix, p->chunk->length);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/frame/length: %d", prefix, p->chunk->frame.length);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/frame/hdr_length: %d", prefix, p->chunk->frame.hdr_length);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/chunk/frame/raw_length: %d", prefix, p->chunk->frame.raw_length);
}

void pk_dump_conn(char* prefix, struct pk_conn* conn)
{
pk_log(PK_LOG_MANAGER_DEBUG, "%s/status: %8.8x", prefix, conn->status);
if (conn->sockfd < 0) return;

pk_log(PK_LOG_MANAGER_DEBUG, "%s/sockfd: %d", prefix, conn->sockfd);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/activity: %x", prefix, conn->activity);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/read_bytes: %d", prefix, conn->read_bytes);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/read_kb: %d", prefix, conn->read_kb);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/sent_kb: %d", prefix, conn->sent_kb);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/send_window_kb: %d", prefix, conn->send_window_kb);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/wrote_bytes: %d", prefix, conn->wrote_bytes);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/reported_kb: %d", prefix, conn->reported_kb);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/in_buffer_pos: %d", prefix, conn->in_buffer_pos);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/out_buffer_pos: %d", prefix, conn->out_buffer_pos);
}

void pk_dump_frontend(char* prefix, struct pk_frontend* fe)
{
char tmp[1024];
if (NULL == fe->ai) return;

pk_log(PK_LOG_MANAGER_DEBUG, "%s/fe_hostname: %s", prefix, fe->fe_hostname);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/fe_port: %d", prefix, fe->fe_port);

if (0 <= fe->conn.sockfd) {
pk_log(PK_LOG_MANAGER_DEBUG, "%s/fe_session: %s", prefix, fe->fe_session);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/request_count: %d", prefix, fe->request_count);
in_addr_to_str(fe->ai->ai_addr, tmp, 1024);
pk_log(PK_LOG_MANAGER_DEBUG, "%s/fe_ai: %s", prefix, tmp);
sprintf(tmp, "%s/conn", prefix);
pk_dump_conn(tmp, &(fe->conn));
sprintf(tmp, "%s/parser", prefix);
pk_dump_parser(tmp, fe->parser);
}
}

void pk_dump_be_conn(char* prefix, struct pk_backend_conn* bec)
{
}

void pk_dump_state(struct pk_manager* pkm)
{
int i;
char prefix[1024];
struct pk_frontend* fe;
struct pk_backend_conn* bec;

#define LL PK_LOG_MANAGER_DEBUG
pk_log(LL, "pk_global_state/app_id_short: %s", pk_state.app_id_short);
pk_log(LL, "pk_global_state/app_id_long: %s", pk_state.app_id_long);
pk_log(LL, "pk_global_state/have_ssl: %d", pk_state.have_ssl);
pk_log(LL, "pk_global_state/live_streams: %d", pk_state.live_streams);
pk_log(LL, "pk_global_state/live_frontends: %d", pk_state.live_frontends);
pk_log(LL, "pk_manager/status: %d", pkm->status);
pk_log(LL, "pk_manager/buffer_bytes_free: %d", pkm->buffer_bytes_free);
pk_log(LL, "pk_manager/kite_max: %d", pkm->kite_max);
pk_log(LL, "pk_manager/frontend_max: %d", pkm->frontend_max);
pk_log(LL, "pk_manager/be_conn_max: %d", pkm->be_conn_max);
pk_log(LL, "pk_manager/last_world_update: %x", pkm->last_world_update);
pk_log(LL, "pk_manager/next_tick: %d", pkm->next_tick);
pk_log(LL, "pk_manager/enable_timer: %d", 0 < pkm->enable_timer);
pk_log(LL, "pk_manager/fancy_pagekite_net_rejection: %d", 0 < pkm->fancy_pagekite_net_rejection);
pk_log(LL, "pk_manager/want_spare_frontends: %d", pkm->want_spare_frontends);
pk_log(LL, "pk_manager/dynamic_dns_url: %s", pkm->dynamic_dns_url);

for (i = 0, fe = pkm->frontends; i < pkm->frontend_max; i++, fe++) {
sprintf(prefix, "fe_%d", i);
pk_dump_frontend(prefix, fe);
}
for (i = 0, bec = pkm->be_conns; i < pkm->be_conn_max; i++, bec++) {
sprintf(prefix, "beconn_%d", i);
pk_dump_be_conn(prefix, bec);
}
}

4 changes: 3 additions & 1 deletion pklogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ Note: For alternate license terms, see the file COPYING.md.
#define PK_LOG_ALL 0xffff

int pk_log(int, const char *fmt, ...);
int pk_log_chunk(struct pk_chunk* chnk);
int pk_log_chunk(struct pk_chunk*);
void pk_dump_state(struct pk_manager*);

11 changes: 7 additions & 4 deletions pkmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,19 @@ void pkm_parse_eof(struct pk_backend_conn* pkb, char *eof)

void pkm_tunnel_readable_cb(EV_P_ ev_io *w, int revents)
{
int rv;
struct pk_frontend* fe = (struct pk_frontend*) w->data;
fe->conn.status &= ~CONN_STATUS_WANT_READ;
if (0 < pkc_read(&(fe->conn))) {
if (0 > pk_parser_parse(fe->parser,
fe->conn.in_buffer_pos,
(char *) fe->conn.in_buffer))
if (0 > (rv = pk_parser_parse(fe->parser,
fe->conn.in_buffer_pos,
(char *) fe->conn.in_buffer)))
{
/* Parse failed: remote is borked: should kill this conn. */
fe->conn.status |= CONN_STATUS_BROKEN;
pk_log(PK_LOG_TUNNEL_HEADERS, "pkm_tunnel_readable_cb(): parse failed!");
pk_log(PK_LOG_TUNNEL_HEADERS,
"pkm_tunnel_readable_cb(): parse error = %d", rv);
pk_dump_state(fe->manager);
}
fe->conn.in_buffer_pos = 0;
}
Expand Down
3 changes: 3 additions & 0 deletions pkproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Note: For alternate license terms, see the file COPYING.md.
#include "utils.h"
#include "pkconn.h"
#include "pkproto.h"
#include "pkstate.h"
#include "pkblocker.h"
#include "pkmanager.h"
#include "pklogging.h"
#include "pkerror.h"

Expand Down

0 comments on commit 7ec775c

Please sign in to comment.