[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-edac
Subject: [PATCH 05/10] rasd: parse config file for events to enable
From: Jean Pihet <jean.pihet () linaro ! org>
Date: 2014-09-25 9:55:56
Message-ID: 1411638961-8112-5-git-send-email-jean.pihet () linaro ! org
[Download RAW message or body]
The file 'rasd.cfg' is parsed for options:
.the events to enable are stored line by line. The format is 'sys:name'.
Warning: an empty line is considered as an event line.
.a line starting with '#' is a comment line and is ignored,
Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
---
src/rasd.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 49 insertions(+), 11 deletions(-)
diff --git a/src/rasd.c b/src/rasd.c
index 2d85989..537cb65 100644
--- a/src/rasd.c
+++ b/src/rasd.c
@@ -7,9 +7,10 @@
#define EVENT_STR_MAX_LENGTH 1024
#define SYS_NAME_SEPARATOR ":"
+#define RASD_CFG_FILE "rasd.cfg"
unsigned int page_size;
-struct perf_evlist evlist;
+struct perf_evlist *evlist;
struct perf_rasd rasd;
/*
@@ -69,7 +70,7 @@ static int add_tp_event(char *event_str)
case 0:
/* Add the event to the lists of events */
list_add_tail(&r_ev->node, &rasd.event_entries);
- list_add_tail(&tp->node, &evlist.entries);
+ list_add_tail(&tp->node, &evlist->entries);
break;
case -ENOMEM:
err("cannot allocate event path");
@@ -92,10 +93,42 @@ static int add_tp_event(char *event_str)
return ret;
}
+/*
+ * Read the config file for events to enable
+ */
+static int read_config_file(void)
+{
+ FILE *file;
+ char *event_str;
+ int ret = 0;
+
+ file = fopen(RASD_CFG_FILE, "r");
+ if (!file)
+ return -ENODEV;
+
+ event_str = malloc(EVENT_STR_MAX_LENGTH);
+ if (!event_str)
+ return -ENOMEM;
+
+ /* Read config file, line by line */
+ while (fgets(event_str, EVENT_STR_MAX_LENGTH, file))
+ /* If line starts with '#', ignore the line */
+ if (event_str[0] != '#')
+ /* Parse the specified event */
+ add_tp_event(event_str);
+
+ if (ferror(file))
+ ret = -EINVAL;
+
+ free(event_str);
+ fclose(file);
+
+ return ret;
+}
+
int main()
{
struct perf_evsel *c;
- char *ev_name = strdup("mce:mce_record");
page_size = sysconf(_SC_PAGE_SIZE);
@@ -105,26 +138,31 @@ int main()
if (!debugfs_mount(NULL))
err("mounting debugfs");
- INIT_LIST_HEAD(&evlist.entries);
INIT_LIST_HEAD(&rasd.event_entries);
- /* Add event from the name string */
- add_tp_event(ev_name);
+ /* Initialize evlist */
+ evlist = perf_evlist__new();
+ if (!evlist)
+ err("allocating evlist");
+
+ /* Read config file */
+ if (read_config_file())
+ err("error reading config file");
- evlist__for_each(&evlist, c) {
+ evlist__for_each(evlist, c) {
/*
* On all online cpus by default.
*/
if (perf_evsel__open(c, cpu_map__new(NULL), NULL) < 0)
- err("opening counter");
+ err("opening tracepoint, are you root?");
}
- if (perf_evlist__mmap(&evlist, 4 /* opts->mmap_pages */, false) < 0)
- err("Failed to mmap with %d (%s)\n", errno, strerror(errno));
+ if (perf_evlist__mmap(evlist, 4 /* opts->mmap_pages */, false) < 0)
+ err("Failed to mmap with %d (%s)\n", errno, strerror(errno));
/* mmap it and all that, consume it */
- perf_evlist__delete(&evlist);
+ perf_evlist__delete(evlist);
return 0;
}
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-edac" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic