Merge branch 'master' of git.dolda2000.com:/srv/git/r/ashd
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 18 May 2016 04:48:32 +0000 (06:48 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 18 May 2016 04:48:32 +0000 (06:48 +0200)
lib/mtio.c
lib/mtio.h
python/ashd/perf.py
python3/ashd/perf.py
src/accesslog.c
src/callfcgi.c
src/callscgi.c
src/htparser.c
src/plaintcp.c
src/psendfile.c

index b2f55f8..d7f36ac 100644 (file)
 #include <mt.h>
 #include <mtio.h>
 
-struct stdiofd {
-    int fd;
-    int sock;
-    int timeout;
-};
-
 static ssize_t mtread(void *cookie, void *buf, size_t len)
 {
     struct stdiofd *d = cookie;
@@ -98,7 +92,7 @@ static int mtclose(void *cookie)
     return(0);
 }
 
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop)
 {
     struct stdiofd *d;
     FILE *ret;
@@ -117,11 +111,13 @@ FILE *mtstdopen(int fd, int issock, int timeout, char *mode)
     d->fd = fd;
     d->sock = issock;
     d->timeout = timeout;
-    ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose);
-    if(!ret)
+    if(!(ret = funstdio(d, r?mtread:NULL, w?mtwrite:NULL, NULL, mtclose))) {
        free(d);
-    else
-       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+       return(NULL);
+    }
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+    if(infop)
+       *infop = d;
     return(ret);
 }
 
index 2bc21fd..75928eb 100644 (file)
@@ -6,10 +6,16 @@
 #define EV_READ 1
 #define EV_WRITE 2
 
+struct stdiofd {
+    int fd;
+    int sock;
+    int timeout;
+};
+
 int block(int fd, int ev, time_t to);
 int ioloop(void);
 void exitioloop(int status);
-FILE *mtstdopen(int fd, int issock, int timeout, char *mode);
+FILE *mtstdopen(int fd, int issock, int timeout, char *mode, struct stdiofd **infop);
 void mtiopipe(FILE **read, FILE **write);
 
 #endif
index 97146a8..c74e443 100644 (file)
@@ -16,8 +16,13 @@ if pdm:
             self.method = env.get("REQUEST_METHOD")
             self.uri = env.get("REQUEST_URI")
             self.host = env.get("HTTP_HOST")
+            self.script_uri = env.get("SCRIPT_NAME")
+            self.script_path = env.get("SCRIPT_FILENAME")
+            self.pathinfo = env.get("PATH_INFO")
+            self.querystring = env.get("QUERY_STRING")
             self.remoteaddr = env.get("REMOTE_ADDR")
             self.remoteport = env.get("REMOTE_PORT")
+            self.scheme = env.get("wsgi.url_scheme")
 
     class reqfinish(pdm.perf.finishevent):
         def __init__(self, start, aborted, status):
index 6942424..86fe43c 100644 (file)
@@ -3,6 +3,11 @@ try:
     import pdm.perf
 except:
     pdm = None
+try:
+    import time
+    clock_thread = time.CLOCK_THREAD_CPUTIME_ID
+except:
+    clock_thread = None
 
 reqstat = {}
 
@@ -17,13 +22,23 @@ if pdm:
             self.method = env.get("REQUEST_METHOD")
             self.uri = env.get("REQUEST_URI")
             self.host = env.get("HTTP_HOST")
+            self.script_uri = env.get("SCRIPT_NAME")
+            self.script_path = env.get("SCRIPT_FILENAME")
+            self.pathinfo = env.get("PATH_INFO")
+            self.querystring = env.get("QUERY_STRING")
             self.remoteaddr = env.get("REMOTE_ADDR")
             self.remoteport = env.get("REMOTE_PORT")
