control.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Interface for configuring and controlling the state of tracing events.
  3. *
  4. * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2. See
  7. * the COPYING file in the top-level directory.
  8. */
  9. #include "trace/control.h"
  10. void trace_backend_init_events(const char *fname)
  11. {
  12. if (fname == NULL) {
  13. return;
  14. }
  15. FILE *fp = fopen(fname, "r");
  16. if (!fp) {
  17. fprintf(stderr, "error: could not open trace events file '%s': %s\n",
  18. fname, strerror(errno));
  19. exit(1);
  20. }
  21. char line_buf[1024];
  22. while (fgets(line_buf, sizeof(line_buf), fp)) {
  23. size_t len = strlen(line_buf);
  24. if (len > 1) { /* skip empty lines */
  25. line_buf[len - 1] = '\0';
  26. if ('#' == line_buf[0]) { /* skip commented lines */
  27. continue;
  28. }
  29. if (!trace_event_set_state(line_buf, true)) {
  30. fprintf(stderr,
  31. "error: trace event '%s' does not exist\n", line_buf);
  32. exit(1);
  33. }
  34. }
  35. }
  36. if (fclose(fp) != 0) {
  37. fprintf(stderr, "error: closing file '%s': %s\n",
  38. fname, strerror(errno));
  39. exit(1);
  40. }
  41. }