aboutsummaryrefslogtreecommitdiff
path: root/trace/control.c
blob: be05efb99b847bcd479892923ab643bf71f21ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Interface for configuring and controlling the state of tracing events.
 *
 * Copyright (C) 2011 LluĂ­s Vilanova <vilanova@ac.upc.edu>
 *
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 * the COPYING file in the top-level directory.
 */

#include "trace/control.h"


void trace_backend_init_events(const char *fname)
{
    int ret;

    if (fname == NULL) {
        return;
    }

    FILE *fp = fopen(fname, "r");
    if (!fp) {
        fprintf(stderr, "error: could not open trace events file '%s': %s\n",
                fname, strerror(errno));
        exit(1);
    }
    char line_buf[1024];
    while (fgets(line_buf, sizeof(line_buf), fp)) {
        size_t len = strlen(line_buf);
        if (len > 1) {              /* skip empty lines */
            line_buf[len - 1] = '\0';
            if ('#' == line_buf[0]) { /* skip commented lines */
                continue;
            }
            if ('-' == line_buf[0]) {
                ret = trace_event_set_state(line_buf+1, false);
            } else {
                ret = trace_event_set_state(line_buf, true);
            }
            if (!ret) {
                fprintf(stderr,
                        "error: trace event '%s' does not exist\n", line_buf);
                exit(1);
            }
        }
    }
    if (fclose(fp) != 0) {
        fprintf(stderr, "error: closing file '%s': %s\n",
                fname, strerror(errno));
        exit(1);
    }
}