+            self.scheme = env.get("wsgi.url_scheme")
+            if clock_thread is not None:
+                self.icpu = time.clock_gettime(clock_thread)
 
     class reqfinish(pdm.perf.finishevent):
         def __init__(self, start, aborted, status):
             super().__init__(start, aborted)
             self.status = status
+            self.cputime = 0
+            if clock_thread is not None:
+                self.cputime = time.clock_gettime(clock_thread) - start.icpu
 
 class request(object):
     def __init__(self, env):
index 1addb38..a3894bf 100644 (file)
@@ -249,10 +249,10 @@ static void filterreq(struct muth *mt, va_list args)
     data = defdata;
     data.req = req;
     gettimeofday(&data.start, NULL);
-    cl = mtstdopen(fd, 1, 600, "r+");
+    cl = mtstdopen(fd, 1, 600, "r+", NULL);
     if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
        goto out;
-    hd = mtstdopen(pfds[1], 1, 600, "r+");
+    hd = mtstdopen(pfds[1], 1, 600, "r+", NULL);
     if(sendreq(ch, req, pfds[0])) {
        close(pfds[0]);
        goto out;
index 6b04c20..8d33eef 100644 (file)
@@ -690,12 +690,12 @@ static void serve(struct muth *muth, va_list args)
     char buf[8192];
     
     sfd = reconn();
-    is = mtstdopen(fd, 1, 60, "r+");
-    os = mtstdopen(sfd, 1, 600, "r+");
+    is = mtstdopen(fd, 1, 60, "r+", NULL);
+    os = mtstdopen(sfd, 1, 600, "r+", NULL);
     
     outi = NULL;
     mtiopipe(&outi, &outo); mtiopipe(&erri, &erro);
-    mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+"), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
+    mustart(outplex, mtstdopen(dup(sfd), 1, 600, "r+", NULL), outo, FCGI_STDOUT, erro, FCGI_STDERR, NULL);
     mustart(errhandler, erri);
     
     if(begreq(os, 1))
index 3c26e33..2483c49 100644 (file)
@@ -521,8 +521,8 @@ static void serve(struct muth *muth, va_list args)
     struct hthead *resp;
     
     sfd = reconn();
-    is = mtstdopen(fd, 1, 60, "r+");
-    os = mtstdopen(sfd, 1, 600, "r+");
+    is = mtstdopen(fd, 1, 60, "r+", NULL);
+    os = mtstdopen(sfd, 1, 600, "r+", NULL);
     
     bufinit(head);
     mkcgienv(req, &head);
index a20b329..92445d7 100644 (file)
@@ -328,7 +328,7 @@ void serve(FILE *in, struct conn *conn)
        if(sendreq(plex, req, pfds[0]))
            break;
        close(pfds[0]);
-       out = mtstdopen(pfds[1], 1, 600, "r+");
+       out = mtstdopen(pfds[1], 1, 600, "r+", NULL);
 
        if(getheader(req, "content-type") != NULL) {
            if((hd = getheader(req, "content-length")) != NULL) {
index 0592166..1d3e2e7 100644 (file)
@@ -156,7 +156,7 @@ void servetcp(struct muth *muth, va_list args)
     
     memset(&conn, 0, sizeof(conn));
     memset(&tcp, 0, sizeof(tcp));
-    in = mtstdopen(fd, 1, 60, "r+");
+    in = mtstdopen(fd, 1, 60, "r+", NULL);
     conn.pdata = &tcp;
     conn.initreq = initreq;
     tcp.fd = fd;
index f5c7fdd..3e26f8f 100644 (file)
@@ -227,7 +227,7 @@ static void serve(struct muth *muth, va_list args)
     
     sfile = NULL;
     contype = NULL;
-    out = mtstdopen(fd, 1, 60, "r+");
+    out = mtstdopen(fd, 1, 60, "r+", NULL);
     
     if((file = getheader(req, "X-Ash-File")) == NULL) {
        flog(LOG_ERR, "psendfile: needs to be called with the X-Ash-File header");