Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
Created January 13, 2016 20:05
Show Gist options
  • Save gregoryyoung/a7486d8ae32918a52415 to your computer and use it in GitHub Desktop.
Save gregoryyoung/a7486d8ae32918a52415 to your computer and use it in GitHub Desktop.
void
get_config (MonoProfiler *profiler, const char *desc) {
const char *p;
const char *opt;
p = desc;
if (strncmp (p, "peye", 4))
usage (1);
p += 4;
if (*p == ':')
p++;
for (; *p; p = opt) {
char *val;
if (*p == ',') {
opt = p + 1;
continue;
}
if ((opt = match_option (p, "help", NULL)) != p) {
usage (1);
}
if ((opt = match_option (p, "debug", NULL)) != p) {
profiler->debug = TRUE;
continue;
}
if ((opt = match_option (p, "whatif", NULL)) != p) {
profiler->whatif = TRUE;
continue;
}
if ((opt = match_option (p, "nogettersetter", NULL)) != p) {
profiler->no_getters = TRUE;
continue;
}
if ((opt = match_option (p, "startenabled", NULL)) != p) {
profiler->method_tracking_enabled = TRUE;
profiler->allocation_tracking_enabled = TRUE;
profiler->gc_tracking_enabled = TRUE;
profiler->exception_tracking_enabled = TRUE;
continue;
}
if ((opt = match_option (p, "mtenabled", NULL)) != p) {
profiler->method_tracking_enabled = TRUE;
continue;
}
if ((opt = match_option (p, "allocenabled", NULL)) != p) {
profiler->allocation_tracking_enabled = TRUE;
continue;
}
if ((opt = match_option (p, "gcenabled", NULL)) != p) {
profiler->gc_tracking_enabled = TRUE;
continue;
}
if ((opt = match_option (p, "excenabled", NULL)) != p) {
profiler->exception_tracking_enabled = TRUE;
continue;
}
if ((opt = match_option (p, "debugenterleave", NULL)) != p) {
profiler->debugenterleave = TRUE;
profiler->debug = TRUE;
continue;
}
if ((opt = match_option (p, "debugallocs", NULL)) != p) {
profiler->debugallocs = TRUE;
profiler->debug = TRUE;
continue;
}
if ((opt = match_option (p, "nodefaultfilter", NULL)) != p) {
profiler->nodefaultfilter = TRUE;
continue;
}
if ((opt = match_option (p, "nocache", NULL)) != p) {
profiler->cache = FALSE;
continue;
}
if ((opt = match_option (p, "ip", &val)) != p) {
profiler->address = strdup(val);
free (val);
continue;
}
if ((opt = match_option (p, "exclude", &val)) != p) {
IncludeExcludeItem *last = profiler->excludes;
IncludeExcludeItem *first = NULL;
char *str = strdup(val);
char *token;
while ((token = strsep(&val, "/"))) {
IncludeExcludeItem *i = (IncludeExcludeItem*) malloc(sizeof(IncludeExcludeItem));
i->pattern = token;
i->len = strlen(token);
i->next = NULL;
if(first == NULL) first = i;
if(last != NULL) last->next = i;
last = i;
}
free (str);
profiler->excludes=first;
continue;
}
if ((opt = match_option (p, "include", &val)) != p) {
IncludeExcludeItem *last = profiler->includes;
IncludeExcludeItem *first = NULL;
char *str = strdup(val);
char *token;
while ((token = strsep(&val, "/"))) {
IncludeExcludeItem *i = (IncludeExcludeItem*) malloc(sizeof(IncludeExcludeItem));
i->pattern = token;
i->next = NULL;
i->len = strlen(token);
if(first == NULL) first = i;
if(last != NULL) last->next = i;
last = i;
}
free (str);
profiler->includes=first;
continue;
}
if ((opt = match_option (p, "port", &val)) != p) {
profiler->port = atoi(val);
free (val);
continue;
}
if ((opt = match_option (p, "samplems", &val)) != p) {
profiler->sample_ms = atoi(val);
free (val);
continue;
}
if ((opt = match_option (p, "self", &val)) != p) {
profiler->cache = FALSE;
profiler->self = TRUE;
continue;
}
if ((opt = match_option (p, "mode", &val)) != p) {
if (strcmp (val, "connect") == 0) {
profiler->connect = TRUE;
} else if (strcmp (val, "listen") == 0) {
profiler->connect = FALSE;
} else {
usage (1);
}
free (val);
continue;
}
if (opt == p) {
usage (0);
exit (0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment