static void update(int p) { struct top *tp, *tp2; int l, len; double t = 0; static time_t last = 0; static unsigned n; time_t now; now = time(NULL); if (now == last) return; last = now; l = 1; if (n < p) n++; AC(erase()); if (end_of_file) AC(mvprintw(0, COLS - 1 - strlen(VUT.name) - 5, "%s (EOF)", VUT.name)); else AC(mvprintw(0, COLS - 1 - strlen(VUT.name), "%s", VUT.name)); AC(mvprintw(0, 0, "list length %u", ntop)); for (tp = VRB_MIN(t_order, &h_order); tp != NULL; tp = tp2) { tp2 = VRB_NEXT(t_order, &h_order, tp); if (++l < LINES) { len = tp->clen; if (len > COLS - 20) len = COLS - 20; AC(mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n", tp->count, maxfieldlen, maxfieldlen, VSL_tags[tp->tag], len, len, tp->rec_data)); t = tp->count; } if (end_of_file) continue; tp->count += (1.0/3.0 - tp->count) / (double)n; if (tp->count * 10 < t || l > LINES * 10) { VRB_REMOVE(t_key, &h_key, tp); VRB_REMOVE(t_order, &h_order, tp); free(tp->rec_buf); free(tp); ntop--; } } AC(refresh()); }
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); }
static void update(const struct VSM_data *vd, int period) { struct top *tp, *tp2; int l, len; double t = 0; static time_t last = 0; static unsigned n; time_t now; now = time(NULL); if (now == last) return; last = now; l = 1; if (n < period) n++; AC(erase()); AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd))); AC(mvprintw(0, 0, "list length %u", ntop)); for (tp = VRB_MIN(top_tree, &top_tree_head); tp != NULL; tp = tp2) { tp2 = VRB_NEXT(top_tree, &top_tree_head, tp); if (++l < LINES) { len = tp->clen; if (len > COLS - 20) len = COLS - 20; AC(mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n", tp->count, maxfieldlen, maxfieldlen, VSL_tags[tp->tag], len, len, tp->rec_data)); t = tp->count; } tp->count += (1.0/3.0 - tp->count) / (double)n; if (tp->count * 10 < t || l > LINES * 10) { VRB_REMOVE(top_tree, &top_tree_head, tp); free(tp->rec_data); free(tp); ntop--; } } AC(refresh()); }
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); }