int main(int argc, char * const *argv) { int i; if (argc != 2) { fprintf(stderr, "vsl_glob_test <tagname/glob>\n"); exit(1); } i = VSL_Name2Tag(argv[1], -1); printf("VSL_Name2Tag returns %d", i); if (i >= 0) printf(" (%s)", VSL_tags[i]); printf("\n"); printf("VSL_Glob2Tags:\n"); i = VSL_Glob2Tags(argv[1], -1, cb, NULL); printf("VSL_Glob2Tags returns %d\n", i); printf("VSL_List2Tags:\n"); i = VSL_List2Tags(argv[1], -1, cb, NULL); printf("VSL_List2Tags returns %d\n", i); return (0); }
static int vsl_ix_arg(struct VSL_data *vsl, int opt, const char *arg) { int i, l; const char *b, *e; CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); /* If first option is 'i', set all bits for supression */ if (opt == 'i' && !(vsl->flags & F_SEEN_ix)) for (i = 0; i < 256; i++) vbit_set(vsl->vbm_supress, i); vsl->flags |= F_SEEN_ix; for (b = arg; *b; b = e) { while (isspace(*b)) b++; e = strchr(b, ','); if (e == NULL) e = strchr(b, '\0'); l = e - b; if (*e == ',') e++; while (isspace(b[l - 1])) l--; i = VSL_Name2Tag(b, l); if (i >= 0) { if (opt == 'x') vbit_set(vsl->vbm_supress, i); else vbit_clr(vsl->vbm_supress, i); } else if (i == -2) { return (vsl_diag(vsl, "-%c: \"%*.*s\" matches multiple tags\n", (char)opt, l, l, b)); } else { return (vsl_diag(vsl, "-%c: Could not match \"%*.*s\" to any tag\n", (char)opt, l, l, b)); } } return (1); }
int main(int argc, char **argv) { int i; const char *colon, *ptag; const char *profile = "responsetime"; pthread_t thr; int fnum = -1; struct profile cli_p = {0}; cli_p.name = 0; VUT_Init(progname, argc, argv, &vopt_spec); AZ(pthread_cond_init(&timebend_cv, NULL)); while ((i = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) { switch (i) { case 'h': /* Usage help */ usage(0); case 'p': delay = strtod(optarg, NULL); if (delay <= 0) VUT_Error(1, "-p: invalid '%s'", optarg); break; case 'P': colon = strchr(optarg, ':'); /* no colon, take the profile as a name */ if (colon == NULL) { profile = optarg; break; } /* else it's a definition, we hope */ if (colon == optarg + 1 && (*optarg == 'b' || *optarg == 'c')) { cli_p.VSL_arg = *optarg; ptag = colon + 1; colon = strchr(colon + 1, ':'); if (colon == NULL) profile_error(optarg); } else { ptag = optarg; cli_p.VSL_arg = 'c'; } assert(colon); if (sscanf(colon + 1, "%d:%d:%d", &cli_p.field, &cli_p.hist_low, &cli_p.hist_high) != 3) profile_error(optarg); match_tag = VSL_Name2Tag(ptag, colon - ptag); if (match_tag < 0) VUT_Error(1, "-P: '%s' is not a valid tag name", optarg); cli_p.name = "custom"; cli_p.tag = match_tag; profile = NULL; active_profile = &cli_p; break; case 'B': timebend = strtod(optarg, NULL); if (timebend == 0) VUT_Error(1, "-B: being able to bend time does not" " mean we can stop it" " (invalid factor '%s')", optarg); if (timebend < 0) VUT_Error(1, "-B: being able to bend time does not" " mean we can make it go backwards" " (invalid factor '%s')", optarg); break; default: if (!VUT_Arg(i, optarg)) usage(1); } } if (optind != argc) usage(1); /* Check for valid grouping mode */ assert(VUT.g_arg < VSL_g__MAX); if (VUT.g_arg != VSL_g_vxid && VUT.g_arg != VSL_g_request) VUT_Error(1, "Invalid grouping mode: %s" " (only vxid and request are supported)", VSLQ_grouping[VUT.g_arg]); if (profile) { for (active_profile = profiles; active_profile->name; active_profile++) { if (strcmp(active_profile->name, profile) == 0) break; } } AN(active_profile); if (!active_profile->name) VUT_Error(1, "-P: No such profile '%s'", profile); assert(VUT_Arg(active_profile->VSL_arg, NULL)); match_tag = active_profile->tag; fnum = active_profile->field; hist_low = active_profile->hist_low; hist_high = active_profile->hist_high; hist_range = hist_high - hist_low; hist_buckets = hist_range * HIST_RES; bucket_hit = calloc(sizeof *bucket_hit, hist_buckets); bucket_miss = calloc(sizeof *bucket_miss, hist_buckets); if (timebend > 0) t0 = VTIM_mono(); format = malloc(4L * fnum); AN(format); for (i = 0; i < fnum - 1; i++) strcpy(format + 4 * i, "%*s "); strcpy(format + 4 * (fnum - 1), "%lf"); log_ten = log(10.0); VUT_Setup(); if (pthread_create(&thr, NULL, do_curses, NULL) != 0) VUT_Error(1, "pthread_create(): %s", strerror(errno)); VUT.dispatch_f = accumulate; VUT.dispatch_priv = NULL; VUT.sighup_f = sighup; VUT_Main(); end_of_file = 1; AZ(pthread_join(thr, NULL)); VUT_Fini(); exit(0); }
int VSL_Glob2Tags(const char *glob, int l, VSL_tagfind_f *func, void *priv) { int i, r, l2; int pre = 0; int post = 0; char buf[64]; AN(glob); if (l < 0) l = strlen(glob); if (l == 0 || l > sizeof buf - 1) return (-1); if (strchr(glob, '*') != NULL) { if (glob[0] == '*') { /* Prefix wildcard */ pre = 1; glob++; l--; } if (l > 0 && glob[l - 1] == '*') { /* Postfix wildcard */ post = 1; l--; } } if (pre && post) /* Support only post or prefix wildcards */ return (-3); memcpy(buf, glob, l); buf[l] = '\0'; if (strchr(buf, '*') != NULL) /* No multiple wildcards */ return (-3); if (pre == 0 && post == 0) { /* No wildcards, use VSL_Name2Tag */ i = VSL_Name2Tag(buf, l); if (i < 0) return (i); if (func != NULL) (func)(i, priv); return (1); } r = 0; for (i = 0; i < SLT__MAX; i++) { if (VSL_tags[i] == NULL) continue; l2 = strlen(VSL_tags[i]); if (l2 < l) continue; if (pre) { /* Prefix wildcard match */ if (strcasecmp(buf, VSL_tags[i] + l2 - l)) continue; } else { /* Postfix wildcard match */ if (strncasecmp(buf, VSL_tags[i], l)) continue; } if (func != NULL) (func)(i, priv); r++; } if (r == 0) return (-1); return (r); }