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, const 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, const 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, const char *str)
673 return __read_expected(expect, str, 1);
676 static int read_expected_item(enum event_type expect, const 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 field_is_string(struct format_field *field)
726 if ((field->flags & FIELD_IS_ARRAY) &&
727 (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
728 !strstr(field->type, "s8")))
734 static int field_is_dynamic(struct format_field *field)
736 if (!strcmp(field->type, "__data_loc"))
742 static int event_read_fields(struct event *event, struct format_field **fields)
744 struct format_field *field = NULL;
745 enum event_type type;
751 type = read_token(&token);
752 if (type == EVENT_NEWLINE) {
759 if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
763 type = read_token(&token);
765 * The ftrace fields may still use the "special" name.
768 if (event->flags & EVENT_FL_ISFTRACE &&
769 type == EVENT_ITEM && strcmp(token, "special") == 0) {
771 type = read_token(&token);
774 if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
777 if (read_expect_type(EVENT_ITEM, &token) < 0)
782 field = malloc_or_die(sizeof(*field));
783 memset(field, 0, sizeof(*field));
785 /* read the rest of the type */
787 type = read_token(&token);
788 if (type == EVENT_ITEM ||
789 (type == EVENT_OP && strcmp(token, "*") == 0) ||
791 * Some of the ftrace fields are broken and have
792 * an illegal "." in them.
794 (event->flags & EVENT_FL_ISFTRACE &&
795 type == EVENT_OP && strcmp(token, ".") == 0)) {
797 if (strcmp(token, "*") == 0)
798 field->flags |= FIELD_IS_POINTER;
801 field->type = realloc(field->type,
802 strlen(field->type) +
803 strlen(last_token) + 2);
804 strcat(field->type, " ");
805 strcat(field->type, last_token);
807 field->type = last_token;
816 die("no type found");
819 field->name = last_token;
821 if (test_type(type, EVENT_OP))
824 if (strcmp(token, "[") == 0) {
825 enum event_type last_type = type;
826 char *brackets = token;
829 field->flags |= FIELD_IS_ARRAY;
831 type = read_token(&token);
832 while (strcmp(token, "]") != 0) {
833 if (last_type == EVENT_ITEM &&
840 brackets = realloc(brackets,
842 strlen(token) + len);
844 strcat(brackets, " ");
845 strcat(brackets, token);
847 type = read_token(&token);
848 if (type == EVENT_NONE) {
849 die("failed to find token");
856 brackets = realloc(brackets, strlen(brackets) + 2);
857 strcat(brackets, "]");
859 /* add brackets to type */
861 type = read_token(&token);
863 * If the next token is not an OP, then it is of
864 * the format: type [] item;
866 if (type == EVENT_ITEM) {
867 field->type = realloc(field->type,
868 strlen(field->type) +
869 strlen(field->name) +
870 strlen(brackets) + 2);
871 strcat(field->type, " ");
872 strcat(field->type, field->name);
873 free_token(field->name);
874 strcat(field->type, brackets);
876 type = read_token(&token);
878 field->type = realloc(field->type,
879 strlen(field->type) +
880 strlen(brackets) + 1);
881 strcat(field->type, brackets);
886 if (field_is_string(field)) {
887 field->flags |= FIELD_IS_STRING;
888 if (field_is_dynamic(field))
889 field->flags |= FIELD_IS_DYNAMIC;
892 if (test_type_token(type, token, EVENT_OP, (char *)";"))
896 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
899 if (read_expected(EVENT_OP, (char *)":") < 0)
902 if (read_expect_type(EVENT_ITEM, &token))
904 field->offset = strtoul(token, NULL, 0);
907 if (read_expected(EVENT_OP, (char *)";") < 0)
910 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
913 if (read_expected(EVENT_OP, (char *)":") < 0)
916 if (read_expect_type(EVENT_ITEM, &token))
918 field->size = strtoul(token, NULL, 0);
921 if (read_expected(EVENT_OP, (char *)";") < 0)
924 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
927 if (read_expected(EVENT_OP, (char *)":") < 0)
930 if (read_expect_type(EVENT_ITEM, &token))
932 if (strtoul(token, NULL, 0))
933 field->flags |= FIELD_IS_SIGNED;
936 if (read_expected(EVENT_OP, (char *)";") < 0)
939 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
944 fields = &field->next;
958 static int event_read_format(struct event *event)
963 if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
966 if (read_expected(EVENT_OP, (char *)":") < 0)
969 if (read_expect_type(EVENT_NEWLINE, &token))
973 ret = event_read_fields(event, &event->format.common_fields);
976 event->format.nr_common = ret;
978 ret = event_read_fields(event, &event->format.fields);
981 event->format.nr_fields = ret;
991 process_arg_token(struct event *event, struct print_arg *arg,
992 char **tok, enum event_type type);
994 static enum event_type
995 process_arg(struct event *event, struct print_arg *arg, char **tok)
997 enum event_type type;
1000 type = read_token(&token);
1003 return process_arg_token(event, arg, tok, type);
1006 static enum event_type
1007 process_cond(struct event *event, struct print_arg *top, char **tok)
1009 struct print_arg *arg, *left, *right;
1010 enum event_type type;
1013 arg = malloc_or_die(sizeof(*arg));
1014 memset(arg, 0, sizeof(*arg));
1016 left = malloc_or_die(sizeof(*left));
1018 right = malloc_or_die(sizeof(*right));
1020 arg->type = PRINT_OP;
1021 arg->op.left = left;
1022 arg->op.right = right;
1025 type = process_arg(event, left, &token);
1026 if (test_type_token(type, token, EVENT_OP, (char *)":"))
1031 type = process_arg(event, right, &token);
1033 top->op.right = arg;
1046 static int get_op_prio(char *op)
1057 /* '>>' and '<<' are 8 */
1061 /* '==' and '!=' are 10 */
1071 die("unknown op '%c'", op[0]);
1075 if (strcmp(op, "++") == 0 ||
1076 strcmp(op, "--") == 0) {
1078 } else if (strcmp(op, ">>") == 0 ||
1079 strcmp(op, "<<") == 0) {
1081 } else if (strcmp(op, ">=") == 0 ||
1082 strcmp(op, "<=") == 0) {
1084 } else if (strcmp(op, "==") == 0 ||
1085 strcmp(op, "!=") == 0) {
1087 } else if (strcmp(op, "&&") == 0) {
1089 } else if (strcmp(op, "||") == 0) {
1092 die("unknown op '%s'", op);
1098 static void set_op_prio(struct print_arg *arg)
1101 /* single ops are the greatest */
1102 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1107 arg->op.prio = get_op_prio(arg->op.op);
1110 static enum event_type
1111 process_op(struct event *event, struct print_arg *arg, char **tok)
1113 struct print_arg *left, *right = NULL;
1114 enum event_type type;
1117 /* the op is passed in via tok */
1120 if (arg->type == PRINT_OP && !arg->op.left) {
1121 /* handle single op */
1123 die("bad op token %s", token);
1132 die("bad op token %s", token);
1136 /* make an empty left */
1137 left = malloc_or_die(sizeof(*left));
1138 left->type = PRINT_NULL;
1139 arg->op.left = left;
1141 right = malloc_or_die(sizeof(*right));
1142 arg->op.right = right;
1144 type = process_arg(event, right, tok);
1146 } else if (strcmp(token, "?") == 0) {
1148 left = malloc_or_die(sizeof(*left));
1149 /* copy the top arg to the left */
1152 arg->type = PRINT_OP;
1154 arg->op.left = left;
1157 type = process_cond(event, arg, tok);
1159 } else if (strcmp(token, ">>") == 0 ||
1160 strcmp(token, "<<") == 0 ||
1161 strcmp(token, "&") == 0 ||
1162 strcmp(token, "|") == 0 ||
1163 strcmp(token, "&&") == 0 ||
1164 strcmp(token, "||") == 0 ||
1165 strcmp(token, "-") == 0 ||
1166 strcmp(token, "+") == 0 ||
1167 strcmp(token, "*") == 0 ||
1168 strcmp(token, "^") == 0 ||
1169 strcmp(token, "/") == 0 ||
1170 strcmp(token, "==") == 0 ||
1171 strcmp(token, "!=") == 0) {
1173 left = malloc_or_die(sizeof(*left));
1175 /* copy the top arg to the left */
1178 arg->type = PRINT_OP;
1180 arg->op.left = left;
1184 right = malloc_or_die(sizeof(*right));
1186 type = process_arg(event, right, tok);
1188 arg->op.right = right;
1191 die("unknown op '%s'", token);
1192 /* the arg is now the left side */
1197 if (type == EVENT_OP) {
1200 /* higher prios need to be closer to the root */
1201 prio = get_op_prio(*tok);
1203 if (prio > arg->op.prio)
1204 return process_op(event, arg, tok);
1206 return process_op(event, right, tok);
1212 static enum event_type
1213 process_entry(struct event *event __unused, struct print_arg *arg,
1216 enum event_type type;
1220 if (read_expected(EVENT_OP, (char *)"->") < 0)
1223 if (read_expect_type(EVENT_ITEM, &token) < 0)
1227 arg->type = PRINT_FIELD;
1228 arg->field.name = field;
1230 type = read_token(&token);
1240 static char *arg_eval (struct print_arg *arg);
1242 static long long arg_num_eval(struct print_arg *arg)
1244 long long left, right;
1247 switch (arg->type) {
1249 val = strtoll(arg->atom.atom, NULL, 0);
1252 val = arg_num_eval(arg->typecast.item);
1255 switch (arg->op.op[0]) {
1257 left = arg_num_eval(arg->op.left);
1258 right = arg_num_eval(arg->op.right);
1260 val = left || right;
1265 left = arg_num_eval(arg->op.left);
1266 right = arg_num_eval(arg->op.right);
1268 val = left && right;
1273 left = arg_num_eval(arg->op.left);
1274 right = arg_num_eval(arg->op.right);
1275 switch (arg->op.op[1]) {
1280 val = left << right;
1283 val = left <= right;
1286 die("unknown op '%s'", arg->op.op);
1290 left = arg_num_eval(arg->op.left);
1291 right = arg_num_eval(arg->op.right);
1292 switch (arg->op.op[1]) {
1297 val = left >> right;
1300 val = left >= right;
1303 die("unknown op '%s'", arg->op.op);
1307 left = arg_num_eval(arg->op.left);
1308 right = arg_num_eval(arg->op.right);
1310 if (arg->op.op[1] != '=')
1311 die("unknown op '%s'", arg->op.op);
1313 val = left == right;
1316 left = arg_num_eval(arg->op.left);
1317 right = arg_num_eval(arg->op.right);
1319 switch (arg->op.op[1]) {
1321 val = left != right;
1324 die("unknown op '%s'", arg->op.op);
1328 die("unknown op '%s'", arg->op.op);
1333 case PRINT_FIELD ... PRINT_SYMBOL:
1336 die("invalid eval type %d", arg->type);
1342 static char *arg_eval (struct print_arg *arg)
1345 static char buf[20];
1347 switch (arg->type) {
1349 return arg->atom.atom;
1351 return arg_eval(arg->typecast.item);
1353 val = arg_num_eval(arg);
1354 sprintf(buf, "%lld", val);
1358 case PRINT_FIELD ... PRINT_SYMBOL:
1361 die("invalid eval type %d", arg->type);
1368 static enum event_type
1369 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1371 enum event_type type;
1372 struct print_arg *arg = NULL;
1373 struct print_flag_sym *field;
1379 type = read_token_item(&token);
1380 if (test_type_token(type, token, EVENT_OP, (char *)"{"))
1383 arg = malloc_or_die(sizeof(*arg));
1386 type = process_arg(event, arg, &token);
1387 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1390 field = malloc_or_die(sizeof(*field));
1391 memset(field, 0, sizeof(field));
1393 value = arg_eval(arg);
1394 field->value = strdup(value);
1397 type = process_arg(event, arg, &token);
1398 if (test_type_token(type, token, EVENT_OP, (char *)"}"))
1401 value = arg_eval(arg);
1402 field->str = strdup(value);
1407 list = &field->next;
1410 type = read_token_item(&token);
1411 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1423 static enum event_type
1424 process_flags(struct event *event, struct print_arg *arg, char **tok)
1426 struct print_arg *field;
1427 enum event_type type;
1430 memset(arg, 0, sizeof(*arg));
1431 arg->type = PRINT_FLAGS;
1433 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1436 field = malloc_or_die(sizeof(*field));
1438 type = process_arg(event, field, &token);
1439 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1442 arg->flags.field = field;
1444 type = read_token_item(&token);
1445 if (event_item_type(type)) {
1446 arg->flags.delim = token;
1447 type = read_token_item(&token);
1450 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1453 type = process_fields(event, &arg->flags.flags, &token);
1454 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1458 type = read_token_item(tok);
1466 static enum event_type
1467 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1469 struct print_arg *field;
1470 enum event_type type;
1473 memset(arg, 0, sizeof(*arg));
1474 arg->type = PRINT_SYMBOL;
1476 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1479 field = malloc_or_die(sizeof(*field));
1481 type = process_arg(event, field, &token);
1482 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1485 arg->symbol.field = field;
1487 type = process_fields(event, &arg->symbol.symbols, &token);
1488 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1492 type = read_token_item(tok);
1500 static enum event_type
1501 process_paren(struct event *event, struct print_arg *arg, char **tok)
1503 struct print_arg *item_arg;
1504 enum event_type type;
1508 type = process_arg(event, arg, &token);
1510 if (type == EVENT_ERROR)
1513 if (type == EVENT_OP) {
1514 /* handle the ptr casts */
1515 if (!strcmp(token, "*")) {
1517 * FIXME: should we zapp whitespaces before ')' ?
1518 * (may require a peek_token_item())
1520 if (__peek_char() == ')') {
1523 type = read_token_item(&token);
1527 type = process_op(event, arg, &token);
1529 if (type == EVENT_ERROR)
1534 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1540 type = read_token_item(&token);
1543 * If the next token is an item or another open paren, then
1544 * this was a typecast.
1546 if (event_item_type(type) ||
1547 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1549 /* make this a typecast and contine */
1551 /* prevous must be an atom */
1552 if (arg->type != PRINT_ATOM)
1553 die("previous needed to be PRINT_ATOM");
1555 item_arg = malloc_or_die(sizeof(*item_arg));
1557 arg->type = PRINT_TYPE;
1559 char *old = arg->atom.atom;
1561 arg->atom.atom = malloc_or_die(strlen(old + 3));
1562 sprintf(arg->atom.atom, "%s *", old);
1565 arg->typecast.type = arg->atom.atom;
1566 arg->typecast.item = item_arg;
1567 type = process_arg_token(event, item_arg, &token, type);
1576 static enum event_type
1577 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1579 enum event_type type;
1582 if (read_expected(EVENT_DELIM, (char *)"(") < 0)
1585 if (read_expect_type(EVENT_ITEM, &token) < 0)
1588 arg->type = PRINT_STRING;
1589 arg->string.string = token;
1590 arg->string.offset = -1;
1592 if (read_expected(EVENT_DELIM, (char *)")") < 0)
1595 type = read_token(&token);
1605 process_arg_token(struct event *event, struct print_arg *arg,
1606 char **tok, enum event_type type)
1615 if (strcmp(token, "REC") == 0) {
1617 type = process_entry(event, arg, &token);
1618 } else if (strcmp(token, "__print_flags") == 0) {
1620 type = process_flags(event, arg, &token);
1621 } else if (strcmp(token, "__print_symbolic") == 0) {
1623 type = process_symbols(event, arg, &token);
1624 } else if (strcmp(token, "__get_str") == 0) {
1626 type = process_str(event, arg, &token);
1629 /* test the next token */
1630 type = read_token_item(&token);
1632 /* atoms can be more than one token long */
1633 while (type == EVENT_ITEM) {
1634 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1636 strcat(atom, token);
1638 type = read_token_item(&token);
1641 /* todo, test for function */
1643 arg->type = PRINT_ATOM;
1644 arg->atom.atom = atom;
1649 arg->type = PRINT_ATOM;
1650 arg->atom.atom = token;
1651 type = read_token_item(&token);
1654 if (strcmp(token, "(") == 0) {
1656 type = process_paren(event, arg, &token);
1660 /* handle single ops */
1661 arg->type = PRINT_OP;
1663 arg->op.left = NULL;
1664 type = process_op(event, arg, &token);
1668 case EVENT_ERROR ... EVENT_NEWLINE:
1670 die("unexpected type %d", type);
1677 static int event_read_print_args(struct event *event, struct print_arg **list)
1679 enum event_type type;
1680 struct print_arg *arg;
1685 arg = malloc_or_die(sizeof(*arg));
1686 memset(arg, 0, sizeof(*arg));
1688 type = process_arg(event, arg, &token);
1690 if (type == EVENT_ERROR) {
1698 if (type == EVENT_OP) {
1699 type = process_op(event, arg, &token);
1704 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1711 } while (type != EVENT_NONE);
1713 if (type != EVENT_NONE)
1719 static int event_read_print(struct event *event)
1721 enum event_type type;
1725 if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
1728 if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
1731 if (read_expected(EVENT_OP, (char *)":") < 0)
1734 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1738 event->print_fmt.format = token;
1739 event->print_fmt.args = NULL;
1741 /* ok to have no arg */
1742 type = read_token_item(&token);
1744 if (type == EVENT_NONE)
1747 /* Handle concatination of print lines */
1748 if (type == EVENT_DQUOTE) {
1751 cat = malloc_or_die(strlen(event->print_fmt.format) +
1753 strcpy(cat, event->print_fmt.format);
1756 free_token(event->print_fmt.format);
1757 event->print_fmt.format = NULL;
1762 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1767 ret = event_read_print_args(event, &event->print_fmt.args);
1778 static struct format_field *
1779 find_common_field(struct event *event, const char *name)
1781 struct format_field *format;
1783 for (format = event->format.common_fields;
1784 format; format = format->next) {
1785 if (strcmp(format->name, name) == 0)
1792 static struct format_field *
1793 find_field(struct event *event, const char *name)
1795 struct format_field *format;
1797 for (format = event->format.fields;
1798 format; format = format->next) {
1799 if (strcmp(format->name, name) == 0)
1806 static struct format_field *
1807 find_any_field(struct event *event, const char *name)
1809 struct format_field *format;
1811 format = find_common_field(event, name);
1814 return find_field(event, name);
1817 static unsigned long long read_size(void *ptr, int size)
1821 return *(unsigned char *)ptr;
1823 return data2host2(ptr);
1825 return data2host4(ptr);
1827 return data2host8(ptr);
1835 raw_field_value(struct event *event, const char *name, void *data)
1837 struct format_field *field;
1839 field = find_any_field(event, name);
1843 return read_size(data + field->offset, field->size);
1846 void *raw_field_ptr(struct event *event, const char *name, void *data)
1848 struct format_field *field;
1850 field = find_any_field(event, name);
1854 return data + field->offset;
1857 static int get_common_info(const char *type, int *offset, int *size)
1859 struct event *event;
1860 struct format_field *field;
1863 * All events should have the same common elements.
1864 * Pick any event to find where the type is;
1867 die("no event_list!");
1870 field = find_common_field(event, type);
1872 die("field '%s' not found", type);
1874 *offset = field->offset;
1875 *size = field->size;
1880 int trace_parse_common_type(void *data)
1882 static int type_offset;
1883 static int type_size;
1887 ret = get_common_info("common_type",
1893 return read_size(data + type_offset, type_size);
1896 static int parse_common_pid(void *data)
1898 static int pid_offset;
1899 static int pid_size;
1903 ret = get_common_info("common_pid",
1910 return read_size(data + pid_offset, pid_size);
1913 struct event *trace_find_event(int id)
1915 struct event *event;
1917 for (event = event_list; event; event = event->next) {
1918 if (event->id == id)
1924 static unsigned long long eval_num_arg(void *data, int size,
1925 struct event *event, struct print_arg *arg)
1927 unsigned long long val = 0;
1928 unsigned long long left, right;
1930 switch (arg->type) {
1935 return strtoull(arg->atom.atom, NULL, 0);
1937 if (!arg->field.field) {
1938 arg->field.field = find_any_field(event, arg->field.name);
1939 if (!arg->field.field)
1940 die("field %s not found", arg->field.name);
1942 /* must be a number */
1943 val = read_size(data + arg->field.field->offset,
1944 arg->field.field->size);
1950 return eval_num_arg(data, size, event, arg->typecast.item);
1955 left = eval_num_arg(data, size, event, arg->op.left);
1956 right = eval_num_arg(data, size, event, arg->op.right);
1957 switch (arg->op.op[0]) {
1960 val = left || right;
1966 val = left && right;
1971 switch (arg->op.op[1]) {
1976 val = left << right;
1979 val = left <= right;
1982 die("unknown op '%s'", arg->op.op);
1986 switch (arg->op.op[1]) {
1991 val = left >> right;
1994 val = left >= right;
1997 die("unknown op '%s'", arg->op.op);
2001 if (arg->op.op[1] != '=')
2002 die("unknown op '%s'", arg->op.op);
2003 val = left == right;
2006 die("unknown op '%s'", arg->op.op);
2009 default: /* not sure what to do there */
2017 unsigned long long value;
2020 static const struct flag flags[] = {
2021 { "HI_SOFTIRQ", 0 },
2022 { "TIMER_SOFTIRQ", 1 },
2023 { "NET_TX_SOFTIRQ", 2 },
2024 { "NET_RX_SOFTIRQ", 3 },
2025 { "BLOCK_SOFTIRQ", 4 },
2026 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
2027 { "TASKLET_SOFTIRQ", 6 },
2028 { "SCHED_SOFTIRQ", 7 },
2029 { "HRTIMER_SOFTIRQ", 8 },
2030 { "RCU_SOFTIRQ", 9 },
2032 { "HRTIMER_NORESTART", 0 },
2033 { "HRTIMER_RESTART", 1 },
2036 static unsigned long long eval_flag(const char *flag)
2041 * Some flags in the format files do not get converted.
2042 * If the flag is not numeric, see if it is something that
2043 * we already know about.
2045 if (isdigit(flag[0]))
2046 return strtoull(flag, NULL, 0);
2048 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
2049 if (strcmp(flags[i].name, flag) == 0)
2050 return flags[i].value;
2055 static void print_str_arg(void *data, int size,
2056 struct event *event, struct print_arg *arg)
2058 struct print_flag_sym *flag;
2059 unsigned long long val, fval;
2063 switch (arg->type) {
2068 printf("%s", arg->atom.atom);
2071 if (!arg->field.field) {
2072 arg->field.field = find_any_field(event, arg->field.name);
2073 if (!arg->field.field)
2074 die("field %s not found", arg->field.name);
2076 str = malloc_or_die(arg->field.field->size + 1);
2077 memcpy(str, data + arg->field.field->offset,
2078 arg->field.field->size);
2079 str[arg->field.field->size] = 0;
2084 val = eval_num_arg(data, size, event, arg->flags.field);
2086 for (flag = arg->flags.flags; flag; flag = flag->next) {
2087 fval = eval_flag(flag->value);
2088 if (!val && !fval) {
2089 printf("%s", flag->str);
2092 if (fval && (val & fval) == fval) {
2093 if (print && arg->flags.delim)
2094 printf("%s", arg->flags.delim);
2095 printf("%s", flag->str);
2102 val = eval_num_arg(data, size, event, arg->symbol.field);
2103 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2104 fval = eval_flag(flag->value);
2106 printf("%s", flag->str);
2114 case PRINT_STRING: {
2117 if (arg->string.offset == -1) {
2118 struct format_field *f;
2120 f = find_any_field(event, arg->string.string);
2121 arg->string.offset = f->offset;
2123 str_offset = *(int *)(data + arg->string.offset);
2124 str_offset &= 0xffff;
2125 printf("%s", ((char *)data) + str_offset);
2130 * The only op for string should be ? :
2132 if (arg->op.op[0] != '?')
2134 val = eval_num_arg(data, size, event, arg->op.left);
2136 print_str_arg(data, size, event, arg->op.right->op.left);
2138 print_str_arg(data, size, event, arg->op.right->op.right);
2146 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2148 static struct format_field *field, *ip_field;
2149 struct print_arg *args, *arg, **next;
2150 unsigned long long ip, val;
2155 field = find_field(event, "buf");
2157 die("can't find buffer field for binary printk");
2158 ip_field = find_field(event, "ip");
2160 die("can't find ip field for binary printk");
2163 ip = read_size(data + ip_field->offset, ip_field->size);
2166 * The first arg is the IP pointer.
2168 args = malloc_or_die(sizeof(*args));
2173 arg->type = PRINT_ATOM;
2174 arg->atom.atom = malloc_or_die(32);
2175 sprintf(arg->atom.atom, "%lld", ip);
2177 /* skip the first "%pf : " */
2178 for (ptr = fmt + 6, bptr = data + field->offset;
2179 bptr < data + size && *ptr; ptr++) {
2203 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2215 val = read_size(bptr, ls);
2217 arg = malloc_or_die(sizeof(*arg));
2219 arg->type = PRINT_ATOM;
2220 arg->atom.atom = malloc_or_die(32);
2221 sprintf(arg->atom.atom, "%lld", val);
2226 arg = malloc_or_die(sizeof(*arg));
2228 arg->type = PRINT_STRING;
2229 arg->string.string = strdup(bptr);
2230 bptr += strlen(bptr) + 1;
2242 static void free_args(struct print_arg *args)
2244 struct print_arg *next;
2249 if (args->type == PRINT_ATOM)
2250 free(args->atom.atom);
2252 free(args->string.string);
2258 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2260 unsigned long long addr;
2261 static struct format_field *field;
2262 struct printk_map *printk;
2267 field = find_field(event, "fmt");
2269 die("can't find format field for binary printk");
2270 printf("field->offset = %d size=%d\n", field->offset, field->size);
2273 addr = read_size(data + field->offset, field->size);
2275 printk = find_printk(addr);
2277 format = malloc_or_die(45);
2278 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2284 /* Remove any quotes. */
2287 format = malloc_or_die(strlen(p) + 10);
2288 sprintf(format, "%s : %s", "%pf", p);
2289 /* remove ending quotes and new line since we will add one too */
2290 p = format + strlen(format) - 1;
2295 if (strcmp(p, "\\n") == 0)
2301 static void pretty_print(void *data, int size, struct event *event)
2303 struct print_fmt *print_fmt = &event->print_fmt;
2304 struct print_arg *arg = print_fmt->args;
2305 struct print_arg *args = NULL;
2306 const char *ptr = print_fmt->format;
2307 unsigned long long val;
2308 struct func_map *func;
2309 const char *saveptr;
2310 char *bprint_fmt = NULL;
2316 if (event->flags & EVENT_FL_ISFUNC)
2317 ptr = " %pF <-- %pF";
2319 if (event->flags & EVENT_FL_ISBPRINT) {
2320 bprint_fmt = get_bprint_format(data, size, event);
2321 args = make_bprint_args(bprint_fmt, data, size, event);
2326 for (; *ptr; ptr++) {
2353 if (*(ptr+1) == 'F' ||
2366 die("no argument match");
2368 len = ((unsigned long)ptr + 1) -
2369 (unsigned long)saveptr;
2371 /* should never happen */
2375 memcpy(format, saveptr, len);
2378 val = eval_num_arg(data, size, event, arg);
2382 func = find_func(val);
2384 printf("%s", func->func);
2385 if (show_func == 'F')
2393 printf(format, (int)val);
2396 printf(format, (long)val);
2399 printf(format, (long long)val);
2402 die("bad count (%d)", ls);
2407 die("no matching argument");
2409 print_str_arg(data, size, event, arg);
2413 printf(">%c<", *ptr);
2426 static inline int log10_cpu(int nb)
2435 /* taken from Linux, written by Frederic Weisbecker */
2436 static void print_graph_cpu(int cpu)
2439 int log10_this = log10_cpu(cpu);
2440 int log10_all = log10_cpu(cpus);
2444 * Start with a space character - to make it stand out
2445 * to the right a bit when trace output is pasted into
2451 * Tricky - we space the CPU field according to the max
2452 * number of online CPUs. On a 2-cpu system it would take
2453 * a maximum of 1 digit - on a 128 cpu system it would
2454 * take up to 3 digits:
2456 for (i = 0; i < log10_all - log10_this; i++)
2459 printf("%d) ", cpu);
2462 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2463 #define TRACE_GRAPH_INDENT 2
2465 static void print_graph_proc(int pid, const char *comm)
2467 /* sign + log10(MAX_INT) + '\0' */
2473 sprintf(pid_str, "%d", pid);
2475 /* 1 stands for the "-" character */
2476 len = strlen(comm) + strlen(pid_str) + 1;
2478 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2479 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2481 /* First spaces to align center */
2482 for (i = 0; i < spaces / 2; i++)
2485 printf("%s-%s", comm, pid_str);
2487 /* Last spaces to align center */
2488 for (i = 0; i < spaces - (spaces / 2); i++)
2492 static struct record *
2493 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2494 struct record *next)
2496 struct format_field *field;
2497 struct event *event;
2502 type = trace_parse_common_type(next->data);
2503 event = trace_find_event(type);
2507 if (!(event->flags & EVENT_FL_ISFUNCRET))
2510 pid = parse_common_pid(next->data);
2511 field = find_field(event, "func");
2513 die("function return does not have field func");
2515 val = read_size(next->data + field->offset, field->size);
2517 if (cur_pid != pid || cur_func != val)
2520 /* this is a leaf, now advance the iterator */
2521 return trace_read_data(cpu);
2524 /* Signal a overhead of time execution to the output */
2525 static void print_graph_overhead(unsigned long long duration)
2527 /* Non nested entry or return */
2528 if (duration == ~0ULL)
2529 return (void)printf(" ");
2531 /* Duration exceeded 100 msecs */
2532 if (duration > 100000ULL)
2533 return (void)printf("! ");
2535 /* Duration exceeded 10 msecs */
2536 if (duration > 10000ULL)
2537 return (void)printf("+ ");
2542 static void print_graph_duration(unsigned long long duration)
2544 unsigned long usecs = duration / 1000;
2545 unsigned long nsecs_rem = duration % 1000;
2546 /* log10(ULONG_MAX) + '\0' */
2552 sprintf(msecs_str, "%lu", usecs);
2555 len = printf("%lu", usecs);
2557 /* Print nsecs (we don't want to exceed 7 numbers) */
2559 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2560 len += printf(".%s", nsecs_str);
2565 /* Print remaining spaces to fit the row's width */
2566 for (i = len; i < 7; i++)
2573 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2575 unsigned long long rettime, calltime;
2576 unsigned long long duration, depth;
2577 unsigned long long val;
2578 struct format_field *field;
2579 struct func_map *func;
2580 struct event *ret_event;
2584 type = trace_parse_common_type(ret_rec->data);
2585 ret_event = trace_find_event(type);
2587 field = find_field(ret_event, "rettime");
2589 die("can't find rettime in return graph");
2590 rettime = read_size(ret_rec->data + field->offset, field->size);
2592 field = find_field(ret_event, "calltime");
2594 die("can't find rettime in return graph");
2595 calltime = read_size(ret_rec->data + field->offset, field->size);
2597 duration = rettime - calltime;
2600 print_graph_overhead(duration);
2603 print_graph_duration(duration);
2605 field = find_field(event, "depth");
2607 die("can't find depth in entry graph");
2608 depth = read_size(data + field->offset, field->size);
2611 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2614 field = find_field(event, "func");
2616 die("can't find func in entry graph");
2617 val = read_size(data + field->offset, field->size);
2618 func = find_func(val);
2621 printf("%s();", func->func);
2623 printf("%llx();", val);
2626 static void print_graph_nested(struct event *event, void *data)
2628 struct format_field *field;
2629 unsigned long long depth;
2630 unsigned long long val;
2631 struct func_map *func;
2635 print_graph_overhead(-1);
2640 field = find_field(event, "depth");
2642 die("can't find depth in entry graph");
2643 depth = read_size(data + field->offset, field->size);
2646 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2649 field = find_field(event, "func");
2651 die("can't find func in entry graph");
2652 val = read_size(data + field->offset, field->size);
2653 func = find_func(val);
2656 printf("%s() {", func->func);
2658 printf("%llx() {", val);
2662 pretty_print_func_ent(void *data, int size, struct event *event,
2663 int cpu, int pid, const char *comm,
2664 unsigned long secs, unsigned long usecs)
2666 struct format_field *field;
2671 printf("%5lu.%06lu | ", secs, usecs);
2673 print_graph_cpu(cpu);
2674 print_graph_proc(pid, comm);
2678 field = find_field(event, "func");
2680 die("function entry does not have func field");
2682 val = read_size(data + field->offset, field->size);
2685 * peek_data may unmap the data pointer. Copy it first.
2687 copy_data = malloc_or_die(size);
2688 memcpy(copy_data, data, size);
2691 rec = trace_peek_data(cpu);
2693 rec = get_return_for_leaf(cpu, pid, val, rec);
2695 print_graph_entry_leaf(event, data, rec);
2699 print_graph_nested(event, data);
2705 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2706 int cpu, int pid, const char *comm,
2707 unsigned long secs, unsigned long usecs)
2709 unsigned long long rettime, calltime;
2710 unsigned long long duration, depth;
2711 struct format_field *field;
2714 printf("%5lu.%06lu | ", secs, usecs);
2716 print_graph_cpu(cpu);
2717 print_graph_proc(pid, comm);
2721 field = find_field(event, "rettime");
2723 die("can't find rettime in return graph");
2724 rettime = read_size(data + field->offset, field->size);
2726 field = find_field(event, "calltime");
2728 die("can't find calltime in return graph");
2729 calltime = read_size(data + field->offset, field->size);
2731 duration = rettime - calltime;
2734 print_graph_overhead(duration);
2737 print_graph_duration(duration);
2739 field = find_field(event, "depth");
2741 die("can't find depth in entry graph");
2742 depth = read_size(data + field->offset, field->size);
2745 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2752 pretty_print_func_graph(void *data, int size, struct event *event,
2753 int cpu, int pid, const char *comm,
2754 unsigned long secs, unsigned long usecs)
2756 if (event->flags & EVENT_FL_ISFUNCENT)
2757 pretty_print_func_ent(data, size, event,
2758 cpu, pid, comm, secs, usecs);
2759 else if (event->flags & EVENT_FL_ISFUNCRET)
2760 pretty_print_func_ret(data, size, event,
2761 cpu, pid, comm, secs, usecs);
2765 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2768 struct event *event;
2770 unsigned long usecs;
2774 secs = nsecs / NSECS_PER_SEC;
2775 nsecs -= secs * NSECS_PER_SEC;
2776 usecs = nsecs / NSECS_PER_USEC;
2778 type = trace_parse_common_type(data);
2780 event = trace_find_event(type);
2782 printf("ug! no event found for type %d\n", type);
2786 pid = parse_common_pid(data);
2788 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2789 return pretty_print_func_graph(data, size, event, cpu,
2790 pid, comm, secs, usecs);
2792 printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
2794 secs, nsecs, event->name);
2796 pretty_print(data, size, event);
2800 static void print_fields(struct print_flag_sym *field)
2802 printf("{ %s, %s }", field->value, field->str);
2805 print_fields(field->next);
2809 static void print_args(struct print_arg *args)
2811 int print_paren = 1;
2813 switch (args->type) {
2818 printf("%s", args->atom.atom);
2821 printf("REC->%s", args->field.name);
2824 printf("__print_flags(");
2825 print_args(args->flags.field);
2826 printf(", %s, ", args->flags.delim);
2827 print_fields(args->flags.flags);
2831 printf("__print_symbolic(");
2832 print_args(args->symbol.field);
2834 print_fields(args->symbol.symbols);
2838 printf("__get_str(%s)", args->string.string);
2841 printf("(%s)", args->typecast.type);
2842 print_args(args->typecast.item);
2845 if (strcmp(args->op.op, ":") == 0)
2849 print_args(args->op.left);
2850 printf(" %s ", args->op.op);
2851 print_args(args->op.right);
2856 /* we should warn... */
2861 print_args(args->next);
2865 static void parse_header_field(char *type,
2866 int *offset, int *size)
2870 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2872 if (read_expected(EVENT_OP, (char *)":") < 0)
2875 if (read_expect_type(EVENT_ITEM, &token) < 0)
2879 if (read_expected(EVENT_ITEM, type) < 0)
2881 if (read_expected(EVENT_OP, (char *)";") < 0)
2883 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2885 if (read_expected(EVENT_OP, (char *)":") < 0)
2887 if (read_expect_type(EVENT_ITEM, &token) < 0)
2889 *offset = atoi(token);
2891 if (read_expected(EVENT_OP, (char *)";") < 0)
2893 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2895 if (read_expected(EVENT_OP, (char *)":") < 0)
2897 if (read_expect_type(EVENT_ITEM, &token) < 0)
2899 *size = atoi(token);
2901 if (read_expected(EVENT_OP, (char *)";") < 0)
2903 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
2905 if (read_expected(EVENT_OP, (char *)":") < 0)
2907 if (read_expect_type(EVENT_ITEM, &token) < 0)
2910 if (read_expected(EVENT_OP, (char *)";") < 0)
2912 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2917 int parse_header_page(char *buf, unsigned long size)
2919 init_input_buf(buf, size);
2921 parse_header_field((char *)"timestamp", &header_page_ts_offset,
2922 &header_page_ts_size);
2923 parse_header_field((char *)"commit", &header_page_size_offset,
2924 &header_page_size_size);
2925 parse_header_field((char *)"data", &header_page_data_offset,
2926 &header_page_data_size);
2931 int parse_ftrace_file(char *buf, unsigned long size)
2933 struct format_field *field;
2934 struct print_arg *arg, **list;
2935 struct event *event;
2938 init_input_buf(buf, size);
2940 event = alloc_event();
2944 event->flags |= EVENT_FL_ISFTRACE;
2946 event->name = event_read_name();
2948 die("failed to read ftrace event name");
2950 if (strcmp(event->name, "function") == 0)
2951 event->flags |= EVENT_FL_ISFUNC;
2953 else if (strcmp(event->name, "funcgraph_entry") == 0)
2954 event->flags |= EVENT_FL_ISFUNCENT;
2956 else if (strcmp(event->name, "funcgraph_exit") == 0)
2957 event->flags |= EVENT_FL_ISFUNCRET;
2959 else if (strcmp(event->name, "bprint") == 0)
2960 event->flags |= EVENT_FL_ISBPRINT;
2962 event->id = event_read_id();
2964 die("failed to read ftrace event id");
2968 ret = event_read_format(event);
2970 die("failed to read ftrace event format");
2972 ret = event_read_print(event);
2974 die("failed to read ftrace event print fmt");
2977 * The arguments for ftrace files are parsed by the fields.
2978 * Set up the fields as their arguments.
2980 list = &event->print_fmt.args;
2981 for (field = event->format.fields; field; field = field->next) {
2982 arg = malloc_or_die(sizeof(*arg));
2983 memset(arg, 0, sizeof(*arg));
2986 arg->type = PRINT_FIELD;
2987 arg->field.name = field->name;
2988 arg->field.field = field;
2993 int parse_event_file(char *buf, unsigned long size, char *sys)
2995 struct event *event;
2998 init_input_buf(buf, size);
3000 event = alloc_event();
3004 event->name = event_read_name();
3006 die("failed to read event name");
3008 event->id = event_read_id();
3010 die("failed to read event id");
3012 ret = event_read_format(event);
3014 die("failed to read event format");
3016 ret = event_read_print(event);
3018 die("failed to read event print fmt");
3020 event->system = strdup(sys);
3022 #define PRINT_ARGS 0
3023 if (PRINT_ARGS && event->print_fmt.args)
3024 print_args(event->print_fmt.args);
3030 void parse_set_info(int nr_cpus, int long_sz)
3033 long_size = long_sz;