static void create_and_free_provider(int argc, char **argv) { usdt_provider_t *provider; usdt_probedef_t *probedef; if ((provider = usdt_create_provider("testlibusdt", "modname")) == NULL) { fprintf(stderr, "unable to create provider\n"); exit (1); } if ((probedef = usdt_create_probe((const char *)argv[1], (const char *)argv[2], (argc-3), (const char **)&argv[3])) == NULL) { fprintf(stderr, "unable to create probe\n"); exit (1); } usdt_provider_add_probe(provider, probedef); if ((usdt_provider_enable(provider)) < 0) { fprintf(stderr, "unable to enable provider: %s\n", usdt_errstr(provider)); exit (1); } if ((usdt_provider_disable(provider)) < 0) { fprintf(stderr, "unable to disable provider: %s\n", usdt_errstr(provider)); exit (1); } usdt_probe_release(probedef); usdt_provider_free(provider); }
/** * USDT::Provider#probe(func, name, pargs*) */ static VALUE provider_probe(int argc, VALUE *argv, VALUE self) { const char *func = rb_id2name(rb_to_id(argv[0])); const char *name = rb_id2name(rb_to_id(argv[1])); const char *types[USDT_ARG_MAX]; size_t i, pargc = 0; size_t t_int = rb_intern("integer"); size_t t_str = rb_intern("string"); for (i = 0; i < USDT_ARG_MAX; i++) { if (i < argc - 2) { Check_Type(argv[i+2], T_SYMBOL); if (t_int == rb_to_id(argv[i+2])) { types[i] = "int"; pargc++; } else if (t_str == rb_to_id(argv[i+2])) { types[i] = "char *"; pargc++; } else { types[i] = NULL; } } else { types[i] = NULL; } } usdt_provider_t *provider = DATA_PTR(self); usdt_probedef_t **probe; probe = ALLOC(usdt_probedef_t *); *probe = usdt_create_probe(func, name, pargc, types); if ((usdt_provider_add_probe(provider, *probe) == 0)) { VALUE rbProbe = Data_Wrap_Struct(USDT_Probe, NULL, free, probe); return rbProbe; } else { rb_raise(USDT_Error, "%s", usdt_errstr(provider)); } }