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)
1737 event->print_fmt.format = token;
1738 event->print_fmt.args = NULL;
1740 /* ok to have no arg */
1741 type = read_token_item(&token);
1743 if (type == EVENT_NONE)
1746 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1751 ret = event_read_print_args(event, &event->print_fmt.args);
1762 static struct format_field *
1763 find_common_field(struct event *event, const char *name)
1765 struct format_field *format;
1767 for (format = event->format.common_fields;
1768 format; format = format->next) {
1769 if (strcmp(format->name, name) == 0)
1776 static struct format_field *
1777 find_field(struct event *event, const char *name)
1779 struct format_field *format;
1781 for (format = event->format.fields;
1782 format; format = format->next) {
1783 if (strcmp(format->name, name) == 0)
1790 static struct format_field *
1791 find_any_field(struct event *event, const char *name)
1793 struct format_field *format;
1795 format = find_common_field(event, name);
1798 return find_field(event, name);
1801 static unsigned long long read_size(void *ptr, int size)
1805 return *(unsigned char *)ptr;
1807 return data2host2(ptr);
1809 return data2host4(ptr);
1811 return data2host8(ptr);
1819 raw_field_value(struct event *event, const char *name, void *data)
1821 struct format_field *field;
1823 field = find_any_field(event, name);
1827 return read_size(data + field->offset, field->size);
1830 void *raw_field_ptr(struct event *event, const char *name, void *data)
1832 struct format_field *field;
1834 field = find_any_field(event, name);
1838 return data + field->offset;
1841 static int get_common_info(const char *type, int *offset, int *size)
1843 struct event *event;
1844 struct format_field *field;
1847 * All events should have the same common elements.
1848 * Pick any event to find where the type is;
1851 die("no event_list!");
1854 field = find_common_field(event, type);
1856 die("field '%s' not found", type);
1858 *offset = field->offset;
1859 *size = field->size;
1864 int trace_parse_common_type(void *data)
1866 static int type_offset;
1867 static int type_size;
1871 ret = get_common_info("common_type",
1877 return read_size(data + type_offset, type_size);
1880 static int parse_common_pid(void *data)
1882 static int pid_offset;
1883 static int pid_size;
1887 ret = get_common_info("common_pid",
1894 return read_size(data + pid_offset, pid_size);
1897 struct event *trace_find_event(int id)
1899 struct event *event;
1901 for (event = event_list; event; event = event->next) {
1902 if (event->id == id)
1908 static unsigned long long eval_num_arg(void *data, int size,
1909 struct event *event, struct print_arg *arg)
1911 unsigned long long val = 0;
1912 unsigned long long left, right;
1914 switch (arg->type) {
1919 return strtoull(arg->atom.atom, NULL, 0);
1921 if (!arg->field.field) {
1922 arg->field.field = find_any_field(event, arg->field.name);
1923 if (!arg->field.field)
1924 die("field %s not found", arg->field.name);
1926 /* must be a number */
1927 val = read_size(data + arg->field.field->offset,
1928 arg->field.field->size);
1934 return eval_num_arg(data, size, event, arg->typecast.item);
1939 left = eval_num_arg(data, size, event, arg->op.left);
1940 right = eval_num_arg(data, size, event, arg->op.right);
1941 switch (arg->op.op[0]) {
1944 val = left || right;
1950 val = left && right;
1955 switch (arg->op.op[1]) {
1960 val = left << right;
1963 val = left <= right;
1966 die("unknown op '%s'", arg->op.op);
1970 switch (arg->op.op[1]) {
1975 val = left >> right;
1978 val = left >= right;
1981 die("unknown op '%s'", arg->op.op);
1985 if (arg->op.op[1] != '=')
1986 die("unknown op '%s'", arg->op.op);
1987 val = left == right;
1990 die("unknown op '%s'", arg->op.op);
1993 default: /* not sure what to do there */
2001 unsigned long long value;
2004 static const struct flag flags[] = {
2005 { "HI_SOFTIRQ", 0 },
2006 { "TIMER_SOFTIRQ", 1 },
2007 { "NET_TX_SOFTIRQ", 2 },
2008 { "NET_RX_SOFTIRQ", 3 },
2009 { "BLOCK_SOFTIRQ", 4 },
2010 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
2011 { "TASKLET_SOFTIRQ", 6 },
2012 { "SCHED_SOFTIRQ", 7 },
2013 { "HRTIMER_SOFTIRQ", 8 },
2014 { "RCU_SOFTIRQ", 9 },
2016 { "HRTIMER_NORESTART", 0 },
2017 { "HRTIMER_RESTART", 1 },
2020 static unsigned long long eval_flag(const char *flag)
2025 * Some flags in the format files do not get converted.
2026 * If the flag is not numeric, see if it is something that
2027 * we already know about.
2029 if (isdigit(flag[0]))
2030 return strtoull(flag, NULL, 0);
2032 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
2033 if (strcmp(flags[i].name, flag) == 0)
2034 return flags[i].value;
2039 static void print_str_arg(void *data, int size,
2040 struct event *event, struct print_arg *arg)
2042 struct print_flag_sym *flag;
2043 unsigned long long val, fval;
2047 switch (arg->type) {
2052 printf("%s", arg->atom.atom);
2055 if (!arg->field.field) {
2056 arg->field.field = find_any_field(event, arg->field.name);
2057 if (!arg->field.field)
2058 die("field %s not found", arg->field.name);
2060 str = malloc_or_die(arg->field.field->size + 1);
2061 memcpy(str, data + arg->field.field->offset,
2062 arg->field.field->size);
2063 str[arg->field.field->size] = 0;
2068 val = eval_num_arg(data, size, event, arg->flags.field);
2070 for (flag = arg->flags.flags; flag; flag = flag->next) {
2071 fval = eval_flag(flag->value);
2072 if (!val && !fval) {
2073 printf("%s", flag->str);
2076 if (fval && (val & fval) == fval) {
2077 if (print && arg->flags.delim)
2078 printf("%s", arg->flags.delim);
2079 printf("%s", flag->str);
2086 val = eval_num_arg(data, size, event, arg->symbol.field);
2087 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2088 fval = eval_flag(flag->value);
2090 printf("%s", flag->str);
2098 case PRINT_STRING: {
2101 if (arg->string.offset == -1) {
2102 struct format_field *f;
2104 f = find_any_field(event, arg->string.string);
2105 arg->string.offset = f->offset;
2107 str_offset = *(int *)(data + arg->string.offset);
2108 str_offset &= 0xffff;
2109 printf("%s", ((char *)data) + str_offset);
2114 * The only op for string should be ? :
2116 if (arg->op.op[0] != '?')
2118 val = eval_num_arg(data, size, event, arg->op.left);
2120 print_str_arg(data, size, event, arg->op.right->op.left);
2122 print_str_arg(data, size, event, arg->op.right->op.right);
2130 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2132 static struct format_field *field, *ip_field;
2133 struct print_arg *args, *arg, **next;
2134 unsigned long long ip, val;
2139 field = find_field(event, "buf");
2141 die("can't find buffer field for binary printk");
2142 ip_field = find_field(event, "ip");
2144 die("can't find ip field for binary printk");
2147 ip = read_size(data + ip_field->offset, ip_field->size);
2150 * The first arg is the IP pointer.
2152 args = malloc_or_die(sizeof(*args));
2157 arg->type = PRINT_ATOM;
2158 arg->atom.atom = malloc_or_die(32);
2159 sprintf(arg->atom.atom, "%lld", ip);
2161 /* skip the first "%pf : " */
2162 for (ptr = fmt + 6, bptr = data + field->offset;
2163 bptr < data + size && *ptr; ptr++) {
2187 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2199 val = read_size(bptr, ls);
2201 arg = malloc_or_die(sizeof(*arg));
2203 arg->type = PRINT_ATOM;
2204 arg->atom.atom = malloc_or_die(32);
2205 sprintf(arg->atom.atom, "%lld", val);
2210 arg = malloc_or_die(sizeof(*arg));
2212 arg->type = PRINT_STRING;
2213 arg->string.string = strdup(bptr);
2214 bptr += strlen(bptr) + 1;
2226 static void free_args(struct print_arg *args)
2228 struct print_arg *next;
2233 if (args->type == PRINT_ATOM)
2234 free(args->atom.atom);
2236 free(args->string.string);
2242 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2244 unsigned long long addr;
2245 static struct format_field *field;
2246 struct printk_map *printk;
2251 field = find_field(event, "fmt");
2253 die("can't find format field for binary printk");
2254 printf("field->offset = %d size=%d\n", field->offset, field->size);
2257 addr = read_size(data + field->offset, field->size);
2259 printk = find_printk(addr);
2261 format = malloc_or_die(45);
2262 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2268 /* Remove any quotes. */
2271 format = malloc_or_die(strlen(p) + 10);
2272 sprintf(format, "%s : %s", "%pf", p);
2273 /* remove ending quotes and new line since we will add one too */
2274 p = format + strlen(format) - 1;
2279 if (strcmp(p, "\\n") == 0)
2285 static void pretty_print(void *data, int size, struct event *event)
2287 struct print_fmt *print_fmt = &event->print_fmt;
2288 struct print_arg *arg = print_fmt->args;
2289 struct print_arg *args = NULL;
2290 const char *ptr = print_fmt->format;
2291 unsigned long long val;
2292 struct func_map *func;
2293 const char *saveptr;
2294 char *bprint_fmt = NULL;
2300 if (event->flags & EVENT_FL_ISFUNC)
2301 ptr = " %pF <-- %pF";
2303 if (event->flags & EVENT_FL_ISBPRINT) {
2304 bprint_fmt = get_bprint_format(data, size, event);
2305 args = make_bprint_args(bprint_fmt, data, size, event);
2310 for (; *ptr; ptr++) {
2337 if (*(ptr+1) == 'F' ||
2350 die("no argument match");
2352 len = ((unsigned long)ptr + 1) -
2353 (unsigned long)saveptr;
2355 /* should never happen */
2359 memcpy(format, saveptr, len);
2362 val = eval_num_arg(data, size, event, arg);
2366 func = find_func(val);
2368 printf("%s", func->func);
2369 if (show_func == 'F')
2377 printf(format, (int)val);
2380 printf(format, (long)val);
2383 printf(format, (long long)val);
2386 die("bad count (%d)", ls);
2391 die("no matching argument");
2393 print_str_arg(data, size, event, arg);
2397 printf(">%c<", *ptr);
2410 static inline int log10_cpu(int nb)
2419 /* taken from Linux, written by Frederic Weisbecker */
2420 static void print_graph_cpu(int cpu)
2423 int log10_this = log10_cpu(cpu);
2424 int log10_all = log10_cpu(cpus);
2428 * Start with a space character - to make it stand out
2429 * to the right a bit when trace output is pasted into
2435 * Tricky - we space the CPU field according to the max
2436 * number of online CPUs. On a 2-cpu system it would take
2437 * a maximum of 1 digit - on a 128 cpu system it would
2438 * take up to 3 digits:
2440 for (i = 0; i < log10_all - log10_this; i++)
2443 printf("%d) ", cpu);
2446 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2447 #define TRACE_GRAPH_INDENT 2
2449 static void print_graph_proc(int pid, const char *comm)
2451 /* sign + log10(MAX_INT) + '\0' */
2457 sprintf(pid_str, "%d", pid);
2459 /* 1 stands for the "-" character */
2460 len = strlen(comm) + strlen(pid_str) + 1;
2462 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2463 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2465 /* First spaces to align center */
2466 for (i = 0; i < spaces / 2; i++)
2469 printf("%s-%s", comm, pid_str);
2471 /* Last spaces to align center */
2472 for (i = 0; i < spaces - (spaces / 2); i++)
2476 static struct record *
2477 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2478 struct record *next)
2480 struct format_field *field;
2481 struct event *event;
2486 type = trace_parse_common_type(next->data);
2487 event = trace_find_event(type);
2491 if (!(event->flags & EVENT_FL_ISFUNCRET))
2494 pid = parse_common_pid(next->data);
2495 field = find_field(event, "func");
2497 die("function return does not have field func");
2499 val = read_size(next->data + field->offset, field->size);
2501 if (cur_pid != pid || cur_func != val)
2504 /* this is a leaf, now advance the iterator */
2505 return trace_read_data(cpu);
2508 /* Signal a overhead of time execution to the output */
2509 static void print_graph_overhead(unsigned long long duration)
2511 /* Non nested entry or return */
2512 if (duration == ~0ULL)
2513 return (void)printf(" ");
2515 /* Duration exceeded 100 msecs */
2516 if (duration > 100000ULL)
2517 return (void)printf("! ");
2519 /* Duration exceeded 10 msecs */
2520 if (duration > 10000ULL)
2521 return (void)printf("+ ");
2526 static void print_graph_duration(unsigned long long duration)
2528 unsigned long usecs = duration / 1000;
2529 unsigned long nsecs_rem = duration % 1000;
2530 /* log10(ULONG_MAX) + '\0' */
2536 sprintf(msecs_str, "%lu", usecs);
2539 len = printf("%lu", usecs);
2541 /* Print nsecs (we don't want to exceed 7 numbers) */
2543 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2544 len += printf(".%s", nsecs_str);
2549 /* Print remaining spaces to fit the row's width */
2550 for (i = len; i < 7; i++)
2557 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2559 unsigned long long rettime, calltime;
2560 unsigned long long duration, depth;
2561 unsigned long long val;
2562 struct format_field *field;
2563 struct func_map *func;
2564 struct event *ret_event;
2568 type = trace_parse_common_type(ret_rec->data);
2569 ret_event = trace_find_event(type);
2571 field = find_field(ret_event, "rettime");
2573 die("can't find rettime in return graph");
2574 rettime = read_size(ret_rec->data + field->offset, field->size);
2576 field = find_field(ret_event, "calltime");
2578 die("can't find rettime in return graph");
2579 calltime = read_size(ret_rec->data + field->offset, field->size);
2581 duration = rettime - calltime;
2584 print_graph_overhead(duration);
2587 print_graph_duration(duration);
2589 field = find_field(event, "depth");
2591 die("can't find depth in entry graph");
2592 depth = read_size(data + field->offset, field->size);
2595 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2598 field = find_field(event, "func");
2600 die("can't find func in entry graph");
2601 val = read_size(data + field->offset, field->size);
2602 func = find_func(val);
2605 printf("%s();", func->func);
2607 printf("%llx();", val);
2610 static void print_graph_nested(struct event *event, void *data)
2612 struct format_field *field;
2613 unsigned long long depth;
2614 unsigned long long val;
2615 struct func_map *func;
2619 print_graph_overhead(-1);
2624 field = find_field(event, "depth");
2626 die("can't find depth in entry graph");
2627 depth = read_size(data + field->offset, field->size);
2630 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2633 field = find_field(event, "func");
2635 die("can't find func in entry graph");
2636 val = read_size(data + field->offset, field->size);
2637 func = find_func(val);
2640 printf("%s() {", func->func);
2642 printf("%llx() {", val);
2646 pretty_print_func_ent(void *data, int size, struct event *event,
2647 int cpu, int pid, const char *comm,
2648 unsigned long secs, unsigned long usecs)
2650 struct format_field *field;
2655 printf("%5lu.%06lu | ", secs, usecs);
2657 print_graph_cpu(cpu);
2658 print_graph_proc(pid, comm);
2662 field = find_field(event, "func");
2664 die("function entry does not have func field");
2666 val = read_size(data + field->offset, field->size);
2669 * peek_data may unmap the data pointer. Copy it first.
2671 copy_data = malloc_or_die(size);
2672 memcpy(copy_data, data, size);
2675 rec = trace_peek_data(cpu);
2677 rec = get_return_for_leaf(cpu, pid, val, rec);
2679 print_graph_entry_leaf(event, data, rec);
2683 print_graph_nested(event, data);
2689 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2690 int cpu, int pid, const char *comm,
2691 unsigned long secs, unsigned long usecs)
2693 unsigned long long rettime, calltime;
2694 unsigned long long duration, depth;
2695 struct format_field *field;
2698 printf("%5lu.%06lu | ", secs, usecs);
2700 print_graph_cpu(cpu);
2701 print_graph_proc(pid, comm);
2705 field = find_field(event, "rettime");
2707 die("can't find rettime in return graph");
2708 rettime = read_size(data + field->offset, field->size);
2710 field = find_field(event, "calltime");
2712 die("can't find calltime in return graph");
2713 calltime = read_size(data + field->offset, field->size);
2715 duration = rettime - calltime;
2718 print_graph_overhead(duration);
2721 print_graph_duration(duration);
2723 field = find_field(event, "depth");
2725 die("can't find depth in entry graph");
2726 depth = read_size(data + field->offset, field->size);
2729 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2736 pretty_print_func_graph(void *data, int size, struct event *event,
2737 int cpu, int pid, const char *comm,
2738 unsigned long secs, unsigned long usecs)
2740 if (event->flags & EVENT_FL_ISFUNCENT)
2741 pretty_print_func_ent(data, size, event,
2742 cpu, pid, comm, secs, usecs);
2743 else if (event->flags & EVENT_FL_ISFUNCRET)
2744 pretty_print_func_ret(data, size, event,
2745 cpu, pid, comm, secs, usecs);
2749 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2752 struct event *event;
2754 unsigned long usecs;
2758 secs = nsecs / NSECS_PER_SEC;
2759 nsecs -= secs * NSECS_PER_SEC;
2760 usecs = nsecs / NSECS_PER_USEC;
2762 type = trace_parse_common_type(data);
2764 event = trace_find_event(type);
2766 printf("ug! no event found for type %d\n", type);
2770 pid = parse_common_pid(data);
2772 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2773 return pretty_print_func_graph(data, size, event, cpu,
2774 pid, comm, secs, usecs);
2776 printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
2778 secs, nsecs, event->name);
2780 pretty_print(data, size, event);
2784 static void print_fields(struct print_flag_sym *field)
2786 printf("{ %s, %s }", field->value, field->str);
2789 print_fields(field->next);
2793 static void print_args(struct print_arg *args)
2795 int print_paren = 1;
2797 switch (args->type) {
2802 printf("%s", args->atom.atom);
2805 printf("REC->%s", args->field.name);
2808 printf("__print_flags(");
2809 print_args(args->flags.field);
2810 printf(", %s, ", args->flags.delim);
2811 print_fields(args->flags.flags);
2815 printf("__print_symbolic(");
2816 print_args(args->symbol.field);
2818 print_fields(args->symbol.symbols);
2822 printf("__get_str(%s)", args->string.string);
2825 printf("(%s)", args->typecast.type);
2826 print_args(args->typecast.item);
2829 if (strcmp(args->op.op, ":") == 0)
2833 print_args(args->op.left);
2834 printf(" %s ", args->op.op);
2835 print_args(args->op.right);
2840 /* we should warn... */
2845 print_args(args->next);
2849 static void parse_header_field(char *type,
2850 int *offset, int *size)
2854 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2856 if (read_expected(EVENT_OP, (char *)":") < 0)
2859 if (read_expect_type(EVENT_ITEM, &token) < 0)
2863 if (read_expected(EVENT_ITEM, type) < 0)
2865 if (read_expected(EVENT_OP, (char *)";") < 0)
2867 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2869 if (read_expected(EVENT_OP, (char *)":") < 0)
2871 if (read_expect_type(EVENT_ITEM, &token) < 0)
2873 *offset = atoi(token);
2875 if (read_expected(EVENT_OP, (char *)";") < 0)
2877 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2879 if (read_expected(EVENT_OP, (char *)":") < 0)
2881 if (read_expect_type(EVENT_ITEM, &token) < 0)
2883 *size = atoi(token);
2885 if (read_expected(EVENT_OP, (char *)";") < 0)
2887 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
2889 if (read_expected(EVENT_OP, (char *)":") < 0)
2891 if (read_expect_type(EVENT_ITEM, &token) < 0)
2894 if (read_expected(EVENT_OP, (char *)";") < 0)
2896 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2901 int parse_header_page(char *buf, unsigned long size)
2903 init_input_buf(buf, size);
2905 parse_header_field((char *)"timestamp", &header_page_ts_offset,
2906 &header_page_ts_size);
2907 parse_header_field((char *)"commit", &header_page_size_offset,
2908 &header_page_size_size);
2909 parse_header_field((char *)"data", &header_page_data_offset,
2910 &header_page_data_size);
2915 int parse_ftrace_file(char *buf, unsigned long size)
2917 struct format_field *field;
2918 struct print_arg *arg, **list;
2919 struct event *event;
2922 init_input_buf(buf, size);
2924 event = alloc_event();
2928 event->flags |= EVENT_FL_ISFTRACE;
2930 event->name = event_read_name();
2932 die("failed to read ftrace event name");
2934 if (strcmp(event->name, "function") == 0)
2935 event->flags |= EVENT_FL_ISFUNC;
2937 else if (strcmp(event->name, "funcgraph_entry") == 0)
2938 event->flags |= EVENT_FL_ISFUNCENT;
2940 else if (strcmp(event->name, "funcgraph_exit") == 0)
2941 event->flags |= EVENT_FL_ISFUNCRET;
2943 else if (strcmp(event->name, "bprint") == 0)
2944 event->flags |= EVENT_FL_ISBPRINT;
2946 event->id = event_read_id();
2948 die("failed to read ftrace event id");
2952 ret = event_read_format(event);
2954 die("failed to read ftrace event format");
2956 ret = event_read_print(event);
2958 die("failed to read ftrace event print fmt");
2961 * The arguments for ftrace files are parsed by the fields.
2962 * Set up the fields as their arguments.
2964 list = &event->print_fmt.args;
2965 for (field = event->format.fields; field; field = field->next) {
2966 arg = malloc_or_die(sizeof(*arg));
2967 memset(arg, 0, sizeof(*arg));
2970 arg->type = PRINT_FIELD;
2971 arg->field.name = field->name;
2972 arg->field.field = field;
2977 int parse_event_file(char *buf, unsigned long size, char *sys)
2979 struct event *event;
2982 init_input_buf(buf, size);
2984 event = alloc_event();
2988 event->name = event_read_name();
2990 die("failed to read event name");
2992 event->id = event_read_id();
2994 die("failed to read event id");
2996 ret = event_read_format(event);
2998 die("failed to read event format");
3000 ret = event_read_print(event);
3002 die("failed to read event print fmt");
3004 event->system = strdup(sys);
3006 #define PRINT_ARGS 0
3007 if (PRINT_ARGS && event->print_fmt.args)
3008 print_args(event->print_fmt.args);
3014 void parse_set_info(int nr_cpus, int long_sz)
3017 long_size = long_sz;