vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, int id)
{
- p[1] = len & 0xff;
- p[2] = (id >> 8) & 0xff;
- p[3] = id & 0xff;
- p[4 + len] = '\0';
- p[5 + len] = SLT_ENDMARKER;
+ p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff;
+ p[__SHMLOG_LEN_LOW] = len & 0xff;
+ p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff;
+ p[__SHMLOG_ID_LOW] = id & 0xff;
+ p[SHMLOG_DATA + len] = '\0';
+ p[SHMLOG_NEXTTAG + len] = SLT_ENDMARKER;
/* XXX: Write barrier here */
- p[0] = tag;
+ p[SHMLOG_TAG] = tag;
}
/*--------------------------------------------------------------------
assert(loghead->ptr < loghead->size);
/* Wrap if necessary */
- if (loghead->ptr + 5 + l + 1 >= loghead->size)
+ if (loghead->ptr + SHMLOG_NEXTTAG + l + 1 >= loghead->size)
vsl_wrap();
p = logstart + loghead->ptr;
- loghead->ptr += 5 + l;
+ loghead->ptr += SHMLOG_NEXTTAG + l;
assert(loghead->ptr < loghead->size);
UNLOCKSHM(&vsl_mtx);
- memcpy(p + 4, t.b, l);
+ memcpy(p + SHMLOG_DATA, t.b, l);
vsl_hdr(tag, p, l, id);
}
assert(loghead->ptr < loghead->size);
/* Wrap if we cannot fit a full size record */
- if (loghead->ptr + 5 + 255 + 1 >= loghead->size)
+ if (loghead->ptr + SHMLOG_NEXTTAG + 255 + 1 >= loghead->size)
vsl_wrap();
p = logstart + loghead->ptr;
- n = vsnprintf((char *)(p + 4), 256, fmt, ap);
+ n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap);
if (n > 255)
n = 255; /* we truncate long fields */
vsl_hdr(tag, p, n, id);
- loghead->ptr += 5 + n;
+ loghead->ptr += SHMLOG_NEXTTAG + n;
assert(loghead->ptr < loghead->size);
UNLOCKSHM(&vsl_mtx);
}
va_end(ap);
}
-
/*--------------------------------------------------------------------*/
void
assert(w->wlp < w->wle);
/* Wrap if necessary */
- if (w->wlp + 5 + l + 1 >= w->wle)
+ if (w->wlp + SHMLOG_NEXTTAG + l + 1 >= w->wle)
WSL_Flush(w);
p = w->wlp;
- w->wlp += 5 + l;
+ w->wlp += SHMLOG_NEXTTAG + l;
assert(w->wlp < w->wle);
- memcpy(p + 4, t.b, l);
+ memcpy(p + SHMLOG_DATA, t.b, l);
vsl_hdr(tag, p, l, id);
w->wlr++;
}
assert(w->wlp < w->wle);
/* Wrap if we cannot fit a full size record */
- if (w->wlp + 5 + 255 + 1 >= w->wle)
+ if (w->wlp + SHMLOG_NEXTTAG + 255 + 1 >= w->wle)
WSL_Flush(w);
p = w->wlp;
- n = vsnprintf((char *)(p + 4), 256, fmt, ap);
+ n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap);
if (n > 255)
n = 255; /* we truncate long fields */
vsl_hdr(tag, p, n, id);
- w->wlp += 5 + n;
+ w->wlp += SHMLOG_NEXTTAG + n;
assert(w->wlp < w->wle);
w->wlr++;
}
static void
do_write(struct VSL_data *vd, const char *w_arg, int a_flag)
{
- int fd, i;
+ int fd, i, l;
unsigned char *p;
fd = open_log(w_arg, a_flag);
if (i < 0)
break;
if (i > 0) {
- i = write(fd, p, 5 + p[1]);
+ l = SHMLOG_LEN(p);
+ i = write(fd, p, SHMLOG_NEXTTAG + l);
if (i < 0) {
perror(w_arg);
exit(1);
{
struct top *tp, *tp2;
const unsigned char *q;
- unsigned int u;
+ unsigned int u, l;
int i;
// fprintf(stderr, "%*.*s\n", p[1], p[1], p + 4);
u = 0;
- q = p + 4;
- for (i = 0; i < p[1]; i++, q++) {
+ q = p + SHMLOG_DATA;
+ l = SHMLOG_LEN(p);
+ for (i = 0; i < l; i++, q++) {
if (f_flag && (*q == ':' || isspace(*q)))
break;
u += *q;
VTAILQ_FOREACH(tp, &top_head, list) {
if (tp->hash != u)
continue;
- if (tp->rec[0] != p[0])
+ if (tp->rec[SHMLOG_TAG] != p[SHMLOG_TAG])
continue;
if (tp->clen != q - p)
continue;
- if (memcmp(p + 4, tp->rec + 4, q - (p + 4)))
+ if (memcmp(p + SHMLOG_DATA, tp->rec + SHMLOG_DATA,
+ q - (p + SHMLOG_DATA)))
continue;
tp->count += 1.0;
break;
tp->clen = q - p;
VTAILQ_INSERT_TAIL(&top_head, tp, list);
}
- memcpy(tp->rec, p, 4 + p[1]);
+ memcpy(tp->rec, p, SHMLOG_DATA + l);
while (1) {
tp2 = VTAILQ_PREV(tp, tophead, list);
if (tp2 == NULL || tp2->count >= tp->count)
update(void)
{
struct top *tp, *tp2;
- int l;
+ int l, len;
double t = 0;
static time_t last;
time_t now;
mvprintw(0, 0, "list length %u", ntop);
VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) {
if (++l < LINES) {
- int len = tp->rec[1];
+ len = SHMLOG_LEN(tp->rec);
if (len > COLS - 20)
len = COLS - 20;
mvprintw(l, 0, "%9.2f %-9.9s %*.*s\n",
- tp->count, VSL_tags[tp->rec[0]],
- len, len, tp->rec + 4);
+ tp->count, VSL_tags[tp->rec[SHMLOG_TAG]],
+ len, len, tp->rec + SHMLOG_DATA);
t = tp->count;
}
tp->count *= .999;
* Record format is as follows:
*
* 1 byte field type (enum shmlogtag)
- * 1 byte length of contents
- * 2 byte record identifier
+ * 2 bytes length of contents
+ * 2 bytes record identifier
* n bytes field contents (isgraph(c) || isspace(c)) allowed.
*/
+#define SHMLOG_TAG 0
+#define __SHMLOG_LEN_HIGH 1
+#define __SHMLOG_LEN_LOW 2
+#define __SHMLOG_ID_HIGH 3
+#define __SHMLOG_ID_LOW 4
+#define SHMLOG_DATA 5
+#define SHMLOG_NEXTTAG 6 /* ... + len */
+
+#define SHMLOG_LEN(p) (((p)[__SHMLOG_LEN_HIGH] << 8) | (p)[__SHMLOG_LEN_LOW])
+#define SHMLOG_ID(p) (((p)[__SHMLOG_ID_HIGH] << 8) | (p)[__SHMLOG_ID_LOW])
+
/*
* The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run
* on this file to extract the table rather than handcode it
/* for -r option */
FILE *fi;
- unsigned char rbuf[5 + 255 + 1];
+ unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1];
int b_opt;
int c_opt;
if (!vd->d_opt && vd->fi == NULL) {
for (p = vd->ptr; *p != SLT_ENDMARKER; )
- p += p[1] + 5;
+ p += SHMLOG_LEN(p) + SHMLOG_NEXTTAG;
vd->ptr = p;
}
return (0);
vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
{
unsigned char *p;
- unsigned w;
+ unsigned w, l;
int i;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL) {
- i = fread(vd->rbuf, 4, 1, vd->fi);
+ i = fread(vd->rbuf, SHMLOG_DATA, 1, vd->fi);
if (i != 1)
return (-1);
- i = fread(vd->rbuf + 4, vd->rbuf[1] + 1, 1, vd->fi);
+ i = fread(vd->rbuf + SHMLOG_DATA,
+ SHMLOG_LEN(vd->rbuf) + 1, 1, vd->fi);
if (i != 1)
return (-1);
*pp = vd->rbuf;
usleep(SLEEP_USEC);
continue;
}
- vd->ptr = p + p[1] + 5;
+ l = SHMLOG_LEN(p);
+ vd->ptr = p + l + SHMLOG_NEXTTAG;
*pp = p;
return (1);
}
{
unsigned char *p;
regmatch_t rm;
- unsigned u;
+ unsigned u, l;
int i;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
i = vsl_nextlog(vd, &p);
if (i != 1)
return (i);
- u = (p[2] << 8) | p[3];
- switch(p[0]) {
+ u = SHMLOG_ID(p);
+ l = SHMLOG_LEN(p);
+ switch(p[SHMLOG_TAG]) {
case SLT_SessionOpen:
case SLT_ReqStart:
vd->map[u] |= M_CLIENT;
default:
break;
}
- if (vd->map[p[0]] & M_SELECT) {
+ if (vd->map[p[SHMLOG_TAG]] & M_SELECT) {
*pp = p;
return (1);
}
- if (vd->map[p[0]] & M_SUPPRESS)
+ if (vd->map[p[SHMLOG_TAG]] & M_SUPPRESS)
continue;
if (vd->b_opt && !(vd->map[u] & M_BACKEND))
continue;
continue;
if (vd->regincl != NULL) {
rm.rm_so = 0;
- rm.rm_eo = p[1];
- i = regexec(vd->regincl, (char *)p + 4, 1, &rm, 0);
+ rm.rm_eo = l;
+ i = regexec(vd->regincl,
+ (char *)p + SHMLOG_DATA, 1, &rm, 0);
if (i == REG_NOMATCH)
continue;
}
if (vd->regexcl != NULL) {
rm.rm_so = 0;
- rm.rm_eo = p[1];
- i = regexec(vd->regexcl, (char *)p + 4, 1, &rm, 0);
+ rm.rm_eo = l;
+ i = regexec(vd->regexcl,
+ (char *)p + SHMLOG_DATA, 1, &rm, 0);
if (i != REG_NOMATCH)
continue;
}
VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv)
{
int i;
- unsigned u;
+ unsigned u, l;
unsigned char *p;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
i = VSL_NextLog(vd, &p);
if (i <= 0)
return (i);
- u = (p[2] << 8) | p[3];
+ u = SHMLOG_ID(p);
+ l = SHMLOG_LEN(p);
if (func(priv,
- p[0], u, p[1],
+ p[SHMLOG_TAG], u, l,
vd->map[u] & (VSL_S_CLIENT|VSL_S_BACKEND),
- (char *)p + 4))
+ (char *)p + SHMLOG_DATA))
return (1);
}
}