about summary refs log tree commit homepage
path: root/http.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-07 20:03:34 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-26 20:41:08 +0000
commit37a5071021601480384c2abe20f2d33ad974579d (patch)
treeb0cc006c9cac9da7002e44adcfba2737bc0ce83f /http.c
parentfe1e1200c1541676e6b8402b7972a16105a76a63 (diff)
downloadcmogstored-37a5071021601480384c2abe20f2d33ad974579d.tar.gz
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.
Diffstat (limited to 'http.c')
-rw-r--r--http.c19
1 files changed, 15 insertions, 4 deletions
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);
 }