xref: /openbmc/qemu/trace/control.c (revision ddde8acc)
123d15e86SLluís /*
223d15e86SLluís  * Interface for configuring and controlling the state of tracing events.
323d15e86SLluís  *
423d15e86SLluís  * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
523d15e86SLluís  *
623d15e86SLluís  * This work is licensed under the terms of the GNU GPL, version 2.  See
723d15e86SLluís  * the COPYING file in the top-level directory.
823d15e86SLluís  */
923d15e86SLluís 
1023d15e86SLluís #include "trace/control.h"
1123d15e86SLluís 
1223d15e86SLluís 
1323d15e86SLluís void trace_backend_init_events(const char *fname)
1423d15e86SLluís {
15*ddde8accSGerd Hoffmann     int ret;
16*ddde8accSGerd Hoffmann 
1723d15e86SLluís     if (fname == NULL) {
1823d15e86SLluís         return;
1923d15e86SLluís     }
2023d15e86SLluís 
2123d15e86SLluís     FILE *fp = fopen(fname, "r");
2223d15e86SLluís     if (!fp) {
2323d15e86SLluís         fprintf(stderr, "error: could not open trace events file '%s': %s\n",
2423d15e86SLluís                 fname, strerror(errno));
2523d15e86SLluís         exit(1);
2623d15e86SLluís     }
2723d15e86SLluís     char line_buf[1024];
2823d15e86SLluís     while (fgets(line_buf, sizeof(line_buf), fp)) {
2923d15e86SLluís         size_t len = strlen(line_buf);
3023d15e86SLluís         if (len > 1) {              /* skip empty lines */
3123d15e86SLluís             line_buf[len - 1] = '\0';
32794b1f96SAlexey Kardashevskiy             if ('#' == line_buf[0]) { /* skip commented lines */
33794b1f96SAlexey Kardashevskiy                 continue;
34794b1f96SAlexey Kardashevskiy             }
35*ddde8accSGerd Hoffmann             if ('-' == line_buf[0]) {
36*ddde8accSGerd Hoffmann                 ret = trace_event_set_state(line_buf+1, false);
37*ddde8accSGerd Hoffmann             } else {
38*ddde8accSGerd Hoffmann                 ret = trace_event_set_state(line_buf, true);
39*ddde8accSGerd Hoffmann             }
40*ddde8accSGerd Hoffmann             if (!ret) {
4123d15e86SLluís                 fprintf(stderr,
4223d15e86SLluís                         "error: trace event '%s' does not exist\n", line_buf);
4323d15e86SLluís                 exit(1);
4423d15e86SLluís             }
4523d15e86SLluís         }
4623d15e86SLluís     }
4723d15e86SLluís     if (fclose(fp) != 0) {
4823d15e86SLluís         fprintf(stderr, "error: closing file '%s': %s\n",
4923d15e86SLluís                 fname, strerror(errno));
5023d15e86SLluís         exit(1);
5123d15e86SLluís     }
5223d15e86SLluís }
53