2 * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License (not later!)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 * The parts for function graph printing was taken and modified from the
22 * Linux Kernel that were written by Frederic Weisbecker.
33 #include "trace-event.h"
35 int header_page_ts_offset;
36 int header_page_ts_size;
37 int header_page_size_offset;
38 int header_page_size_size;
39 int header_page_data_offset;
40 int header_page_data_size;
42 static char *input_buf;
43 static unsigned long long input_buf_ptr;
44 static unsigned long long input_buf_siz;
49 static void init_input_buf(char *buf, unsigned long long size)
61 static struct cmdline *cmdlines;
62 static int cmdline_count;
64 static int cmdline_cmp(const void *a, const void *b)
66 const struct cmdline *ca = a;
67 const struct cmdline *cb = b;
69 if (ca->pid < cb->pid)
71 if (ca->pid > cb->pid)
77 void parse_cmdlines(char *file, int size __unused)
80 struct cmdline_list *next;
83 } *list = NULL, *item;
88 line = strtok_r(file, "\n", &next);
90 item = malloc_or_die(sizeof(*item));
91 sscanf(line, "%d %as", &item->pid,
92 (float *)&item->comm); /* workaround gcc warning */
95 line = strtok_r(NULL, "\n", &next);
99 cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
103 cmdlines[i].pid = list->pid;
104 cmdlines[i].comm = list->comm;
111 qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
114 static struct func_map {
115 unsigned long long addr;
119 static unsigned int func_count;
121 static int func_cmp(const void *a, const void *b)
123 const struct func_map *fa = a;
124 const struct func_map *fb = b;
126 if (fa->addr < fb->addr)
128 if (fa->addr > fb->addr)
134 void parse_proc_kallsyms(char *file, unsigned int size __unused)
137 struct func_list *next;
138 unsigned long long addr;
141 } *list = NULL, *item;
149 line = strtok_r(file, "\n", &next);
151 item = malloc_or_die(sizeof(*item));
153 ret = sscanf(line, "%as %c %as\t[%as",
154 (float *)&addr_str, /* workaround gcc warning */
156 (float *)&item->func,
157 (float *)&item->mod);
158 item->addr = strtoull(addr_str, NULL, 16);
161 /* truncate the extra ']' */
163 item->mod[strlen(item->mod) - 1] = 0;
168 line = strtok_r(NULL, "\n", &next);
172 func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
176 func_list[i].func = list->func;
177 func_list[i].addr = list->addr;
178 func_list[i].mod = list->mod;
185 qsort(func_list, func_count, sizeof(*func_list), func_cmp);
188 * Add a special record at the end.
190 func_list[func_count].func = NULL;
191 func_list[func_count].addr = 0;
192 func_list[func_count].mod = NULL;
196 * We are searching for a record in between, not an exact
199 static int func_bcmp(const void *a, const void *b)
201 const struct func_map *fa = a;
202 const struct func_map *fb = b;
204 if ((fa->addr == fb->addr) ||
206 (fa->addr > fb->addr &&
207 fa->addr < (fb+1)->addr))
210 if (fa->addr < fb->addr)
216 static struct func_map *find_func(unsigned long long addr)
218 struct func_map *func;
223 func = bsearch(&key, func_list, func_count, sizeof(*func_list),
229 void print_funcs(void)
233 for (i = 0; i < (int)func_count; i++) {
237 if (func_list[i].mod)
238 printf(" [%s]\n", func_list[i].mod);
244 static struct printk_map {
245 unsigned long long addr;
248 static unsigned int printk_count;
250 static int printk_cmp(const void *a, const void *b)
252 const struct func_map *fa = a;
253 const struct func_map *fb = b;
255 if (fa->addr < fb->addr)
257 if (fa->addr > fb->addr)
263 static struct printk_map *find_printk(unsigned long long addr)
265 struct printk_map *printk;
266 struct printk_map key;
270 printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
276 void parse_ftrace_printk(char *file, unsigned int size __unused)
279 struct printk_list *next;
280 unsigned long long addr;
282 } *list = NULL, *item;
289 line = strtok_r(file, "\n", &next);
291 item = malloc_or_die(sizeof(*item));
292 ret = sscanf(line, "%as : %as",
293 (float *)&addr_str, /* workaround gcc warning */
294 (float *)&item->printk);
295 item->addr = strtoull(addr_str, NULL, 16);
300 line = strtok_r(NULL, "\n", &next);
304 printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
308 printk_list[i].printk = list->printk;
309 printk_list[i].addr = list->addr;
316 qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
319 void print_printk(void)
323 for (i = 0; i < (int)printk_count; i++) {
324 printf("%016llx %s\n",
326 printk_list[i].printk);
330 static struct event *alloc_event(void)
334 event = malloc_or_die(sizeof(*event));
335 memset(event, 0, sizeof(*event));
352 static struct event *event_list;
354 static void add_event(struct event *event)
356 event->next = event_list;
360 static int event_item_type(enum event_type type)
363 case EVENT_ITEM ... EVENT_SQUOTE:
365 case EVENT_ERROR ... EVENT_DELIM:
371 static void free_arg(struct print_arg *arg)
379 free(arg->atom.atom);
382 case PRINT_FIELD ... PRINT_OP:
391 static enum event_type get_type(int ch)
394 return EVENT_NEWLINE;
397 if (isalnum(ch) || ch == '_')
405 if (ch == '(' || ch == ')' || ch == ',')
411 static int __read_char(void)
413 if (input_buf_ptr >= input_buf_siz)
416 return input_buf[input_buf_ptr++];
419 static int __peek_char(void)
421 if (input_buf_ptr >= input_buf_siz)
424 return input_buf[input_buf_ptr];
427 static enum event_type __read_token(char **tok)
430 int ch, last_ch, quote_ch, next_ch;
433 enum event_type type;
443 if (type == EVENT_NONE)
451 *tok = malloc_or_die(2);
459 next_ch = __peek_char();
460 if (next_ch == '>') {
461 buf[i++] = __read_char();
474 buf[i++] = __read_char();
486 default: /* what should we do instead? */
496 buf[i++] = __read_char();
501 /* don't keep quotes */
506 if (i == (BUFSIZ - 1)) {
509 *tok = realloc(*tok, tok_size + BUFSIZ);
524 } while (ch != quote_ch && last_ch != '\\');
525 /* remove the last quote */
529 case EVENT_ERROR ... EVENT_SPACE:
535 while (get_type(__peek_char()) == type) {
536 if (i == (BUFSIZ - 1)) {
539 *tok = realloc(*tok, tok_size + BUFSIZ);
558 *tok = realloc(*tok, tok_size + i);
570 static void free_token(char *tok)
576 static enum event_type read_token(char **tok)
578 enum event_type type;
581 type = __read_token(tok);
582 if (type != EVENT_SPACE)
593 static enum event_type read_token_item(char **tok)
595 enum event_type type;
598 type = __read_token(tok);
599 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
609 static int test_type(enum event_type type, enum event_type expect)
611 if (type != expect) {
612 die("Error: expected type %d but read %d",
619 static int test_type_token(enum event_type type, char *token,
620 enum event_type expect, char *expect_tok)
622 if (type != expect) {
623 die("Error: expected type %d but read %d",
628 if (strcmp(token, expect_tok) != 0) {
629 die("Error: expected '%s' but read '%s'",
636 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
638 enum event_type type;
641 type = read_token(tok);
643 type = read_token_item(tok);
644 return test_type(type, expect);
647 static int read_expect_type(enum event_type expect, char **tok)
649 return __read_expect_type(expect, tok, 1);
652 static int __read_expected(enum event_type expect, char *str, int newline_ok)
654 enum event_type type;
659 type = read_token(&token);
661 type = read_token_item(&token);
663 ret = test_type_token(type, token, expect, str);
670 static int read_expected(enum event_type expect, char *str)
672 return __read_expected(expect, str, 1);
675 static int read_expected_item(enum event_type expect, char *str)
677 return __read_expected(expect, str, 0);
680 static char *event_read_name(void)
684 if (read_expected(EVENT_ITEM, (char *)"name") < 0)
687 if (read_expected(EVENT_OP, (char *)":") < 0)
690 if (read_expect_type(EVENT_ITEM, &token) < 0)
700 static int event_read_id(void)
705 if (read_expected_item(EVENT_ITEM, (char *)"ID") < 0)
708 if (read_expected(EVENT_OP, (char *)":") < 0)
711 if (read_expect_type(EVENT_ITEM, &token) < 0)
714 id = strtoul(token, NULL, 0);
723 static int event_read_fields(struct event *event, struct format_field **fields)
725 struct format_field *field = NULL;
726 enum event_type type;
732 type = read_token(&token);
733 if (type == EVENT_NEWLINE) {
740 if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
744 type = read_token(&token);
746 * The ftrace fields may still use the "special" name.
749 if (event->flags & EVENT_FL_ISFTRACE &&
750 type == EVENT_ITEM && strcmp(token, "special") == 0) {
752 type = read_token(&token);
755 if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
758 if (read_expect_type(EVENT_ITEM, &token) < 0)
763 field = malloc_or_die(sizeof(*field));
764 memset(field, 0, sizeof(*field));
766 /* read the rest of the type */
768 type = read_token(&token);
769 if (type == EVENT_ITEM ||
770 (type == EVENT_OP && strcmp(token, "*") == 0) ||
772 * Some of the ftrace fields are broken and have
773 * an illegal "." in them.
775 (event->flags & EVENT_FL_ISFTRACE &&
776 type == EVENT_OP && strcmp(token, ".") == 0)) {
778 if (strcmp(token, "*") == 0)
779 field->flags |= FIELD_IS_POINTER;
782 field->type = realloc(field->type,
783 strlen(field->type) +
784 strlen(last_token) + 2);
785 strcat(field->type, " ");
786 strcat(field->type, last_token);
788 field->type = last_token;
797 die("no type found");
800 field->name = last_token;
802 if (test_type(type, EVENT_OP))
805 if (strcmp(token, "[") == 0) {
806 enum event_type last_type = type;
807 char *brackets = token;
810 field->flags |= FIELD_IS_ARRAY;
812 type = read_token(&token);
813 while (strcmp(token, "]") != 0) {
814 if (last_type == EVENT_ITEM &&
821 brackets = realloc(brackets,
823 strlen(token) + len);
825 strcat(brackets, " ");
826 strcat(brackets, token);
828 type = read_token(&token);
829 if (type == EVENT_NONE) {
830 die("failed to find token");
837 brackets = realloc(brackets, strlen(brackets) + 2);
838 strcat(brackets, "]");
840 /* add brackets to type */
842 type = read_token(&token);
844 * If the next token is not an OP, then it is of
845 * the format: type [] item;
847 if (type == EVENT_ITEM) {
848 field->type = realloc(field->type,
849 strlen(field->type) +
850 strlen(field->name) +
851 strlen(brackets) + 2);
852 strcat(field->type, " ");
853 strcat(field->type, field->name);
854 free_token(field->name);
855 strcat(field->type, brackets);
857 type = read_token(&token);
859 field->type = realloc(field->type,
860 strlen(field->type) +
861 strlen(brackets) + 1);
862 strcat(field->type, brackets);
867 if (test_type_token(type, token, EVENT_OP, (char *)";"))
871 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
874 if (read_expected(EVENT_OP, (char *)":") < 0)
877 if (read_expect_type(EVENT_ITEM, &token))
879 field->offset = strtoul(token, NULL, 0);
882 if (read_expected(EVENT_OP, (char *)";") < 0)
885 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
888 if (read_expected(EVENT_OP, (char *)":") < 0)
891 if (read_expect_type(EVENT_ITEM, &token))
893 field->size = strtoul(token, NULL, 0);
896 if (read_expected(EVENT_OP, (char *)";") < 0)
899 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
904 fields = &field->next;
918 static int event_read_format(struct event *event)
923 if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
926 if (read_expected(EVENT_OP, (char *)":") < 0)
929 if (read_expect_type(EVENT_NEWLINE, &token))
933 ret = event_read_fields(event, &event->format.common_fields);
936 event->format.nr_common = ret;
938 ret = event_read_fields(event, &event->format.fields);
941 event->format.nr_fields = ret;
951 process_arg_token(struct event *event, struct print_arg *arg,
952 char **tok, enum event_type type);
954 static enum event_type
955 process_arg(struct event *event, struct print_arg *arg, char **tok)
957 enum event_type type;
960 type = read_token(&token);
963 return process_arg_token(event, arg, tok, type);
966 static enum event_type
967 process_cond(struct event *event, struct print_arg *top, char **tok)
969 struct print_arg *arg, *left, *right;
970 enum event_type type;
973 arg = malloc_or_die(sizeof(*arg));
974 memset(arg, 0, sizeof(*arg));
976 left = malloc_or_die(sizeof(*left));
978 right = malloc_or_die(sizeof(*right));
980 arg->type = PRINT_OP;
982 arg->op.right = right;
985 type = process_arg(event, left, &token);
986 if (test_type_token(type, token, EVENT_OP, (char *)":"))
991 type = process_arg(event, right, &token);
1006 static int get_op_prio(char *op)
1017 /* '>>' and '<<' are 8 */
1021 /* '==' and '!=' are 10 */
1031 die("unknown op '%c'", op[0]);
1035 if (strcmp(op, "++") == 0 ||
1036 strcmp(op, "--") == 0) {
1038 } else if (strcmp(op, ">>") == 0 ||
1039 strcmp(op, "<<") == 0) {
1041 } else if (strcmp(op, ">=") == 0 ||
1042 strcmp(op, "<=") == 0) {
1044 } else if (strcmp(op, "==") == 0 ||
1045 strcmp(op, "!=") == 0) {
1047 } else if (strcmp(op, "&&") == 0) {
1049 } else if (strcmp(op, "||") == 0) {
1052 die("unknown op '%s'", op);
1058 static void set_op_prio(struct print_arg *arg)
1061 /* single ops are the greatest */
1062 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1067 arg->op.prio = get_op_prio(arg->op.op);
1070 static enum event_type
1071 process_op(struct event *event, struct print_arg *arg, char **tok)
1073 struct print_arg *left, *right = NULL;
1074 enum event_type type;
1077 /* the op is passed in via tok */
1080 if (arg->type == PRINT_OP && !arg->op.left) {
1081 /* handle single op */
1083 die("bad op token %s", token);
1092 die("bad op token %s", token);
1096 /* make an empty left */
1097 left = malloc_or_die(sizeof(*left));
1098 left->type = PRINT_NULL;
1099 arg->op.left = left;
1101 right = malloc_or_die(sizeof(*right));
1102 arg->op.right = right;
1104 type = process_arg(event, right, tok);
1106 } else if (strcmp(token, "?") == 0) {
1108 left = malloc_or_die(sizeof(*left));
1109 /* copy the top arg to the left */
1112 arg->type = PRINT_OP;
1114 arg->op.left = left;
1117 type = process_cond(event, arg, tok);
1119 } else if (strcmp(token, ">>") == 0 ||
1120 strcmp(token, "<<") == 0 ||
1121 strcmp(token, "&") == 0 ||
1122 strcmp(token, "|") == 0 ||
1123 strcmp(token, "&&") == 0 ||
1124 strcmp(token, "||") == 0 ||
1125 strcmp(token, "-") == 0 ||
1126 strcmp(token, "+") == 0 ||
1127 strcmp(token, "*") == 0 ||
1128 strcmp(token, "^") == 0 ||
1129 strcmp(token, "/") == 0 ||
1130 strcmp(token, "==") == 0 ||
1131 strcmp(token, "!=") == 0) {
1133 left = malloc_or_die(sizeof(*left));
1135 /* copy the top arg to the left */
1138 arg->type = PRINT_OP;
1140 arg->op.left = left;
1144 right = malloc_or_die(sizeof(*right));
1146 type = process_arg(event, right, tok);
1148 arg->op.right = right;
1151 die("unknown op '%s'", token);
1152 /* the arg is now the left side */
1157 if (type == EVENT_OP) {
1160 /* higher prios need to be closer to the root */
1161 prio = get_op_prio(*tok);
1163 if (prio > arg->op.prio)
1164 return process_op(event, arg, tok);
1166 return process_op(event, right, tok);
1172 static enum event_type
1173 process_entry(struct event *event __unused, struct print_arg *arg,
1176 enum event_type type;
1180 if (read_expected(EVENT_OP, (char *)"->") < 0)
1183 if (read_expect_type(EVENT_ITEM, &token) < 0)
1187 arg->type = PRINT_FIELD;
1188 arg->field.name = field;
1190 type = read_token(&token);
1200 static char *arg_eval (struct print_arg *arg);
1202 static long long arg_num_eval(struct print_arg *arg)
1204 long long left, right;
1207 switch (arg->type) {
1209 val = strtoll(arg->atom.atom, NULL, 0);
1212 val = arg_num_eval(arg->typecast.item);
1215 switch (arg->op.op[0]) {
1217 left = arg_num_eval(arg->op.left);
1218 right = arg_num_eval(arg->op.right);
1220 val = left || right;
1225 left = arg_num_eval(arg->op.left);
1226 right = arg_num_eval(arg->op.right);
1228 val = left && right;
1233 left = arg_num_eval(arg->op.left);
1234 right = arg_num_eval(arg->op.right);
1235 switch (arg->op.op[1]) {
1240 val = left << right;
1243 val = left <= right;
1246 die("unknown op '%s'", arg->op.op);
1250 left = arg_num_eval(arg->op.left);
1251 right = arg_num_eval(arg->op.right);
1252 switch (arg->op.op[1]) {
1257 val = left >> right;
1260 val = left >= right;
1263 die("unknown op '%s'", arg->op.op);
1267 left = arg_num_eval(arg->op.left);
1268 right = arg_num_eval(arg->op.right);
1270 if (arg->op.op[1] != '=')
1271 die("unknown op '%s'", arg->op.op);
1273 val = left == right;
1276 left = arg_num_eval(arg->op.left);
1277 right = arg_num_eval(arg->op.right);
1279 switch (arg->op.op[1]) {
1281 val = left != right;
1284 die("unknown op '%s'", arg->op.op);
1288 die("unknown op '%s'", arg->op.op);
1293 case PRINT_FIELD ... PRINT_SYMBOL:
1296 die("invalid eval type %d", arg->type);
1302 static char *arg_eval (struct print_arg *arg)
1305 static char buf[20];
1307 switch (arg->type) {
1309 return arg->atom.atom;
1311 return arg_eval(arg->typecast.item);
1313 val = arg_num_eval(arg);
1314 sprintf(buf, "%lld", val);
1318 case PRINT_FIELD ... PRINT_SYMBOL:
1321 die("invalid eval type %d", arg->type);
1328 static enum event_type
1329 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1331 enum event_type type;
1332 struct print_arg *arg = NULL;
1333 struct print_flag_sym *field;
1339 type = read_token_item(&token);
1340 if (test_type_token(type, token, EVENT_OP, (char *)"{"))
1343 arg = malloc_or_die(sizeof(*arg));
1346 type = process_arg(event, arg, &token);
1347 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1350 field = malloc_or_die(sizeof(*field));
1351 memset(field, 0, sizeof(field));
1353 value = arg_eval(arg);
1354 field->value = strdup(value);
1357 type = process_arg(event, arg, &token);
1358 if (test_type_token(type, token, EVENT_OP, (char *)"}"))
1361 value = arg_eval(arg);
1362 field->str = strdup(value);
1367 list = &field->next;
1370 type = read_token_item(&token);
1371 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1383 static enum event_type
1384 process_flags(struct event *event, struct print_arg *arg, char **tok)
1386 struct print_arg *field;
1387 enum event_type type;
1390 memset(arg, 0, sizeof(*arg));
1391 arg->type = PRINT_FLAGS;
1393 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1396 field = malloc_or_die(sizeof(*field));
1398 type = process_arg(event, field, &token);
1399 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1402 arg->flags.field = field;
1404 type = read_token_item(&token);
1405 if (event_item_type(type)) {
1406 arg->flags.delim = token;
1407 type = read_token_item(&token);
1410 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1413 type = process_fields(event, &arg->flags.flags, &token);
1414 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1418 type = read_token_item(tok);
1426 static enum event_type
1427 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1429 struct print_arg *field;
1430 enum event_type type;
1433 memset(arg, 0, sizeof(*arg));
1434 arg->type = PRINT_SYMBOL;
1436 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1439 field = malloc_or_die(sizeof(*field));
1441 type = process_arg(event, field, &token);
1442 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1445 arg->symbol.field = field;
1447 type = process_fields(event, &arg->symbol.symbols, &token);
1448 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1452 type = read_token_item(tok);
1460 static enum event_type
1461 process_paren(struct event *event, struct print_arg *arg, char **tok)
1463 struct print_arg *item_arg;
1464 enum event_type type;
1467 type = process_arg(event, arg, &token);
1469 if (type == EVENT_ERROR)
1472 if (type == EVENT_OP)
1473 type = process_op(event, arg, &token);
1475 if (type == EVENT_ERROR)
1478 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1484 type = read_token_item(&token);
1487 * If the next token is an item or another open paren, then
1488 * this was a typecast.
1490 if (event_item_type(type) ||
1491 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1493 /* make this a typecast and contine */
1495 /* prevous must be an atom */
1496 if (arg->type != PRINT_ATOM)
1497 die("previous needed to be PRINT_ATOM");
1499 item_arg = malloc_or_die(sizeof(*item_arg));
1501 arg->type = PRINT_TYPE;
1502 arg->typecast.type = arg->atom.atom;
1503 arg->typecast.item = item_arg;
1504 type = process_arg_token(event, item_arg, &token, type);
1513 static enum event_type
1514 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1516 enum event_type type;
1519 if (read_expected(EVENT_DELIM, (char *)"(") < 0)
1522 if (read_expect_type(EVENT_ITEM, &token) < 0)
1525 arg->type = PRINT_STRING;
1526 arg->string.string = token;
1528 if (read_expected(EVENT_DELIM, (char *)")") < 0)
1531 type = read_token(&token);
1541 process_arg_token(struct event *event, struct print_arg *arg,
1542 char **tok, enum event_type type)
1551 if (strcmp(token, "REC") == 0) {
1553 type = process_entry(event, arg, &token);
1554 } else if (strcmp(token, "__print_flags") == 0) {
1556 type = process_flags(event, arg, &token);
1557 } else if (strcmp(token, "__print_symbolic") == 0) {
1559 type = process_symbols(event, arg, &token);
1560 } else if (strcmp(token, "__get_str") == 0) {
1562 type = process_str(event, arg, &token);
1565 /* test the next token */
1566 type = read_token_item(&token);
1568 /* atoms can be more than one token long */
1569 while (type == EVENT_ITEM) {
1570 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1572 strcat(atom, token);
1574 type = read_token_item(&token);
1577 /* todo, test for function */
1579 arg->type = PRINT_ATOM;
1580 arg->atom.atom = atom;
1585 arg->type = PRINT_ATOM;
1586 arg->atom.atom = token;
1587 type = read_token_item(&token);
1590 if (strcmp(token, "(") == 0) {
1592 type = process_paren(event, arg, &token);
1596 /* handle single ops */
1597 arg->type = PRINT_OP;
1599 arg->op.left = NULL;
1600 type = process_op(event, arg, &token);
1604 case EVENT_ERROR ... EVENT_NEWLINE:
1606 die("unexpected type %d", type);
1613 static int event_read_print_args(struct event *event, struct print_arg **list)
1615 enum event_type type;
1616 struct print_arg *arg;
1621 arg = malloc_or_die(sizeof(*arg));
1622 memset(arg, 0, sizeof(*arg));
1624 type = process_arg(event, arg, &token);
1626 if (type == EVENT_ERROR) {
1634 if (type == EVENT_OP) {
1635 type = process_op(event, arg, &token);
1640 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1647 } while (type != EVENT_NONE);
1649 if (type != EVENT_NONE)
1655 static int event_read_print(struct event *event)
1657 enum event_type type;
1661 if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
1664 if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
1667 if (read_expected(EVENT_OP, (char *)":") < 0)
1670 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1673 event->print_fmt.format = token;
1674 event->print_fmt.args = NULL;
1676 /* ok to have no arg */
1677 type = read_token_item(&token);
1679 if (type == EVENT_NONE)
1682 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1687 ret = event_read_print_args(event, &event->print_fmt.args);
1698 static struct format_field *
1699 find_common_field(struct event *event, const char *name)
1701 struct format_field *format;
1703 for (format = event->format.common_fields;
1704 format; format = format->next) {
1705 if (strcmp(format->name, name) == 0)
1712 static struct format_field *
1713 find_field(struct event *event, const char *name)
1715 struct format_field *format;
1717 for (format = event->format.fields;
1718 format; format = format->next) {
1719 if (strcmp(format->name, name) == 0)
1726 static struct format_field *
1727 find_any_field(struct event *event, const char *name)
1729 struct format_field *format;
1731 format = find_common_field(event, name);
1734 return find_field(event, name);
1737 static unsigned long long read_size(void *ptr, int size)
1741 return *(unsigned char *)ptr;
1743 return data2host2(ptr);
1745 return data2host4(ptr);
1747 return data2host8(ptr);
1754 static int get_common_info(const char *type, int *offset, int *size)
1756 struct event *event;
1757 struct format_field *field;
1760 * All events should have the same common elements.
1761 * Pick any event to find where the type is;
1764 die("no event_list!");
1767 field = find_common_field(event, type);
1769 die("field '%s' not found", type);
1771 *offset = field->offset;
1772 *size = field->size;
1777 static int parse_common_type(void *data)
1779 static int type_offset;
1780 static int type_size;
1784 ret = get_common_info("common_type",
1790 return read_size(data + type_offset, type_size);
1793 static int parse_common_pid(void *data)
1795 static int pid_offset;
1796 static int pid_size;
1800 ret = get_common_info("common_pid",
1807 return read_size(data + pid_offset, pid_size);
1810 static struct event *find_event(int id)
1812 struct event *event;
1814 for (event = event_list; event; event = event->next) {
1815 if (event->id == id)
1821 static unsigned long long eval_num_arg(void *data, int size,
1822 struct event *event, struct print_arg *arg)
1824 unsigned long long val = 0;
1825 unsigned long long left, right;
1827 switch (arg->type) {
1832 return strtoull(arg->atom.atom, NULL, 0);
1834 if (!arg->field.field) {
1835 arg->field.field = find_any_field(event, arg->field.name);
1836 if (!arg->field.field)
1837 die("field %s not found", arg->field.name);
1839 /* must be a number */
1840 val = read_size(data + arg->field.field->offset,
1841 arg->field.field->size);
1847 return eval_num_arg(data, size, event, arg->typecast.item);
1852 left = eval_num_arg(data, size, event, arg->op.left);
1853 right = eval_num_arg(data, size, event, arg->op.right);
1854 switch (arg->op.op[0]) {
1857 val = left || right;
1863 val = left && right;
1868 switch (arg->op.op[1]) {
1873 val = left << right;
1876 val = left <= right;
1879 die("unknown op '%s'", arg->op.op);
1883 switch (arg->op.op[1]) {
1888 val = left >> right;
1891 val = left >= right;
1894 die("unknown op '%s'", arg->op.op);
1898 if (arg->op.op[1] != '=')
1899 die("unknown op '%s'", arg->op.op);
1900 val = left == right;
1903 die("unknown op '%s'", arg->op.op);
1906 default: /* not sure what to do there */
1914 unsigned long long value;
1917 static const struct flag flags[] = {
1918 { "HI_SOFTIRQ", 0 },
1919 { "TIMER_SOFTIRQ", 1 },
1920 { "NET_TX_SOFTIRQ", 2 },
1921 { "NET_RX_SOFTIRQ", 3 },
1922 { "BLOCK_SOFTIRQ", 4 },
1923 { "TASKLET_SOFTIRQ", 5 },
1924 { "SCHED_SOFTIRQ", 6 },
1925 { "HRTIMER_SOFTIRQ", 7 },
1926 { "RCU_SOFTIRQ", 8 },
1928 { "HRTIMER_NORESTART", 0 },
1929 { "HRTIMER_RESTART", 1 },
1932 static unsigned long long eval_flag(const char *flag)
1937 * Some flags in the format files do not get converted.
1938 * If the flag is not numeric, see if it is something that
1939 * we already know about.
1941 if (isdigit(flag[0]))
1942 return strtoull(flag, NULL, 0);
1944 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
1945 if (strcmp(flags[i].name, flag) == 0)
1946 return flags[i].value;
1951 static void print_str_arg(void *data, int size,
1952 struct event *event, struct print_arg *arg)
1954 struct print_flag_sym *flag;
1955 unsigned long long val, fval;
1959 switch (arg->type) {
1964 printf("%s", arg->atom.atom);
1967 if (!arg->field.field) {
1968 arg->field.field = find_any_field(event, arg->field.name);
1969 if (!arg->field.field)
1970 die("field %s not found", arg->field.name);
1972 str = malloc_or_die(arg->field.field->size + 1);
1973 memcpy(str, data + arg->field.field->offset,
1974 arg->field.field->size);
1975 str[arg->field.field->size] = 0;
1979 val = eval_num_arg(data, size, event, arg->flags.field);
1981 for (flag = arg->flags.flags; flag; flag = flag->next) {
1982 fval = eval_flag(flag->value);
1983 if (!val && !fval) {
1984 printf("%s", flag->str);
1987 if (fval && (val & fval) == fval) {
1988 if (print && arg->flags.delim)
1989 printf("%s", arg->flags.delim);
1990 printf("%s", flag->str);
1997 val = eval_num_arg(data, size, event, arg->symbol.field);
1998 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
1999 fval = eval_flag(flag->value);
2001 printf("%s", flag->str);
2010 printf("%s", arg->string.string);
2014 * The only op for string should be ? :
2016 if (arg->op.op[0] != '?')
2018 val = eval_num_arg(data, size, event, arg->op.left);
2020 print_str_arg(data, size, event, arg->op.right->op.left);
2022 print_str_arg(data, size, event, arg->op.right->op.right);
2030 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2032 static struct format_field *field, *ip_field;
2033 struct print_arg *args, *arg, **next;
2034 unsigned long long ip, val;
2039 field = find_field(event, "buf");
2041 die("can't find buffer field for binary printk");
2042 ip_field = find_field(event, "ip");
2044 die("can't find ip field for binary printk");
2047 ip = read_size(data + ip_field->offset, ip_field->size);
2050 * The first arg is the IP pointer.
2052 args = malloc_or_die(sizeof(*args));
2057 arg->type = PRINT_ATOM;
2058 arg->atom.atom = malloc_or_die(32);
2059 sprintf(arg->atom.atom, "%lld", ip);
2061 /* skip the first "%pf : " */
2062 for (ptr = fmt + 6, bptr = data + field->offset;
2063 bptr < data + size && *ptr; ptr++) {
2087 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2099 val = read_size(bptr, ls);
2101 arg = malloc_or_die(sizeof(*arg));
2103 arg->type = PRINT_ATOM;
2104 arg->atom.atom = malloc_or_die(32);
2105 sprintf(arg->atom.atom, "%lld", val);
2110 arg = malloc_or_die(sizeof(*arg));
2112 arg->type = PRINT_STRING;
2113 arg->string.string = strdup(bptr);
2114 bptr += strlen(bptr) + 1;
2126 static void free_args(struct print_arg *args)
2128 struct print_arg *next;
2133 if (args->type == PRINT_ATOM)
2134 free(args->atom.atom);
2136 free(args->string.string);
2142 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2144 unsigned long long addr;
2145 static struct format_field *field;
2146 struct printk_map *printk;
2151 field = find_field(event, "fmt");
2153 die("can't find format field for binary printk");
2154 printf("field->offset = %d size=%d\n", field->offset, field->size);
2157 addr = read_size(data + field->offset, field->size);
2159 printk = find_printk(addr);
2161 format = malloc_or_die(45);
2162 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2168 /* Remove any quotes. */
2171 format = malloc_or_die(strlen(p) + 10);
2172 sprintf(format, "%s : %s", "%pf", p);
2173 /* remove ending quotes and new line since we will add one too */
2174 p = format + strlen(format) - 1;
2179 if (strcmp(p, "\\n") == 0)
2185 static void pretty_print(void *data, int size, struct event *event)
2187 struct print_fmt *print_fmt = &event->print_fmt;
2188 struct print_arg *arg = print_fmt->args;
2189 struct print_arg *args = NULL;
2190 const char *ptr = print_fmt->format;
2191 unsigned long long val;
2192 struct func_map *func;
2193 const char *saveptr;
2194 char *bprint_fmt = NULL;
2200 if (event->flags & EVENT_FL_ISFUNC)
2201 ptr = " %pF <-- %pF";
2203 if (event->flags & EVENT_FL_ISBPRINT) {
2204 bprint_fmt = get_bprint_format(data, size, event);
2205 args = make_bprint_args(bprint_fmt, data, size, event);
2210 for (; *ptr; ptr++) {
2237 if (*(ptr+1) == 'F' ||
2250 die("no argument match");
2252 len = ((unsigned long)ptr + 1) -
2253 (unsigned long)saveptr;
2255 /* should never happen */
2259 memcpy(format, saveptr, len);
2262 val = eval_num_arg(data, size, event, arg);
2266 func = find_func(val);
2268 printf("%s", func->func);
2269 if (show_func == 'F')
2277 printf(format, (int)val);
2280 printf(format, (long)val);
2283 printf(format, (long long)val);
2286 die("bad count (%d)", ls);
2291 die("no matching argument");
2293 print_str_arg(data, size, event, arg);
2297 printf(">%c<", *ptr);
2310 static inline int log10_cpu(int nb)
2319 /* taken from Linux, written by Frederic Weisbecker */
2320 static void print_graph_cpu(int cpu)
2323 int log10_this = log10_cpu(cpu);
2324 int log10_all = log10_cpu(cpus);
2328 * Start with a space character - to make it stand out
2329 * to the right a bit when trace output is pasted into
2335 * Tricky - we space the CPU field according to the max
2336 * number of online CPUs. On a 2-cpu system it would take
2337 * a maximum of 1 digit - on a 128 cpu system it would
2338 * take up to 3 digits:
2340 for (i = 0; i < log10_all - log10_this; i++)
2343 printf("%d) ", cpu);
2346 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2347 #define TRACE_GRAPH_INDENT 2
2349 static void print_graph_proc(int pid, const char *comm)
2351 /* sign + log10(MAX_INT) + '\0' */
2357 sprintf(pid_str, "%d", pid);
2359 /* 1 stands for the "-" character */
2360 len = strlen(comm) + strlen(pid_str) + 1;
2362 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2363 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2365 /* First spaces to align center */
2366 for (i = 0; i < spaces / 2; i++)
2369 printf("%s-%s", comm, pid_str);
2371 /* Last spaces to align center */
2372 for (i = 0; i < spaces - (spaces / 2); i++)
2376 static struct record *
2377 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2378 struct record *next)
2380 struct format_field *field;
2381 struct event *event;
2386 type = parse_common_type(next->data);
2387 event = find_event(type);
2391 if (!(event->flags & EVENT_FL_ISFUNCRET))
2394 pid = parse_common_pid(next->data);
2395 field = find_field(event, "func");
2397 die("function return does not have field func");
2399 val = read_size(next->data + field->offset, field->size);
2401 if (cur_pid != pid || cur_func != val)
2404 /* this is a leaf, now advance the iterator */
2405 return trace_read_data(cpu);
2408 /* Signal a overhead of time execution to the output */
2409 static void print_graph_overhead(unsigned long long duration)
2411 /* Non nested entry or return */
2412 if (duration == ~0ULL)
2413 return (void)printf(" ");
2415 /* Duration exceeded 100 msecs */
2416 if (duration > 100000ULL)
2417 return (void)printf("! ");
2419 /* Duration exceeded 10 msecs */
2420 if (duration > 10000ULL)
2421 return (void)printf("+ ");
2426 static void print_graph_duration(unsigned long long duration)
2428 unsigned long usecs = duration / 1000;
2429 unsigned long nsecs_rem = duration % 1000;
2430 /* log10(ULONG_MAX) + '\0' */
2436 sprintf(msecs_str, "%lu", usecs);
2439 len = printf("%lu", usecs);
2441 /* Print nsecs (we don't want to exceed 7 numbers) */
2443 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2444 len += printf(".%s", nsecs_str);
2449 /* Print remaining spaces to fit the row's width */
2450 for (i = len; i < 7; i++)
2457 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2459 unsigned long long rettime, calltime;
2460 unsigned long long duration, depth;
2461 unsigned long long val;
2462 struct format_field *field;
2463 struct func_map *func;
2464 struct event *ret_event;
2468 type = parse_common_type(ret_rec->data);
2469 ret_event = find_event(type);
2471 field = find_field(ret_event, "rettime");
2473 die("can't find rettime in return graph");
2474 rettime = read_size(ret_rec->data + field->offset, field->size);
2476 field = find_field(ret_event, "calltime");
2478 die("can't find rettime in return graph");
2479 calltime = read_size(ret_rec->data + field->offset, field->size);
2481 duration = rettime - calltime;
2484 print_graph_overhead(duration);
2487 print_graph_duration(duration);
2489 field = find_field(event, "depth");
2491 die("can't find depth in entry graph");
2492 depth = read_size(data + field->offset, field->size);
2495 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2498 field = find_field(event, "func");
2500 die("can't find func in entry graph");
2501 val = read_size(data + field->offset, field->size);
2502 func = find_func(val);
2505 printf("%s();", func->func);
2507 printf("%llx();", val);
2510 static void print_graph_nested(struct event *event, void *data)
2512 struct format_field *field;
2513 unsigned long long depth;
2514 unsigned long long val;
2515 struct func_map *func;
2519 print_graph_overhead(-1);
2524 field = find_field(event, "depth");
2526 die("can't find depth in entry graph");
2527 depth = read_size(data + field->offset, field->size);
2530 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2533 field = find_field(event, "func");
2535 die("can't find func in entry graph");
2536 val = read_size(data + field->offset, field->size);
2537 func = find_func(val);
2540 printf("%s() {", func->func);
2542 printf("%llx() {", val);
2546 pretty_print_func_ent(void *data, int size, struct event *event,
2547 int cpu, int pid, const char *comm,
2548 unsigned long secs, unsigned long usecs)
2550 struct format_field *field;
2555 printf("%5lu.%06lu | ", secs, usecs);
2557 print_graph_cpu(cpu);
2558 print_graph_proc(pid, comm);
2562 field = find_field(event, "func");
2564 die("function entry does not have func field");
2566 val = read_size(data + field->offset, field->size);
2569 * peek_data may unmap the data pointer. Copy it first.
2571 copy_data = malloc_or_die(size);
2572 memcpy(copy_data, data, size);
2575 rec = trace_peek_data(cpu);
2577 rec = get_return_for_leaf(cpu, pid, val, rec);
2579 print_graph_entry_leaf(event, data, rec);
2583 print_graph_nested(event, data);
2589 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2590 int cpu, int pid, const char *comm,
2591 unsigned long secs, unsigned long usecs)
2593 unsigned long long rettime, calltime;
2594 unsigned long long duration, depth;
2595 struct format_field *field;
2598 printf("%5lu.%06lu | ", secs, usecs);
2600 print_graph_cpu(cpu);
2601 print_graph_proc(pid, comm);
2605 field = find_field(event, "rettime");
2607 die("can't find rettime in return graph");
2608 rettime = read_size(data + field->offset, field->size);
2610 field = find_field(event, "calltime");
2612 die("can't find calltime in return graph");
2613 calltime = read_size(data + field->offset, field->size);
2615 duration = rettime - calltime;
2618 print_graph_overhead(duration);
2621 print_graph_duration(duration);
2623 field = find_field(event, "depth");
2625 die("can't find depth in entry graph");
2626 depth = read_size(data + field->offset, field->size);
2629 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2636 pretty_print_func_graph(void *data, int size, struct event *event,
2637 int cpu, int pid, const char *comm,
2638 unsigned long secs, unsigned long usecs)
2640 if (event->flags & EVENT_FL_ISFUNCENT)
2641 pretty_print_func_ent(data, size, event,
2642 cpu, pid, comm, secs, usecs);
2643 else if (event->flags & EVENT_FL_ISFUNCRET)
2644 pretty_print_func_ret(data, size, event,
2645 cpu, pid, comm, secs, usecs);
2649 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2652 struct event *event;
2654 unsigned long usecs;
2658 secs = nsecs / NSECS_PER_SEC;
2659 nsecs -= secs * NSECS_PER_SEC;
2660 usecs = nsecs / NSECS_PER_USEC;
2662 type = parse_common_type(data);
2664 event = find_event(type);
2666 die("ug! no event found for type %d", type);
2668 pid = parse_common_pid(data);
2670 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2671 return pretty_print_func_graph(data, size, event, cpu,
2672 pid, comm, secs, usecs);
2674 printf("%16s-%-5d [%03d] %5lu.%06lu: %s: ",
2676 secs, usecs, event->name);
2678 pretty_print(data, size, event);
2682 static void print_fields(struct print_flag_sym *field)
2684 printf("{ %s, %s }", field->value, field->str);
2687 print_fields(field->next);
2691 static void print_args(struct print_arg *args)
2693 int print_paren = 1;
2695 switch (args->type) {
2700 printf("%s", args->atom.atom);
2703 printf("REC->%s", args->field.name);
2706 printf("__print_flags(");
2707 print_args(args->flags.field);
2708 printf(", %s, ", args->flags.delim);
2709 print_fields(args->flags.flags);
2713 printf("__print_symbolic(");
2714 print_args(args->symbol.field);
2716 print_fields(args->symbol.symbols);
2720 printf("__get_str(%s)", args->string.string);
2723 printf("(%s)", args->typecast.type);
2724 print_args(args->typecast.item);
2727 if (strcmp(args->op.op, ":") == 0)
2731 print_args(args->op.left);
2732 printf(" %s ", args->op.op);
2733 print_args(args->op.right);
2738 /* we should warn... */
2743 print_args(args->next);
2747 static void parse_header_field(char *type,
2748 int *offset, int *size)
2752 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2754 if (read_expected(EVENT_OP, (char *)":") < 0)
2757 if (read_expect_type(EVENT_ITEM, &token) < 0)
2761 if (read_expected(EVENT_ITEM, type) < 0)
2763 if (read_expected(EVENT_OP, (char *)";") < 0)
2765 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2767 if (read_expected(EVENT_OP, (char *)":") < 0)
2769 if (read_expect_type(EVENT_ITEM, &token) < 0)
2771 *offset = atoi(token);
2773 if (read_expected(EVENT_OP, (char *)";") < 0)
2775 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2777 if (read_expected(EVENT_OP, (char *)":") < 0)
2779 if (read_expect_type(EVENT_ITEM, &token) < 0)
2781 *size = atoi(token);
2783 if (read_expected(EVENT_OP, (char *)";") < 0)
2785 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2790 int parse_header_page(char *buf, unsigned long size)
2792 init_input_buf(buf, size);
2794 parse_header_field((char *)"timestamp", &header_page_ts_offset,
2795 &header_page_ts_size);
2796 parse_header_field((char *)"commit", &header_page_size_offset,
2797 &header_page_size_size);
2798 parse_header_field((char *)"data", &header_page_data_offset,
2799 &header_page_data_size);
2804 int parse_ftrace_file(char *buf, unsigned long size)
2806 struct format_field *field;
2807 struct print_arg *arg, **list;
2808 struct event *event;
2811 init_input_buf(buf, size);
2813 event = alloc_event();
2817 event->flags |= EVENT_FL_ISFTRACE;
2819 event->name = event_read_name();
2821 die("failed to read ftrace event name");
2823 if (strcmp(event->name, "function") == 0)
2824 event->flags |= EVENT_FL_ISFUNC;
2826 else if (strcmp(event->name, "funcgraph_entry") == 0)
2827 event->flags |= EVENT_FL_ISFUNCENT;
2829 else if (strcmp(event->name, "funcgraph_exit") == 0)
2830 event->flags |= EVENT_FL_ISFUNCRET;
2832 else if (strcmp(event->name, "bprint") == 0)
2833 event->flags |= EVENT_FL_ISBPRINT;
2835 event->id = event_read_id();
2837 die("failed to read ftrace event id");
2841 ret = event_read_format(event);
2843 die("failed to read ftrace event format");
2845 ret = event_read_print(event);
2847 die("failed to read ftrace event print fmt");
2850 * The arguments for ftrace files are parsed by the fields.
2851 * Set up the fields as their arguments.
2853 list = &event->print_fmt.args;
2854 for (field = event->format.fields; field; field = field->next) {
2855 arg = malloc_or_die(sizeof(*arg));
2856 memset(arg, 0, sizeof(*arg));
2859 arg->type = PRINT_FIELD;
2860 arg->field.name = field->name;
2861 arg->field.field = field;
2866 int parse_event_file(char *buf, unsigned long size, char *system__unused __unused)
2868 struct event *event;
2871 init_input_buf(buf, size);
2873 event = alloc_event();
2877 event->name = event_read_name();
2879 die("failed to read event name");
2881 event->id = event_read_id();
2883 die("failed to read event id");
2885 ret = event_read_format(event);
2887 die("failed to read event format");
2889 ret = event_read_print(event);
2891 die("failed to read event print fmt");
2893 #define PRINT_ARGS 0
2894 if (PRINT_ARGS && event->print_fmt.args)
2895 print_args(event->print_fmt.args);
2901 void parse_set_info(int nr_cpus, int long_sz)
2904 long_size = long_sz;