|
|
@@ -140,8 +140,15 @@ static void fetch_fail(unsigned int status, int err, const char *ctype,
|
|
|
u_syscall3(SYS_WRITE_FILE, (int)fp.meta, (int)meta, (int)n);
|
|
|
}
|
|
|
|
|
|
+struct fetch_times {
|
|
|
+ unsigned int open_ms;
|
|
|
+ unsigned int first_ms;
|
|
|
+ unsigned int total_ms;
|
|
|
+};
|
|
|
+
|
|
|
static void write_meta(unsigned int seq, int with_seq, struct uhttp *h,
|
|
|
- int err, unsigned int body_len, unsigned int body_trunc)
|
|
|
+ int err, unsigned int body_len, unsigned int body_trunc,
|
|
|
+ const struct fetch_times *t)
|
|
|
{
|
|
|
char meta[1024];
|
|
|
unsigned int n = 0;
|
|
|
@@ -157,6 +164,9 @@ static void write_meta(unsigned int seq, int with_seq, struct uhttp *h,
|
|
|
app_str(meta, &n, h->resp.content_type, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
app_str(meta, &n, h->resp.final_url, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
app_dec(meta, &n, body_len, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
+ app_dec(meta, &n, t ? t->open_ms : 0, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
+ app_dec(meta, &n, t ? t->first_ms : 0, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
+ app_dec(meta, &n, t ? t->total_ms : 0, sizeof(meta)); app_ch(meta, &n, '\n', sizeof(meta));
|
|
|
u_syscall3(SYS_WRITE_FILE, (int)fp.meta, (int)meta, (int)n);
|
|
|
}
|
|
|
|
|
|
@@ -164,14 +174,21 @@ static void write_meta(unsigned int seq, int with_seq, struct uhttp *h,
|
|
|
static void helper_fetch(struct uhttp *h, const char *url, unsigned int cap,
|
|
|
const char *post, unsigned int post_len,
|
|
|
unsigned char *buf, unsigned int *outlen,
|
|
|
- unsigned int *outtrunc, int *outerr)
|
|
|
+ unsigned int *outtrunc, int *outerr,
|
|
|
+ struct fetch_times *times)
|
|
|
{
|
|
|
unsigned int total = 0;
|
|
|
+ unsigned int t0 = u_ticks_ms(), t1, tfirst = 0;
|
|
|
int rv, trunc = 0, err = 0;
|
|
|
|
|
|
*outlen = 0;
|
|
|
*outtrunc = 0;
|
|
|
*outerr = 0;
|
|
|
+ if (times) {
|
|
|
+ times->open_ms = 0;
|
|
|
+ times->first_ms = 0;
|
|
|
+ times->total_ms = 0;
|
|
|
+ }
|
|
|
uhttp_set_method(h, post_len ? "POST" : 0, post, post_len,
|
|
|
"application/x-www-form-urlencoded");
|
|
|
rv = uhttp_open(h, url, UHTTP_GZIP, 0);
|
|
|
@@ -183,6 +200,11 @@ static void helper_fetch(struct uhttp *h, const char *url, unsigned int cap,
|
|
|
rv = uhttp_open(h, url, UHTTP_GZIP, 0);
|
|
|
}
|
|
|
}
|
|
|
+ t1 = u_ticks_ms();
|
|
|
+ if (times) {
|
|
|
+ times->open_ms = t1 - t0;
|
|
|
+ times->total_ms = t1 - t0;
|
|
|
+ }
|
|
|
if (rv != 0) {
|
|
|
*outerr = rv;
|
|
|
return;
|
|
|
@@ -191,6 +213,8 @@ static void helper_fetch(struct uhttp *h, const char *url, unsigned int cap,
|
|
|
rv = uhttp_read(h, buf + total, cap - total,
|
|
|
UHTTP_IDLE_TIMEOUT_MS);
|
|
|
if (rv > 0) {
|
|
|
+ if (!tfirst)
|
|
|
+ tfirst = u_ticks_ms();
|
|
|
total += (unsigned int)rv;
|
|
|
if (total >= cap) {
|
|
|
trunc = 1;
|
|
|
@@ -205,12 +229,19 @@ static void helper_fetch(struct uhttp *h, const char *url, unsigned int cap,
|
|
|
*outlen = total;
|
|
|
*outtrunc = (unsigned int)trunc;
|
|
|
*outerr = err;
|
|
|
+ if (times) {
|
|
|
+ times->first_ms = tfirst ? tfirst - t0 : 0;
|
|
|
+ times->total_ms = u_ticks_ms() - t0;
|
|
|
+ if (!times->total_ms)
|
|
|
+ times->total_ms = 1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void fetch_once(void)
|
|
|
{
|
|
|
static struct uhttp h;
|
|
|
char req[768];
|
|
|
+ struct fetch_times times;
|
|
|
|
|
|
fetch_paths_init(0, -1);
|
|
|
unsigned char *buf;
|
|
|
@@ -248,11 +279,12 @@ static void fetch_once(void)
|
|
|
|
|
|
uhttp_init(&h);
|
|
|
h.user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36";
|
|
|
- helper_fetch(&h, req + i, cap, 0, 0, buf, &body_len, &body_trunc, &err);
|
|
|
+ helper_fetch(&h, req + i, cap, 0, 0, buf, &body_len, &body_trunc, &err,
|
|
|
+ ×);
|
|
|
if (body_len)
|
|
|
u_syscall3(SYS_WRITE_FILE, (int)fp.body, (int)buf,
|
|
|
(int)body_len);
|
|
|
- write_meta(0, 0, &h, err, body_len, body_trunc);
|
|
|
+ write_meta(0, 0, &h, err, body_len, body_trunc, ×);
|
|
|
uhttp_close(&h);
|
|
|
free(buf);
|
|
|
u_exit(err ? 1 : 0);
|
|
|
@@ -266,6 +298,7 @@ static void fetch_serve(const char *arg)
|
|
|
{
|
|
|
static struct uhttp h;
|
|
|
char req[768];
|
|
|
+ struct fetch_times times;
|
|
|
unsigned char *buf, *post;
|
|
|
unsigned int last_seq = 0, idle = 0, session = 0;
|
|
|
int slot = -1;
|
|
|
@@ -343,8 +376,11 @@ static void fetch_serve(const char *arg)
|
|
|
}
|
|
|
if (!url || !url[0] || seq == last_seq) {
|
|
|
idle++;
|
|
|
- u_sleep_ms(50);
|
|
|
- if (idle >= 200)
|
|
|
+ /* 10 ms keeps the next navigation's first request from
|
|
|
+ * waiting on this poll; 1000 ticks is still ten idle
|
|
|
+ * seconds before the helper releases the NIC. */
|
|
|
+ u_sleep_ms(10);
|
|
|
+ if (idle >= 1000)
|
|
|
break;
|
|
|
continue;
|
|
|
}
|
|
|
@@ -368,11 +404,11 @@ static void fetch_serve(const char *arg)
|
|
|
}
|
|
|
|
|
|
helper_fetch(&h, url, cap, is_post ? (char *)post : 0, post_len,
|
|
|
- buf, &body_len, &body_trunc, &err);
|
|
|
+ buf, &body_len, &body_trunc, &err, ×);
|
|
|
if (body_len)
|
|
|
u_syscall3(SYS_WRITE_FILE, (int)fp.body, (int)buf,
|
|
|
(int)body_len);
|
|
|
- write_meta(seq, 1, &h, err, body_len, body_trunc);
|
|
|
+ write_meta(seq, 1, &h, err, body_len, body_trunc, ×);
|
|
|
app_dec(done, &dn, seq, sizeof(done));
|
|
|
u_syscall3(SYS_WRITE_FILE, (int)fp.done, (int)done, (int)dn);
|
|
|
|
|
|
@@ -399,7 +435,7 @@ void _start(const char *arg)
|
|
|
{
|
|
|
static struct uhttp h;
|
|
|
unsigned char buf[512];
|
|
|
- unsigned int total = 0;
|
|
|
+ unsigned int total = 0, t0, t1 = 0, t2 = 0;
|
|
|
int rv;
|
|
|
|
|
|
if (arg && arg[0] == '_' && arg[1] == '_') {
|
|
|
@@ -424,7 +460,9 @@ void _start(const char *arg)
|
|
|
u_puts(arg);
|
|
|
u_putc('\n');
|
|
|
|
|
|
+ t0 = u_ticks_ms();
|
|
|
rv = uhttp_open(&h, arg, 0, &hooks);
|
|
|
+ t1 = u_ticks_ms();
|
|
|
if (rv != 0) {
|
|
|
u_puts("curl: ");
|
|
|
u_puts(uhttp_error_string(rv));
|
|
|
@@ -442,6 +480,8 @@ void _start(const char *arg)
|
|
|
if (rv > 0) {
|
|
|
int i;
|
|
|
|
|
|
+ if (!t2)
|
|
|
+ t2 = u_ticks_ms();
|
|
|
for (i = 0; i < rv; i++)
|
|
|
u_putc((char)buf[i]);
|
|
|
total += (unsigned int)rv;
|
|
|
@@ -459,6 +499,19 @@ void _start(const char *arg)
|
|
|
u_putdec(total);
|
|
|
u_puts(" bytes received, status ");
|
|
|
u_putdec((unsigned int)h.resp.status);
|
|
|
+ if (t2) {
|
|
|
+ u_puts(", ");
|
|
|
+ u_putdec(t2 - t0);
|
|
|
+ u_puts(" ms to first byte");
|
|
|
+ }
|
|
|
+ u_puts(", ");
|
|
|
+ u_putdec(u_ticks_ms() - t0);
|
|
|
+ u_puts(" ms total");
|
|
|
+ if (!t2 && t1) {
|
|
|
+ u_puts(" (headers ");
|
|
|
+ u_putdec(t1 - t0);
|
|
|
+ u_puts(" ms)");
|
|
|
+ }
|
|
|
u_putc('\n');
|
|
|
uhttp_close(&h);
|
|
|
u_exit(0);
|