blob: 9147d65036858e4d0a8e3934e1808f630450a691 [file] [log] [blame]
#include "cpumap.h"
#include "evsel.h"
#include "evlist.h"
#include "ras.h"
#include "debugfs.h"
#define EVENT_STR_MAX_LENGTH 1024
#define SYS_NAME_SEPARATOR ":"
unsigned int page_size;
struct perf_evlist evlist;
struct perf_rasd rasd;
/*
* Extract the event subsystem and event names from the command
* line argument. The syntax is 'sys:name'.
*/
static int extract_sys_name(char **str, char **sys, char **name)
{
/* Look for the sys:name separator */
char *sys_ptr = strsep(str, SYS_NAME_SEPARATOR);
if (!*str || !sys_ptr)
return -1;
/* Is there something after the separator? */
if (!strlen(*str))
return -1;
/* Alloc and fill the sys part */
*sys = strndup(sys_ptr, EVENT_STR_MAX_LENGTH);
/*
* Look for the newline in the rest of the string.
* If found alloc and fill the name part.
*/
*name = strndup(strsep(str, "\n\r"), EVENT_STR_MAX_LENGTH);
return 0;
}
/* Add the requested tracepoint event to evlist */
static int add_tp_event(char *event_str)
{
struct perf_evsel *tp;
char **str = &event_str;
int ret;
if (extract_sys_name(str, &rasd.sys, &rasd.name))
err("invalid event specified, syntax is sys:name");
/* Initialize tracepoint evsel */
tp = perf_evsel__newtp_idx(rasd.sys, rasd.name, 0);
if (!tp)
err("init tracepoint evsel");
/* Add the event to the lists of events */
list_add_tail(&tp->node, &evlist.entries);
return ret;
}
int main()
{
struct perf_evsel *c;
char *ev_name = strdup("mce:mce_record");
page_size = sysconf(_SC_PAGE_SIZE);
/*
* Mount debugfs. The basepath is in debugfs_mountpoint
*/
if (!debugfs_mount(NULL))
err("mounting debugfs");
INIT_LIST_HEAD(&evlist.entries);
/* Add event from the name string */
add_tp_event(ev_name);
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");
}
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);
free(rasd.name);
free(rasd.sys);
return 0;
}