#include #include #include #include #include #include #include #include static char *argv0; static char *get_this_name(void) { static char *this_name; char *arg; char *p; if (this_name) return this_name; arg = argv0; p = arg+strlen(arg); while (p >= arg && *p != '/') p--; p++; this_name = p; return p; } static void usage(void) { char *p = get_this_name(); printf("usage: %s exec\n" "\n",p); exit(-1); } static void __vdie(const char *fmt, va_list ap, int err) { int ret = errno; char *p = get_this_name(); if (err && errno) perror(p); else ret = -1; fprintf(stderr, " "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); exit(ret); } void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); __vdie(fmt, ap, 0); va_end(ap); } void pdie(const char *fmt, ...) { va_list ap; va_start(ap, fmt); __vdie(fmt, ap, 1); va_end(ap); } int main (int argc, char **argv) { struct tep_handle *tep; off_t size; char *buf; int ret; argv0 = argv[0]; if (argc < 2) usage(); tep = tep_alloc(); if (!tep) pdie("tep_alloc"); tep_set_loglevel(TEP_LOG_ALL); ret = open(argv[1], O_RDONLY); if (ret < 0) pdie(argv[1]); size = lseek(ret, 0, SEEK_END); if (size < 0) pdie("lseek"); lseek(ret, 0, SEEK_SET); buf = malloc(size); if (!buf) pdie("malloc"); size = read(ret, buf, size); if (size < 0) pdie("read"); close(ret); ret = tep_parse_event(tep, buf, size, "sys"); if (ret < 0) pdie("tep_parse_event"); free(buf); tep_free(tep); return 0; }