Example #1
0
static int
accumulate(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
    unsigned spec, const char *ptr, uint64_t bm)
{
	struct top *tp, t;
	const char *q;
	char *rd;
	unsigned int u;
	int i;

	(void)priv;
	(void)fd;
	(void)spec;
	(void)bm;
	// fprintf(stderr, "%p %08x %08x\n", p, p[0], p[1]);

	u = 0;
	q = ptr;
	for (i = 0; i < len; i++, q++) {
		if (f_flag && (*q == ':' || isspace(*q))) {
			len = q - ptr;
			break;
		}
		u += *q;
	}
	t.hash = u;
	t.tag = tag;
	t.clen = len;
	rd = malloc(len);
	AN(rd);
	memcpy(rd, ptr, len);
	t.rec_data = rd;

	AZ(pthread_mutex_lock(&mtx));
	tp = VRB_FIND(top_tree, &top_tree_head, &t);
	if (tp) {
		VRB_REMOVE(top_tree, &top_tree_head, tp);
		tp->count += 1.0;
		/* Reinsert to rebalance */
		VRB_INSERT(top_tree, &top_tree_head, tp);
	} else {
		ntop++;
		tp = calloc(sizeof *tp, 1);
		assert(tp != NULL);
		tp->rec_data = calloc(len + 1, 1);
		assert(tp->rec_data != NULL);
		tp->hash = u;
		tp->count = 1.0;
		tp->clen = len;
		tp->tag = tag;
		memcpy(tp->rec_data, ptr, len);
		tp->rec_data[len] = '\0';
		VRB_INSERT(top_tree, &top_tree_head, tp);
	}
	AZ(pthread_mutex_unlock(&mtx));

	return (0);
}
Example #2
0
accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
	void *priv)
{
	struct top *tp, t;
	unsigned int u;
	unsigned tag;
	const char *b, *e, *p;
	unsigned len;
	struct VSL_transaction *tr;

	(void)priv;

	for (tr = pt[0]; tr != NULL; tr = *++pt) {
		while ((1 == VSL_Next(tr->c))) {
			if (!VSL_Match(vsl, tr->c))
				continue;
			tag = VSL_TAG(tr->c->rec.ptr);
			b = VSL_CDATA(tr->c->rec.ptr);
			e = b + VSL_LEN(tr->c->rec.ptr);
			u = 0;
			for (p = b; p <= e; p++) {
				if (*p == '\0')
					break;
				if (f_flag && (*p == ':' || isspace(*p)))
					break;
				u += *p;
			}
			len = p - b;
			if (len == 0)
				continue;

			t.hash = u;
			t.tag = tag;
			t.clen = len;
			t.rec_data = VSL_CDATA(tr->c->rec.ptr);

			AZ(pthread_mutex_lock(&mtx));
			tp = VRB_FIND(t_key, &h_key, &t);
			if (tp) {
				VRB_REMOVE(t_order, &h_order, tp);
				tp->count += 1.0;
				/* Reinsert to rebalance */
				VRB_INSERT(t_order, &h_order, tp);
			} else {
				ntop++;
				tp = calloc(sizeof *tp, 1);
				assert(tp != NULL);
				tp->hash = u;
				tp->count = 1.0;
				tp->clen = len;
				tp->tag = tag;
				tp->rec_buf = strdup(t.rec_data);
				tp->rec_data = tp->rec_buf;
				AN(tp->rec_data);
				VRB_INSERT(t_key, &h_key, tp);
				VRB_INSERT(t_order, &h_order, tp);
			}
			AZ(pthread_mutex_unlock(&mtx));

		}
	}

	return (0);
}