-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.c
48 lines (43 loc) · 1.93 KB
/
stats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "stats.h"
#include "humanize.h"
#include <stdio.h>
#include "functions.h"
#include "log.h"
#include "malloc.h"
#include "humanize.h"
extern Stats stats;
extern bool LOG_STATS;
const char* strstat(Stats st)
{
static char str[1024];
sprintf(str,
"sent: %s\t"
"recv: %s\t"
"c: %ld\t"
"tc: %ld",
humanize_bytes(st.bytesSent), humanize_bytes(st.bytesReceived), st.connectionCount,
st.connectionCountMax);
return str;
}
char * stats_html(Stats st, char * document) {
czero(document);
csprintf(document, "<table>\n");
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Total accepted:", st.connectionCount);
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Max concurrency:", st.connectionCountMax);
csprintf(document, "<tr><th>%s</th><td>%s</td></tr>\n", "Bytes sent:", humanize_bytes(st.bytesSent));
csprintf(document, "<tr><th>%s</th><td>%s</td></tr>\n", "Bytes received:", humanize_bytes(st.bytesReceived));
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Requests started:", st.requestCount);
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Requests done:", st.requestDone);
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Requests error:", st.requestError);
csprintf(document, "<tr><th>%s</th><td>%ld</td></tr>\n", "Requests chunks:", st.requestChunks);
csprintf(document, "<tr><th>%s</th><td>%s</td></tr>\n", "Memory allocated", humanize_bytes(httpc_allocated));
csprintf(document, "<tr><th>%s</th><td>%s</td></tr>\n", "Memory freed", humanize_bytes(httpc_freed));
csprintf(document, "<tr><th>%s</th><td>%s</td></tr>\n", "Memory allocated peak", humanize_bytes(httpc_allocated_max));
csprintf(document, "</table>\n");
LogLine * line = log_tail(250);
while(line) {
csprintf(document, "%s<br />\n", strtrimr(line->line,'\n'));
line = line->next;
}
return document;
}