From 37a5071021601480384c2abe20f2d33ad974579d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 7 Aug 2013 20:03:34 +0000 Subject: flesh out systemtap support and awk helpers Our "all.stp" tapset now generates awk-friendly output for feeding some sample awk scripts. Using awk (and gawk) was necessary to avoid reimplementing strftime in guru mode for generating CLF (Common Log Format) HTTP access logs. Using awk also gives us several advantages: * floating point number support (for time differences) * a more familiar language to systems administrators (given this is for MogileFS, perhaps Perl would be even more familiar...). * fast edit/run cycle, so the slowness of using stap to rebuild/reload the kernel module for all.stp changes can be avoided when output must be customized. --- http.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'http.c') diff --git a/http.c b/http.c index 3ec62a6..547fdb1 100644 --- a/http.c +++ b/http.c @@ -205,7 +205,7 @@ static enum mog_next http_run(struct mog_fd *mfd, struct mog_rbuf *rbuf, } else { /* pipelined request */ if (buf_len) - TRACE(CMOGSTORED_HTTP_REQ_BEGIN(true)); + TRACE(CMOGSTORED_HTTP_REQ_BEGIN(mfd->fd, true)); http_defer_rbuf(http, rbuf, buf_len); mog_http_reset(mfd); @@ -219,7 +219,7 @@ http_client_died(struct mog_fd *mfd, size_t buf_len, int save_err) struct mog_ni ni; /* TODO: support nameinfo */ - TRACE(CMOGSTORED_HTTP_RDERR(buf_len, save_err)); + TRACE(CMOGSTORED_HTTP_RDERR(mfd->fd, buf_len, save_err)); switch (save_err) { case ECONNRESET: @@ -240,6 +240,7 @@ http_rbuf_grow(struct mog_fd *mfd, struct mog_rbuf **rbuf, size_t buf_len) { struct mog_http *http = &mfd->as.http; + TRACE(CMOGSTORED_HTTP_RBUF_GROW(mfd->fd, buf_len)); (*rbuf)->rsize = buf_len; http->rbuf = *rbuf = mog_rbuf_grow(*rbuf); return *rbuf ? (*rbuf)->rptr : NULL; @@ -251,6 +252,7 @@ http_parse_continue(struct mog_fd *mfd, struct mog_rbuf **rbuf, { struct mog_http *http = &mfd->as.http; + TRACE(CMOGSTORED_HTTP_PARSE_CONTINUE(mfd->fd, buf_len)); assert(http->wbuf == NULL && "tried to write (and failed) with partial req"); if (http->_p.buf_off >= (*rbuf)->rcapa) { @@ -302,7 +304,7 @@ reread: r = read(mfd->fd, buf + off, rbuf->rcapa - off); if (r > 0) { if (off == 0) - TRACE(CMOGSTORED_HTTP_REQ_BEGIN(false)); + TRACE(CMOGSTORED_HTTP_REQ_BEGIN(mfd->fd, false)); buf_len = r + off; parse: @@ -320,7 +322,7 @@ parse: return http_run(mfd, rbuf, buf, buf_len); } } else if (r == 0) { /* client shut down */ - TRACE(CMOGSTORED_HTTP_RDCLOSE(buf_len)); + TRACE(CMOGSTORED_HTTP_CLIENT_CLOSE(mfd->fd, buf_len)); return MOG_NEXT_CLOSE; } else { switch (errno) { @@ -476,10 +478,18 @@ void mog_http_resp0(struct mog_fd *mfd, struct iovec *status, bool alive) struct mog_http *http = &mfd->as.http; assert(status->iov_len * 2 + 1024 < iov.iov_len && "fsbuf too small"); + assert(status->iov_len > 3 && "HTTP response status too short"); #define CPY(str) mempcpy(dst, (str),(sizeof(str)-1)) dst = CPY("HTTP/1.1 "); dst = mempcpy(dst, status->iov_base, status->iov_len); + + /* + * putting this here avoids systemtap faults, as status->iov_base + * is already hot in cache from the above mempcpy + */ + TRACE(CMOGSTORED_HTTP_RES_START(mfd->fd, status->iov_base)); + dst = CPY("\r\nDate: "); now = mog_now(); dst = mempcpy(dst, now->httpdate, sizeof(now->httpdate)-1); @@ -502,6 +512,7 @@ void mog_http_resp0(struct mog_fd *mfd, struct iovec *status, bool alive) /* call whenever we're ready to read the next HTTP request */ void mog_http_reset(struct mog_fd *mfd) { + TRACE(CMOGSTORED_HTTP_RES_DONE(mfd->fd)); tcp_push(mfd, true); mog_http_reset_parser(&mfd->as.http); } -- cgit v1.2.3-24-ge0c7