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.
34 #include "trace-event.h"
36 int header_page_ts_offset;
37 int header_page_ts_size;
38 int header_page_size_offset;
39 int header_page_size_size;
40 int header_page_data_offset;
41 int header_page_data_size;
43 static char *input_buf;
44 static unsigned long long input_buf_ptr;
45 static unsigned long long input_buf_siz;
50 static void init_input_buf(char *buf, unsigned long long size)
62 static struct cmdline *cmdlines;
63 static int cmdline_count;
65 static int cmdline_cmp(const void *a, const void *b)
67 const struct cmdline *ca = a;
68 const struct cmdline *cb = b;
70 if (ca->pid < cb->pid)
72 if (ca->pid > cb->pid)
78 void parse_cmdlines(char *file, int size __unused)
81 struct cmdline_list *next;
84 } *list = NULL, *item;
89 line = strtok_r(file, "\n", &next);
91 item = malloc_or_die(sizeof(*item));
92 sscanf(line, "%d %as", &item->pid,
93 (float *)(void *)&item->comm); /* workaround gcc warning */
96 line = strtok_r(NULL, "\n", &next);
100 cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
104 cmdlines[i].pid = list->pid;
105 cmdlines[i].comm = list->comm;
112 qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
115 static struct func_map {
116 unsigned long long addr;
120 static unsigned int func_count;
122 static int func_cmp(const void *a, const void *b)
124 const struct func_map *fa = a;
125 const struct func_map *fb = b;
127 if (fa->addr < fb->addr)
129 if (fa->addr > fb->addr)
135 void parse_proc_kallsyms(char *file, unsigned int size __unused)
138 struct func_list *next;
139 unsigned long long addr;
142 } *list = NULL, *item;
150 line = strtok_r(file, "\n", &next);
152 item = malloc_or_die(sizeof(*item));
154 ret = sscanf(line, "%as %c %as\t[%as",
155 (float *)(void *)&addr_str, /* workaround gcc warning */
157 (float *)(void *)&item->func,
158 (float *)(void *)&item->mod);
159 item->addr = strtoull(addr_str, NULL, 16);
162 /* truncate the extra ']' */
164 item->mod[strlen(item->mod) - 1] = 0;
169 line = strtok_r(NULL, "\n", &next);
173 func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
177 func_list[i].func = list->func;
178 func_list[i].addr = list->addr;
179 func_list[i].mod = list->mod;
186 qsort(func_list, func_count, sizeof(*func_list), func_cmp);
189 * Add a special record at the end.
191 func_list[func_count].func = NULL;
192 func_list[func_count].addr = 0;
193 func_list[func_count].mod = NULL;
197 * We are searching for a record in between, not an exact
200 static int func_bcmp(const void *a, const void *b)
202 const struct func_map *fa = a;
203 const struct func_map *fb = b;
205 if ((fa->addr == fb->addr) ||
207 (fa->addr > fb->addr &&
208 fa->addr < (fb+1)->addr))
211 if (fa->addr < fb->addr)
217 static struct func_map *find_func(unsigned long long addr)
219 struct func_map *func;
224 func = bsearch(&key, func_list, func_count, sizeof(*func_list),
230 void print_funcs(void)
234 for (i = 0; i < (int)func_count; i++) {
238 if (func_list[i].mod)
239 printf(" [%s]\n", func_list[i].mod);
245 static struct printk_map {
246 unsigned long long addr;
249 static unsigned int printk_count;
251 static int printk_cmp(const void *a, const void *b)
253 const struct func_map *fa = a;
254 const struct func_map *fb = b;
256 if (fa->addr < fb->addr)
258 if (fa->addr > fb->addr)
264 static struct printk_map *find_printk(unsigned long long addr)
266 struct printk_map *printk;
267 struct printk_map key;
271 printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
277 void parse_ftrace_printk(char *file, unsigned int size __unused)
280 struct printk_list *next;
281 unsigned long long addr;
283 } *list = NULL, *item;
290 line = strtok_r(file, "\n", &next);
292 item = malloc_or_die(sizeof(*item));
293 ret = sscanf(line, "%as : %as",
294 (float *)(void *)&addr_str, /* workaround gcc warning */
295 (float *)(void *)&item->printk);
296 item->addr = strtoull(addr_str, NULL, 16);
301 line = strtok_r(NULL, "\n", &next);
305 printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
309 printk_list[i].printk = list->printk;
310 printk_list[i].addr = list->addr;
317 qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
320 void print_printk(void)
324 for (i = 0; i < (int)printk_count; i++) {
325 printf("%016llx %s\n",
327 printk_list[i].printk);
331 static struct event *alloc_event(void)
335 event = malloc_or_die(sizeof(*event));
336 memset(event, 0, sizeof(*event));
353 static struct event *event_list;
355 static void add_event(struct event *event)
357 event->next = event_list;
361 static int event_item_type(enum event_type type)
364 case EVENT_ITEM ... EVENT_SQUOTE:
366 case EVENT_ERROR ... EVENT_DELIM:
372 static void free_arg(struct print_arg *arg)
380 free(arg->atom.atom);
383 case PRINT_FIELD ... PRINT_OP:
392 static enum event_type get_type(int ch)
395 return EVENT_NEWLINE;
398 if (isalnum(ch) || ch == '_')
406 if (ch == '(' || ch == ')' || ch == ',')
412 static int __read_char(void)
414 if (input_buf_ptr >= input_buf_siz)
417 return input_buf[input_buf_ptr++];
420 static int __peek_char(void)
422 if (input_buf_ptr >= input_buf_siz)
425 return input_buf[input_buf_ptr];
428 static enum event_type __read_token(char **tok)
431 int ch, last_ch, quote_ch, next_ch;
434 enum event_type type;
444 if (type == EVENT_NONE)
452 *tok = malloc_or_die(2);
460 next_ch = __peek_char();
461 if (next_ch == '>') {
462 buf[i++] = __read_char();
475 buf[i++] = __read_char();
487 default: /* what should we do instead? */
497 buf[i++] = __read_char();
502 /* don't keep quotes */
507 if (i == (BUFSIZ - 1)) {
510 *tok = realloc(*tok, tok_size + BUFSIZ);
525 } while (ch != quote_ch && last_ch != '\\');
526 /* remove the last quote */
530 case EVENT_ERROR ... EVENT_SPACE:
536 while (get_type(__peek_char()) == type) {
537 if (i == (BUFSIZ - 1)) {
540 *tok = realloc(*tok, tok_size + BUFSIZ);
559 *tok = realloc(*tok, tok_size + i);
571 static void free_token(char *tok)
577 static enum event_type read_token(char **tok)
579 enum event_type type;
582 type = __read_token(tok);
583 if (type != EVENT_SPACE)
594 static enum event_type read_token_item(char **tok)
596 enum event_type type;
599 type = __read_token(tok);
600 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
610 static int test_type(enum event_type type, enum event_type expect)
612 if (type != expect) {
613 die("Error: expected type %d but read %d",
620 static int test_type_token(enum event_type type, char *token,
621 enum event_type expect, char *expect_tok)
623 if (type != expect) {
624 die("Error: expected type %d but read %d",
629 if (strcmp(token, expect_tok) != 0) {
630 die("Error: expected '%s' but read '%s'",
637 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
639 enum event_type type;
642 type = read_token(tok);
644 type = read_token_item(tok);
645 return test_type(type, expect);
648 static int read_expect_type(enum event_type expect, char **tok)
650 return __read_expect_type(expect, tok, 1);
653 static int __read_expected(enum event_type expect, char *str, int newline_ok)
655 enum event_type type;
660 type = read_token(&token);
662 type = read_token_item(&token);
664 ret = test_type_token(type, token, expect, str);
671 static int read_expected(enum event_type expect, char *str)
673 return __read_expected(expect, str, 1);
676 static int read_expected_item(enum event_type expect, char *str)
678 return __read_expected(expect, str, 0);
681 static char *event_read_name(void)
685 if (read_expected(EVENT_ITEM, (char *)"name") < 0)
688 if (read_expected(EVENT_OP, (char *)":") < 0)
691 if (read_expect_type(EVENT_ITEM, &token) < 0)
701 static int event_read_id(void)
706 if (read_expected_item(EVENT_ITEM, (char *)"ID") < 0)
709 if (read_expected(EVENT_OP, (char *)":") < 0)
712 if (read_expect_type(EVENT_ITEM, &token) < 0)
715 id = strtoul(token, NULL, 0);
724 static int event_read_fields(struct event *event, struct format_field **fields)
726 struct format_field *field = NULL;
727 enum event_type type;
733 type = read_token(&token);
734 if (type == EVENT_NEWLINE) {
741 if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
745 type = read_token(&token);
747 * The ftrace fields may still use the "special" name.
750 if (event->flags & EVENT_FL_ISFTRACE &&
751 type == EVENT_ITEM && strcmp(token, "special") == 0) {
753 type = read_token(&token);
756 if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
759 if (read_expect_type(EVENT_ITEM, &token) < 0)
764 field = malloc_or_die(sizeof(*field));
765 memset(field, 0, sizeof(*field));
767 /* read the rest of the type */
769 type = read_token(&token);
770 if (type == EVENT_ITEM ||
771 (type == EVENT_OP && strcmp(token, "*") == 0) ||
773 * Some of the ftrace fields are broken and have
774 * an illegal "." in them.
776 (event->flags & EVENT_FL_ISFTRACE &&
777 type == EVENT_OP && strcmp(token, ".") == 0)) {
779 if (strcmp(token, "*") == 0)
780 field->flags |= FIELD_IS_POINTER;
783 field->type = realloc(field->type,
784 strlen(field->type) +
785 strlen(last_token) + 2);
786 strcat(field->type, " ");
787 strcat(field->type, last_token);
789 field->type = last_token;
798 die("no type found");
801 field->name = last_token;
803 if (test_type(type, EVENT_OP))
806 if (strcmp(token, "[") == 0) {
807 enum event_type last_type = type;
808 char *brackets = token;
811 field->flags |= FIELD_IS_ARRAY;
813 type = read_token(&token);
814 while (strcmp(token, "]") != 0) {
815 if (last_type == EVENT_ITEM &&
822 brackets = realloc(brackets,
824 strlen(token) + len);
826 strcat(brackets, " ");
827 strcat(brackets, token);
829 type = read_token(&token);
830 if (type == EVENT_NONE) {
831 die("failed to find token");
838 brackets = realloc(brackets, strlen(brackets) + 2);
839 strcat(brackets, "]");
841 /* add brackets to type */
843 type = read_token(&token);
845 * If the next token is not an OP, then it is of
846 * the format: type [] item;
848 if (type == EVENT_ITEM) {
849 field->type = realloc(field->type,
850 strlen(field->type) +
851 strlen(field->name) +
852 strlen(brackets) + 2);
853 strcat(field->type, " ");
854 strcat(field->type, field->name);
855 free_token(field->name);
856 strcat(field->type, brackets);
858 type = read_token(&token);
860 field->type = realloc(field->type,
861 strlen(field->type) +
862 strlen(brackets) + 1);
863 strcat(field->type, brackets);
868 if (test_type_token(type, token, EVENT_OP, (char *)";"))
872 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
875 if (read_expected(EVENT_OP, (char *)":") < 0)
878 if (read_expect_type(EVENT_ITEM, &token))
880 field->offset = strtoul(token, NULL, 0);
883 if (read_expected(EVENT_OP, (char *)";") < 0)
886 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
889 if (read_expected(EVENT_OP, (char *)":") < 0)
892 if (read_expect_type(EVENT_ITEM, &token))
894 field->size = strtoul(token, NULL, 0);
897 if (read_expected(EVENT_OP, (char *)";") < 0)
900 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
905 fields = &field->next;
919 static int event_read_format(struct event *event)
924 if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
927 if (read_expected(EVENT_OP, (char *)":") < 0)
930 if (read_expect_type(EVENT_NEWLINE, &token))
934 ret = event_read_fields(event, &event->format.common_fields);
937 event->format.nr_common = ret;
939 ret = event_read_fields(event, &event->format.fields);
942 event->format.nr_fields = ret;
952 process_arg_token(struct event *event, struct print_arg *arg,
953 char **tok, enum event_type type);
955 static enum event_type
956 process_arg(struct event *event, struct print_arg *arg, char **tok)
958 enum event_type type;
961 type = read_token(&token);
964 return process_arg_token(event, arg, tok, type);
967 static enum event_type
968 process_cond(struct event *event, struct print_arg *top, char **tok)
970 struct print_arg *arg, *left, *right;
971 enum event_type type;
974 arg = malloc_or_die(sizeof(*arg));
975 memset(arg, 0, sizeof(*arg));
977 left = malloc_or_die(sizeof(*left));
979 right = malloc_or_die(sizeof(*right));
981 arg->type = PRINT_OP;
983 arg->op.right = right;
986 type = process_arg(event, left, &token);
987 if (test_type_token(type, token, EVENT_OP, (char *)":"))
992 type = process_arg(event, right, &token);
1007 static int get_op_prio(char *op)
1018 /* '>>' and '<<' are 8 */
1022 /* '==' and '!=' are 10 */
1032 die("unknown op '%c'", op[0]);
1036 if (strcmp(op, "++") == 0 ||
1037 strcmp(op, "--") == 0) {
1039 } else if (strcmp(op, ">>") == 0 ||
1040 strcmp(op, "<<") == 0) {
1042 } else if (strcmp(op, ">=") == 0 ||
1043 strcmp(op, "<=") == 0) {
1045 } else if (strcmp(op, "==") == 0 ||
1046 strcmp(op, "!=") == 0) {
1048 } else if (strcmp(op, "&&") == 0) {
1050 } else if (strcmp(op, "||") == 0) {
1053 die("unknown op '%s'", op);
1059 static void set_op_prio(struct print_arg *arg)
1062 /* single ops are the greatest */
1063 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1068 arg->op.prio = get_op_prio(arg->op.op);
1071 static enum event_type
1072 process_op(struct event *event, struct print_arg *arg, char **tok)
1074 struct print_arg *left, *right = NULL;
1075 enum event_type type;
1078 /* the op is passed in via tok */
1081 if (arg->type == PRINT_OP && !arg->op.left) {
1082 /* handle single op */
1084 die("bad op token %s", token);
1093 die("bad op token %s", token);
1097 /* make an empty left */
1098 left = malloc_or_die(sizeof(*left));
1099 left->type = PRINT_NULL;
1100 arg->op.left = left;
1102 right = malloc_or_die(sizeof(*right));
1103 arg->op.right = right;
1105 type = process_arg(event, right, tok);
1107 } else if (strcmp(token, "?") == 0) {
1109 left = malloc_or_die(sizeof(*left));
1110 /* copy the top arg to the left */
1113 arg->type = PRINT_OP;
1115 arg->op.left = left;
1118 type = process_cond(event, arg, tok);
1120 } else if (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 ||
1132 strcmp(token, "!=") == 0) {
1134 left = malloc_or_die(sizeof(*left));
1136 /* copy the top arg to the left */
1139 arg->type = PRINT_OP;
1141 arg->op.left = left;
1145 right = malloc_or_die(sizeof(*right));
1147 type = process_arg(event, right, tok);
1149 arg->op.right = right;
1152 die("unknown op '%s'", token);
1153 /* the arg is now the left side */
1158 if (type == EVENT_OP) {
1161 /* higher prios need to be closer to the root */
1162 prio = get_op_prio(*tok);
1164 if (prio > arg->op.prio)
1165 return process_op(event, arg, tok);
1167 return process_op(event, right, tok);
1173 static enum event_type
1174 process_entry(struct event *event __unused, struct print_arg *arg,
1177 enum event_type type;
1181 if (read_expected(EVENT_OP, (char *)"->") < 0)
1184 if (read_expect_type(EVENT_ITEM, &token) < 0)
1188 arg->type = PRINT_FIELD;
1189 arg->field.name = field;
1191 type = read_token(&token);
1201 static char *arg_eval (struct print_arg *arg);
1203 static long long arg_num_eval(struct print_arg *arg)
1205 long long left, right;
1208 switch (arg->type) {
1210 val = strtoll(arg->atom.atom, NULL, 0);
1213 val = arg_num_eval(arg->typecast.item);
1216 switch (arg->op.op[0]) {
1218 left = arg_num_eval(arg->op.left);
1219 right = arg_num_eval(arg->op.right);
1221 val = left || right;
1226 left = arg_num_eval(arg->op.left);
1227 right = arg_num_eval(arg->op.right);
1229 val = left && right;
1234 left = arg_num_eval(arg->op.left);
1235 right = arg_num_eval(arg->op.right);
1236 switch (arg->op.op[1]) {
1241 val = left << right;
1244 val = left <= right;
1247 die("unknown op '%s'", arg->op.op);
1251 left = arg_num_eval(arg->op.left);
1252 right = arg_num_eval(arg->op.right);
1253 switch (arg->op.op[1]) {
1258 val = left >> right;
1261 val = left >= right;
1264 die("unknown op '%s'", arg->op.op);
1268 left = arg_num_eval(arg->op.left);
1269 right = arg_num_eval(arg->op.right);
1271 if (arg->op.op[1] != '=')
1272 die("unknown op '%s'", arg->op.op);
1274 val = left == right;
1277 left = arg_num_eval(arg->op.left);
1278 right = arg_num_eval(arg->op.right);
1280 switch (arg->op.op[1]) {
1282 val = left != right;
1285 die("unknown op '%s'", arg->op.op);
1289 die("unknown op '%s'", arg->op.op);
1294 case PRINT_FIELD ... PRINT_SYMBOL:
1297 die("invalid eval type %d", arg->type);
1303 static char *arg_eval (struct print_arg *arg)
1306 static char buf[20];
1308 switch (arg->type) {
1310 return arg->atom.atom;
1312 return arg_eval(arg->typecast.item);
1314 val = arg_num_eval(arg);
1315 sprintf(buf, "%lld", val);
1319 case PRINT_FIELD ... PRINT_SYMBOL:
1322 die("invalid eval type %d", arg->type);
1329 static enum event_type
1330 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1332 enum event_type type;
1333 struct print_arg *arg = NULL;
1334 struct print_flag_sym *field;
1340 type = read_token_item(&token);
1341 if (test_type_token(type, token, EVENT_OP, (char *)"{"))
1344 arg = malloc_or_die(sizeof(*arg));
1347 type = process_arg(event, arg, &token);
1348 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1351 field = malloc_or_die(sizeof(*field));
1352 memset(field, 0, sizeof(field));
1354 value = arg_eval(arg);
1355 field->value = strdup(value);
1358 type = process_arg(event, arg, &token);
1359 if (test_type_token(type, token, EVENT_OP, (char *)"}"))
1362 value = arg_eval(arg);
1363 field->str = strdup(value);
1368 list = &field->next;
1371 type = read_token_item(&token);
1372 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1384 static enum event_type
1385 process_flags(struct event *event, struct print_arg *arg, char **tok)
1387 struct print_arg *field;
1388 enum event_type type;
1391 memset(arg, 0, sizeof(*arg));
1392 arg->type = PRINT_FLAGS;
1394 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1397 field = malloc_or_die(sizeof(*field));
1399 type = process_arg(event, field, &token);
1400 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1403 arg->flags.field = field;
1405 type = read_token_item(&token);
1406 if (event_item_type(type)) {
1407 arg->flags.delim = token;
1408 type = read_token_item(&token);
1411 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1414 type = process_fields(event, &arg->flags.flags, &token);
1415 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1419 type = read_token_item(tok);
1427 static enum event_type
1428 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1430 struct print_arg *field;
1431 enum event_type type;
1434 memset(arg, 0, sizeof(*arg));
1435 arg->type = PRINT_SYMBOL;
1437 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1440 field = malloc_or_die(sizeof(*field));
1442 type = process_arg(event, field, &token);
1443 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1446 arg->symbol.field = field;
1448 type = process_fields(event, &arg->symbol.symbols, &token);
1449 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1453 type = read_token_item(tok);
1461 static enum event_type
1462 process_paren(struct event *event, struct print_arg *arg, char **tok)
1464 struct print_arg *item_arg;
1465 enum event_type type;
1469 type = process_arg(event, arg, &token);
1471 if (type == EVENT_ERROR)
1474 if (type == EVENT_OP) {
1475 /* handle the ptr casts */
1476 if (!strcmp(token, "*")) {
1478 * FIXME: should we zapp whitespaces before ')' ?
1479 * (may require a peek_token_item())
1481 if (__peek_char() == ')') {
1484 type = read_token_item(&token);
1488 type = process_op(event, arg, &token);
1490 if (type == EVENT_ERROR)
1495 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1501 type = read_token_item(&token);
1504 * If the next token is an item or another open paren, then
1505 * this was a typecast.
1507 if (event_item_type(type) ||
1508 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1510 /* make this a typecast and contine */
1512 /* prevous must be an atom */
1513 if (arg->type != PRINT_ATOM)
1514 die("previous needed to be PRINT_ATOM");
1516 item_arg = malloc_or_die(sizeof(*item_arg));
1518 arg->type = PRINT_TYPE;
1520 char *old = arg->atom.atom;
1522 arg->atom.atom = malloc_or_die(strlen(old + 3));
1523 sprintf(arg->atom.atom, "%s *", old);
1526 arg->typecast.type = arg->atom.atom;
1527 arg->typecast.item = item_arg;
1528 type = process_arg_token(event, item_arg, &token, type);
1537 static enum event_type
1538 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1540 enum event_type type;
1543 if (read_expected(EVENT_DELIM, (char *)"(") < 0)
1546 if (read_expect_type(EVENT_ITEM, &token) < 0)
1549 arg->type = PRINT_STRING;
1550 arg->string.string = token;
1551 arg->string.offset = -1;
1553 if (read_expected(EVENT_DELIM, (char *)")") < 0)
1556 type = read_token(&token);
1566 process_arg_token(struct event *event, struct print_arg *arg,
1567 char **tok, enum event_type type)
1576 if (strcmp(token, "REC") == 0) {
1578 type = process_entry(event, arg, &token);
1579 } else if (strcmp(token, "__print_flags") == 0) {
1581 type = process_flags(event, arg, &token);
1582 } else if (strcmp(token, "__print_symbolic") == 0) {
1584 type = process_symbols(event, arg, &token);
1585 } else if (strcmp(token, "__get_str") == 0) {
1587 type = process_str(event, arg, &token);
1590 /* test the next token */
1591 type = read_token_item(&token);
1593 /* atoms can be more than one token long */
1594 while (type == EVENT_ITEM) {
1595 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1597 strcat(atom, token);
1599 type = read_token_item(&token);
1602 /* todo, test for function */
1604 arg->type = PRINT_ATOM;
1605 arg->atom.atom = atom;
1610 arg->type = PRINT_ATOM;
1611 arg->atom.atom = token;
1612 type = read_token_item(&token);
1615 if (strcmp(token, "(") == 0) {
1617 type = process_paren(event, arg, &token);
1621 /* handle single ops */
1622 arg->type = PRINT_OP;
1624 arg->op.left = NULL;
1625 type = process_op(event, arg, &token);
1629 case EVENT_ERROR ... EVENT_NEWLINE:
1631 die("unexpected type %d", type);
1638 static int event_read_print_args(struct event *event, struct print_arg **list)
1640 enum event_type type;
1641 struct print_arg *arg;
1646 arg = malloc_or_die(sizeof(*arg));
1647 memset(arg, 0, sizeof(*arg));
1649 type = process_arg(event, arg, &token);
1651 if (type == EVENT_ERROR) {
1659 if (type == EVENT_OP) {
1660 type = process_op(event, arg, &token);
1665 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1672 } while (type != EVENT_NONE);
1674 if (type != EVENT_NONE)
1680 static int event_read_print(struct event *event)
1682 enum event_type type;
1686 if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
1689 if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
1692 if (read_expected(EVENT_OP, (char *)":") < 0)
1695 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1698 event->print_fmt.format = token;
1699 event->print_fmt.args = NULL;
1701 /* ok to have no arg */
1702 type = read_token_item(&token);
1704 if (type == EVENT_NONE)
1707 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1712 ret = event_read_print_args(event, &event->print_fmt.args);
1723 static struct format_field *
1724 find_common_field(struct event *event, const char *name)
1726 struct format_field *format;
1728 for (format = event->format.common_fields;
1729 format; format = format->next) {
1730 if (strcmp(format->name, name) == 0)
1737 static struct format_field *
1738 find_field(struct event *event, const char *name)
1740 struct format_field *format;
1742 for (format = event->format.fields;
1743 format; format = format->next) {
1744 if (strcmp(format->name, name) == 0)
1751 static struct format_field *
1752 find_any_field(struct event *event, const char *name)
1754 struct format_field *format;
1756 format = find_common_field(event, name);
1759 return find_field(event, name);
1762 static unsigned long long read_size(void *ptr, int size)
1766 return *(unsigned char *)ptr;
1768 return data2host2(ptr);
1770 return data2host4(ptr);
1772 return data2host8(ptr);
1780 raw_field_value(struct event *event, const char *name, void *data)
1782 struct format_field *field;
1784 field = find_any_field(event, name);
1788 return read_size(data + field->offset, field->size);
1791 void *raw_field_ptr(struct event *event, const char *name, void *data)
1793 struct format_field *field;
1795 field = find_any_field(event, name);
1799 return data + field->offset;
1802 static int get_common_info(const char *type, int *offset, int *size)
1804 struct event *event;
1805 struct format_field *field;
1808 * All events should have the same common elements.
1809 * Pick any event to find where the type is;
1812 die("no event_list!");
1815 field = find_common_field(event, type);
1817 die("field '%s' not found", type);
1819 *offset = field->offset;
1820 *size = field->size;
1825 int trace_parse_common_type(void *data)
1827 static int type_offset;
1828 static int type_size;
1832 ret = get_common_info("common_type",
1838 return read_size(data + type_offset, type_size);
1841 static int parse_common_pid(void *data)
1843 static int pid_offset;
1844 static int pid_size;
1848 ret = get_common_info("common_pid",
1855 return read_size(data + pid_offset, pid_size);
1858 struct event *trace_find_event(int id)
1860 struct event *event;
1862 for (event = event_list; event; event = event->next) {
1863 if (event->id == id)
1869 static unsigned long long eval_num_arg(void *data, int size,
1870 struct event *event, struct print_arg *arg)
1872 unsigned long long val = 0;
1873 unsigned long long left, right;
1875 switch (arg->type) {
1880 return strtoull(arg->atom.atom, NULL, 0);
1882 if (!arg->field.field) {
1883 arg->field.field = find_any_field(event, arg->field.name);
1884 if (!arg->field.field)
1885 die("field %s not found", arg->field.name);
1887 /* must be a number */
1888 val = read_size(data + arg->field.field->offset,
1889 arg->field.field->size);
1895 return eval_num_arg(data, size, event, arg->typecast.item);
1900 left = eval_num_arg(data, size, event, arg->op.left);
1901 right = eval_num_arg(data, size, event, arg->op.right);
1902 switch (arg->op.op[0]) {
1905 val = left || right;
1911 val = left && right;
1916 switch (arg->op.op[1]) {
1921 val = left << right;
1924 val = left <= right;
1927 die("unknown op '%s'", arg->op.op);
1931 switch (arg->op.op[1]) {
1936 val = left >> right;
1939 val = left >= right;
1942 die("unknown op '%s'", arg->op.op);
1946 if (arg->op.op[1] != '=')
1947 die("unknown op '%s'", arg->op.op);
1948 val = left == right;
1951 die("unknown op '%s'", arg->op.op);
1954 default: /* not sure what to do there */
1962 unsigned long long value;
1965 static const struct flag flags[] = {
1966 { "HI_SOFTIRQ", 0 },
1967 { "TIMER_SOFTIRQ", 1 },
1968 { "NET_TX_SOFTIRQ", 2 },
1969 { "NET_RX_SOFTIRQ", 3 },
1970 { "BLOCK_SOFTIRQ", 4 },
1971 { "TASKLET_SOFTIRQ", 5 },
1972 { "SCHED_SOFTIRQ", 6 },
1973 { "HRTIMER_SOFTIRQ", 7 },
1974 { "RCU_SOFTIRQ", 8 },
1976 { "HRTIMER_NORESTART", 0 },
1977 { "HRTIMER_RESTART", 1 },
1980 static unsigned long long eval_flag(const char *flag)
1985 * Some flags in the format files do not get converted.
1986 * If the flag is not numeric, see if it is something that
1987 * we already know about.
1989 if (isdigit(flag[0]))
1990 return strtoull(flag, NULL, 0);
1992 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
1993 if (strcmp(flags[i].name, flag) == 0)
1994 return flags[i].value;
1999 static void print_str_arg(void *data, int size,
2000 struct event *event, struct print_arg *arg)
2002 struct print_flag_sym *flag;
2003 unsigned long long val, fval;
2007 switch (arg->type) {
2012 printf("%s", arg->atom.atom);
2015 if (!arg->field.field) {
2016 arg->field.field = find_any_field(event, arg->field.name);
2017 if (!arg->field.field)
2018 die("field %s not found", arg->field.name);
2020 str = malloc_or_die(arg->field.field->size + 1);
2021 memcpy(str, data + arg->field.field->offset,
2022 arg->field.field->size);
2023 str[arg->field.field->size] = 0;
2028 val = eval_num_arg(data, size, event, arg->flags.field);
2030 for (flag = arg->flags.flags; flag; flag = flag->next) {
2031 fval = eval_flag(flag->value);
2032 if (!val && !fval) {
2033 printf("%s", flag->str);
2036 if (fval && (val & fval) == fval) {
2037 if (print && arg->flags.delim)
2038 printf("%s", arg->flags.delim);
2039 printf("%s", flag->str);
2046 val = eval_num_arg(data, size, event, arg->symbol.field);
2047 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2048 fval = eval_flag(flag->value);
2050 printf("%s", flag->str);
2058 case PRINT_STRING: {
2061 if (arg->string.offset == -1) {
2062 struct format_field *f;
2064 f = find_any_field(event, arg->string.string);
2065 arg->string.offset = f->offset;
2067 str_offset = *(int *)(data + arg->string.offset);
2068 str_offset &= 0xffff;
2069 printf("%s", ((char *)data) + str_offset);
2074 * The only op for string should be ? :
2076 if (arg->op.op[0] != '?')
2078 val = eval_num_arg(data, size, event, arg->op.left);
2080 print_str_arg(data, size, event, arg->op.right->op.left);
2082 print_str_arg(data, size, event, arg->op.right->op.right);
2090 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2092 static struct format_field *field, *ip_field;
2093 struct print_arg *args, *arg, **next;
2094 unsigned long long ip, val;
2099 field = find_field(event, "buf");
2101 die("can't find buffer field for binary printk");
2102 ip_field = find_field(event, "ip");
2104 die("can't find ip field for binary printk");
2107 ip = read_size(data + ip_field->offset, ip_field->size);
2110 * The first arg is the IP pointer.
2112 args = malloc_or_die(sizeof(*args));
2117 arg->type = PRINT_ATOM;
2118 arg->atom.atom = malloc_or_die(32);
2119 sprintf(arg->atom.atom, "%lld", ip);
2121 /* skip the first "%pf : " */
2122 for (ptr = fmt + 6, bptr = data + field->offset;
2123 bptr < data + size && *ptr; ptr++) {
2147 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2159 val = read_size(bptr, ls);
2161 arg = malloc_or_die(sizeof(*arg));
2163 arg->type = PRINT_ATOM;
2164 arg->atom.atom = malloc_or_die(32);
2165 sprintf(arg->atom.atom, "%lld", val);
2170 arg = malloc_or_die(sizeof(*arg));
2172 arg->type = PRINT_STRING;
2173 arg->string.string = strdup(bptr);
2174 bptr += strlen(bptr) + 1;
2186 static void free_args(struct print_arg *args)
2188 struct print_arg *next;
2193 if (args->type == PRINT_ATOM)
2194 free(args->atom.atom);
2196 free(args->string.string);
2202 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2204 unsigned long long addr;
2205 static struct format_field *field;
2206 struct printk_map *printk;
2211 field = find_field(event, "fmt");
2213 die("can't find format field for binary printk");
2214 printf("field->offset = %d size=%d\n", field->offset, field->size);
2217 addr = read_size(data + field->offset, field->size);
2219 printk = find_printk(addr);
2221 format = malloc_or_die(45);
2222 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2228 /* Remove any quotes. */
2231 format = malloc_or_die(strlen(p) + 10);
2232 sprintf(format, "%s : %s", "%pf", p);
2233 /* remove ending quotes and new line since we will add one too */
2234 p = format + strlen(format) - 1;
2239 if (strcmp(p, "\\n") == 0)
2245 static void pretty_print(void *data, int size, struct event *event)
2247 struct print_fmt *print_fmt = &event->print_fmt;
2248 struct print_arg *arg = print_fmt->args;
2249 struct print_arg *args = NULL;
2250 const char *ptr = print_fmt->format;
2251 unsigned long long val;
2252 struct func_map *func;
2253 const char *saveptr;
2254 char *bprint_fmt = NULL;
2260 if (event->flags & EVENT_FL_ISFUNC)
2261 ptr = " %pF <-- %pF";
2263 if (event->flags & EVENT_FL_ISBPRINT) {
2264 bprint_fmt = get_bprint_format(data, size, event);
2265 args = make_bprint_args(bprint_fmt, data, size, event);
2270 for (; *ptr; ptr++) {
2297 if (*(ptr+1) == 'F' ||
2310 die("no argument match");
2312 len = ((unsigned long)ptr + 1) -
2313 (unsigned long)saveptr;
2315 /* should never happen */
2319 memcpy(format, saveptr, len);
2322 val = eval_num_arg(data, size, event, arg);
2326 func = find_func(val);
2328 printf("%s", func->func);
2329 if (show_func == 'F')
2337 printf(format, (int)val);
2340 printf(format, (long)val);
2343 printf(format, (long long)val);
2346 die("bad count (%d)", ls);
2351 die("no matching argument");
2353 print_str_arg(data, size, event, arg);
2357 printf(">%c<", *ptr);
2370 static inline int log10_cpu(int nb)
2379 /* taken from Linux, written by Frederic Weisbecker */
2380 static void print_graph_cpu(int cpu)
2383 int log10_this = log10_cpu(cpu);
2384 int log10_all = log10_cpu(cpus);
2388 * Start with a space character - to make it stand out
2389 * to the right a bit when trace output is pasted into
2395 * Tricky - we space the CPU field according to the max
2396 * number of online CPUs. On a 2-cpu system it would take
2397 * a maximum of 1 digit - on a 128 cpu system it would
2398 * take up to 3 digits:
2400 for (i = 0; i < log10_all - log10_this; i++)
2403 printf("%d) ", cpu);
2406 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2407 #define TRACE_GRAPH_INDENT 2
2409 static void print_graph_proc(int pid, const char *comm)
2411 /* sign + log10(MAX_INT) + '\0' */
2417 sprintf(pid_str, "%d", pid);
2419 /* 1 stands for the "-" character */
2420 len = strlen(comm) + strlen(pid_str) + 1;
2422 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2423 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2425 /* First spaces to align center */
2426 for (i = 0; i < spaces / 2; i++)
2429 printf("%s-%s", comm, pid_str);
2431 /* Last spaces to align center */
2432 for (i = 0; i < spaces - (spaces / 2); i++)
2436 static struct record *
2437 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2438 struct record *next)
2440 struct format_field *field;
2441 struct event *event;
2446 type = trace_parse_common_type(next->data);
2447 event = trace_find_event(type);
2451 if (!(event->flags & EVENT_FL_ISFUNCRET))
2454 pid = parse_common_pid(next->data);
2455 field = find_field(event, "func");
2457 die("function return does not have field func");
2459 val = read_size(next->data + field->offset, field->size);
2461 if (cur_pid != pid || cur_func != val)
2464 /* this is a leaf, now advance the iterator */
2465 return trace_read_data(cpu);
2468 /* Signal a overhead of time execution to the output */
2469 static void print_graph_overhead(unsigned long long duration)
2471 /* Non nested entry or return */
2472 if (duration == ~0ULL)
2473 return (void)printf(" ");
2475 /* Duration exceeded 100 msecs */
2476 if (duration > 100000ULL)
2477 return (void)printf("! ");
2479 /* Duration exceeded 10 msecs */
2480 if (duration > 10000ULL)
2481 return (void)printf("+ ");
2486 static void print_graph_duration(unsigned long long duration)
2488 unsigned long usecs = duration / 1000;
2489 unsigned long nsecs_rem = duration % 1000;
2490 /* log10(ULONG_MAX) + '\0' */
2496 sprintf(msecs_str, "%lu", usecs);
2499 len = printf("%lu", usecs);
2501 /* Print nsecs (we don't want to exceed 7 numbers) */
2503 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2504 len += printf(".%s", nsecs_str);
2509 /* Print remaining spaces to fit the row's width */
2510 for (i = len; i < 7; i++)
2517 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2519 unsigned long long rettime, calltime;
2520 unsigned long long duration, depth;
2521 unsigned long long val;
2522 struct format_field *field;
2523 struct func_map *func;
2524 struct event *ret_event;
2528 type = trace_parse_common_type(ret_rec->data);
2529 ret_event = trace_find_event(type);
2531 field = find_field(ret_event, "rettime");
2533 die("can't find rettime in return graph");
2534 rettime = read_size(ret_rec->data + field->offset, field->size);
2536 field = find_field(ret_event, "calltime");
2538 die("can't find rettime in return graph");
2539 calltime = read_size(ret_rec->data + field->offset, field->size);
2541 duration = rettime - calltime;
2544 print_graph_overhead(duration);
2547 print_graph_duration(duration);
2549 field = find_field(event, "depth");
2551 die("can't find depth in entry graph");
2552 depth = read_size(data + field->offset, field->size);
2555 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2558 field = find_field(event, "func");
2560 die("can't find func in entry graph");
2561 val = read_size(data + field->offset, field->size);
2562 func = find_func(val);
2565 printf("%s();", func->func);
2567 printf("%llx();", val);
2570 static void print_graph_nested(struct event *event, void *data)
2572 struct format_field *field;
2573 unsigned long long depth;
2574 unsigned long long val;
2575 struct func_map *func;
2579 print_graph_overhead(-1);
2584 field = find_field(event, "depth");
2586 die("can't find depth in entry graph");
2587 depth = read_size(data + field->offset, field->size);
2590 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2593 field = find_field(event, "func");
2595 die("can't find func in entry graph");
2596 val = read_size(data + field->offset, field->size);
2597 func = find_func(val);
2600 printf("%s() {", func->func);
2602 printf("%llx() {", val);
2606 pretty_print_func_ent(void *data, int size, struct event *event,
2607 int cpu, int pid, const char *comm,
2608 unsigned long secs, unsigned long usecs)
2610 struct format_field *field;
2615 printf("%5lu.%06lu | ", secs, usecs);
2617 print_graph_cpu(cpu);
2618 print_graph_proc(pid, comm);
2622 field = find_field(event, "func");
2624 die("function entry does not have func field");
2626 val = read_size(data + field->offset, field->size);
2629 * peek_data may unmap the data pointer. Copy it first.
2631 copy_data = malloc_or_die(size);
2632 memcpy(copy_data, data, size);
2635 rec = trace_peek_data(cpu);
2637 rec = get_return_for_leaf(cpu, pid, val, rec);
2639 print_graph_entry_leaf(event, data, rec);
2643 print_graph_nested(event, data);
2649 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2650 int cpu, int pid, const char *comm,
2651 unsigned long secs, unsigned long usecs)
2653 unsigned long long rettime, calltime;
2654 unsigned long long duration, depth;
2655 struct format_field *field;
2658 printf("%5lu.%06lu | ", secs, usecs);
2660 print_graph_cpu(cpu);
2661 print_graph_proc(pid, comm);
2665 field = find_field(event, "rettime");
2667 die("can't find rettime in return graph");
2668 rettime = read_size(data + field->offset, field->size);
2670 field = find_field(event, "calltime");
2672 die("can't find calltime in return graph");
2673 calltime = read_size(data + field->offset, field->size);
2675 duration = rettime - calltime;
2678 print_graph_overhead(duration);
2681 print_graph_duration(duration);
2683 field = find_field(event, "depth");
2685 die("can't find depth in entry graph");
2686 depth = read_size(data + field->offset, field->size);
2689 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2696 pretty_print_func_graph(void *data, int size, struct event *event,
2697 int cpu, int pid, const char *comm,
2698 unsigned long secs, unsigned long usecs)
2700 if (event->flags & EVENT_FL_ISFUNCENT)
2701 pretty_print_func_ent(data, size, event,
2702 cpu, pid, comm, secs, usecs);
2703 else if (event->flags & EVENT_FL_ISFUNCRET)
2704 pretty_print_func_ret(data, size, event,
2705 cpu, pid, comm, secs, usecs);
2709 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2712 struct event *event;
2714 unsigned long usecs;
2718 secs = nsecs / NSECS_PER_SEC;
2719 nsecs -= secs * NSECS_PER_SEC;
2720 usecs = nsecs / NSECS_PER_USEC;
2722 type = trace_parse_common_type(data);
2724 event = trace_find_event(type);
2726 die("ug! no event found for type %d", type);
2728 pid = parse_common_pid(data);
2730 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2731 return pretty_print_func_graph(data, size, event, cpu,
2732 pid, comm, secs, usecs);
2734 printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
2736 secs, nsecs, event->name);
2738 pretty_print(data, size, event);
2742 static void print_fields(struct print_flag_sym *field)
2744 printf("{ %s, %s }", field->value, field->str);
2747 print_fields(field->next);
2751 static void print_args(struct print_arg *args)
2753 int print_paren = 1;
2755 switch (args->type) {
2760 printf("%s", args->atom.atom);
2763 printf("REC->%s", args->field.name);
2766 printf("__print_flags(");
2767 print_args(args->flags.field);
2768 printf(", %s, ", args->flags.delim);
2769 print_fields(args->flags.flags);
2773 printf("__print_symbolic(");
2774 print_args(args->symbol.field);
2776 print_fields(args->symbol.symbols);
2780 printf("__get_str(%s)", args->string.string);
2783 printf("(%s)", args->typecast.type);
2784 print_args(args->typecast.item);
2787 if (strcmp(args->op.op, ":") == 0)
2791 print_args(args->op.left);
2792 printf(" %s ", args->op.op);
2793 print_args(args->op.right);
2798 /* we should warn... */
2803 print_args(args->next);
2807 static void parse_header_field(char *type,
2808 int *offset, int *size)
2812 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2814 if (read_expected(EVENT_OP, (char *)":") < 0)
2817 if (read_expect_type(EVENT_ITEM, &token) < 0)
2821 if (read_expected(EVENT_ITEM, type) < 0)
2823 if (read_expected(EVENT_OP, (char *)";") < 0)
2825 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2827 if (read_expected(EVENT_OP, (char *)":") < 0)
2829 if (read_expect_type(EVENT_ITEM, &token) < 0)
2831 *offset = atoi(token);
2833 if (read_expected(EVENT_OP, (char *)";") < 0)
2835 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2837 if (read_expected(EVENT_OP, (char *)":") < 0)
2839 if (read_expect_type(EVENT_ITEM, &token) < 0)
2841 *size = atoi(token);
2843 if (read_expected(EVENT_OP, (char *)";") < 0)
2845 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2850 int parse_header_page(char *buf, unsigned long size)
2852 init_input_buf(buf, size);
2854 parse_header_field((char *)"timestamp", &header_page_ts_offset,
2855 &header_page_ts_size);
2856 parse_header_field((char *)"commit", &header_page_size_offset,
2857 &header_page_size_size);
2858 parse_header_field((char *)"data", &header_page_data_offset,
2859 &header_page_data_size);
2864 int parse_ftrace_file(char *buf, unsigned long size)
2866 struct format_field *field;
2867 struct print_arg *arg, **list;
2868 struct event *event;
2871 init_input_buf(buf, size);
2873 event = alloc_event();
2877 event->flags |= EVENT_FL_ISFTRACE;
2879 event->name = event_read_name();
2881 die("failed to read ftrace event name");
2883 if (strcmp(event->name, "function") == 0)
2884 event->flags |= EVENT_FL_ISFUNC;
2886 else if (strcmp(event->name, "funcgraph_entry") == 0)
2887 event->flags |= EVENT_FL_ISFUNCENT;
2889 else if (strcmp(event->name, "funcgraph_exit") == 0)
2890 event->flags |= EVENT_FL_ISFUNCRET;
2892 else if (strcmp(event->name, "bprint") == 0)
2893 event->flags |= EVENT_FL_ISBPRINT;
2895 event->id = event_read_id();
2897 die("failed to read ftrace event id");
2901 ret = event_read_format(event);
2903 die("failed to read ftrace event format");
2905 ret = event_read_print(event);
2907 die("failed to read ftrace event print fmt");
2910 * The arguments for ftrace files are parsed by the fields.
2911 * Set up the fields as their arguments.
2913 list = &event->print_fmt.args;
2914 for (field = event->format.fields; field; field = field->next) {
2915 arg = malloc_or_die(sizeof(*arg));
2916 memset(arg, 0, sizeof(*arg));
2919 arg->type = PRINT_FIELD;
2920 arg->field.name = field->name;
2921 arg->field.field = field;
2926 int parse_event_file(char *buf, unsigned long size, char *system__unused __unused)
2928 struct event *event;
2931 init_input_buf(buf, size);
2933 event = alloc_event();
2937 event->name = event_read_name();
2939 die("failed to read event name");
2941 event->id = event_read_id();
2943 die("failed to read event id");
2945 ret = event_read_format(event);
2947 die("failed to read event format");
2949 ret = event_read_print(event);
2951 die("failed to read event print fmt");
2953 #define PRINT_ARGS 0
2954 if (PRINT_ARGS && event->print_fmt.args)
2955 print_args(event->print_fmt.args);
2961 void parse_set_info(int nr_cpus, int long_sz)
2964 long_size = long_sz;