Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_usdt.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2012, Chris Andrews. All rights reserved.
  3. */
  4. #include "usdt.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. static void
  9. fire_probe(usdt_probedef_t *probedef, int argc, void **argv)
  10. {
  11. if (usdt_is_enabled(probedef->probe))
  12. usdt_fire_probe(probedef->probe, argc, argv);
  13. }
  14. int main(int argc, char **argv) {
  15. usdt_provider_t *provider;
  16. usdt_probedef_t *probedef;
  17. char char_argv[USDT_ARG_MAX];
  18. int int_argv[USDT_ARG_MAX * 2];
  19. void **args = NULL;
  20. int i;
  21. char buf[255];
  22. for (i = 0; i < USDT_ARG_MAX; i++)
  23. int_argv[i] = i + 1;
  24. for (i = 0; i < USDT_ARG_MAX; i++)
  25. char_argv[i] = (char) i + 65;
  26. if (argc < 3) {
  27. fprintf(stderr, "usage: %s func name [types ...]\n", argv[0]);
  28. return(1);
  29. }
  30. if (argc > 3) {
  31. args = malloc((argc-3) * sizeof(void *));
  32. }
  33. for (i = 0; i < USDT_ARG_MAX; i++) {
  34. if (argv[i+3] != NULL && i+3 < argc) {
  35. if (strncmp("c", argv[i+3], 1) == 0) {
  36. args[i] = (void *)strndup(&char_argv[i], 1);
  37. argv[i+3] = strdup("char *");
  38. }
  39. if (strncmp("i", argv[i+3], 1) == 0) {
  40. args[i] = (void *)(long)int_argv[i];
  41. argv[i+3] = strdup("int");
  42. }
  43. }
  44. }
  45. if ((provider = usdt_create_provider("testlibusdt", "modname")) == NULL) {
  46. fprintf(stderr, "unable to create provider\n");
  47. exit (1);
  48. }
  49. if ((probedef = usdt_create_probe((const char *)argv[1],
  50. (const char *)argv[2],
  51. (argc-3), (const char **)&argv[3])) == NULL)
  52. {
  53. fprintf(stderr, "unable to create probe\n");
  54. exit (1);
  55. }
  56. usdt_provider_add_probe(provider, probedef);
  57. if ((usdt_provider_enable(provider)) < 0) {
  58. fprintf(stderr, "unable to enable provider: %s\n", usdt_errstr(provider));
  59. exit (1);
  60. }
  61. fprintf(stdout, "enabled\n");
  62. fflush(stdout);
  63. fgets(buf, 255, stdin);
  64. fire_probe(probedef, (argc-3), (void **)args);
  65. usdt_probe_release(probedef);
  66. if ((usdt_provider_disable(provider)) < 0) {
  67. fprintf(stderr, "unable to disable provider: %s\n", usdt_errstr(provider));
  68. exit (1);
  69. }
  70. usdt_provider_free(provider);
  71. return 0;
  72. }