2 * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License (not later!)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 * The parts for function graph printing was taken and modified from the
22 * Linux Kernel that were written by Frederic Weisbecker.
34 #include "trace-event.h"
36 int header_page_ts_offset;
37 int header_page_ts_size;
38 int header_page_size_offset;
39 int header_page_size_size;
40 int header_page_data_offset;
41 int header_page_data_size;
43 static char *input_buf;
44 static unsigned long long input_buf_ptr;
45 static unsigned long long input_buf_siz;
50 static void init_input_buf(char *buf, unsigned long long size)
62 static struct cmdline *cmdlines;
63 static int cmdline_count;
65 static int cmdline_cmp(const void *a, const void *b)
67 const struct cmdline *ca = a;
68 const struct cmdline *cb = b;
70 if (ca->pid < cb->pid)
72 if (ca->pid > cb->pid)
78 void parse_cmdlines(char *file, int size __unused)
81 struct cmdline_list *next;
84 } *list = NULL, *item;
89 line = strtok_r(file, "\n", &next);
91 item = malloc_or_die(sizeof(*item));
92 sscanf(line, "%d %as", &item->pid,
93 (float *)(void *)&item->comm); /* workaround gcc warning */
96 line = strtok_r(NULL, "\n", &next);
100 cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
104 cmdlines[i].pid = list->pid;
105 cmdlines[i].comm = list->comm;
112 qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
115 static struct func_map {
116 unsigned long long addr;
120 static unsigned int func_count;
122 static int func_cmp(const void *a, const void *b)
124 const struct func_map *fa = a;
125 const struct func_map *fb = b;
127 if (fa->addr < fb->addr)
129 if (fa->addr > fb->addr)
135 void parse_proc_kallsyms(char *file, unsigned int size __unused)
138 struct func_list *next;
139 unsigned long long addr;
142 } *list = NULL, *item;
150 line = strtok_r(file, "\n", &next);
152 item = malloc_or_die(sizeof(*item));
154 ret = sscanf(line, "%as %c %as\t[%as",
155 (float *)(void *)&addr_str, /* workaround gcc warning */
157 (float *)(void *)&item->func,
158 (float *)(void *)&item->mod);
159 item->addr = strtoull(addr_str, NULL, 16);
162 /* truncate the extra ']' */
164 item->mod[strlen(item->mod) - 1] = 0;
169 line = strtok_r(NULL, "\n", &next);
173 func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
177 func_list[i].func = list->func;
178 func_list[i].addr = list->addr;
179 func_list[i].mod = list->mod;
186 qsort(func_list, func_count, sizeof(*func_list), func_cmp);
189 * Add a special record at the end.
191 func_list[func_count].func = NULL;
192 func_list[func_count].addr = 0;
193 func_list[func_count].mod = NULL;
197 * We are searching for a record in between, not an exact
200 static int func_bcmp(const void *a, const void *b)
202 const struct func_map *fa = a;
203 const struct func_map *fb = b;
205 if ((fa->addr == fb->addr) ||
207 (fa->addr > fb->addr &&
208 fa->addr < (fb+1)->addr))
211 if (fa->addr < fb->addr)
217 static struct func_map *find_func(unsigned long long addr)
219 struct func_map *func;
224 func = bsearch(&key, func_list, func_count, sizeof(*func_list),
230 void print_funcs(void)
234 for (i = 0; i < (int)func_count; i++) {
238 if (func_list[i].mod)
239 printf(" [%s]\n", func_list[i].mod);
245 static struct printk_map {
246 unsigned long long addr;
249 static unsigned int printk_count;
251 static int printk_cmp(const void *a, const void *b)
253 const struct func_map *fa = a;
254 const struct func_map *fb = b;
256 if (fa->addr < fb->addr)
258 if (fa->addr > fb->addr)
264 static struct printk_map *find_printk(unsigned long long addr)
266 struct printk_map *printk;
267 struct printk_map key;
271 printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
277 void parse_ftrace_printk(char *file, unsigned int size __unused)
280 struct printk_list *next;
281 unsigned long long addr;
283 } *list = NULL, *item;
290 line = strtok_r(file, "\n", &next);
292 item = malloc_or_die(sizeof(*item));
293 ret = sscanf(line, "%as : %as",
294 (float *)(void *)&addr_str, /* workaround gcc warning */
295 (float *)(void *)&item->printk);
296 item->addr = strtoull(addr_str, NULL, 16);
301 line = strtok_r(NULL, "\n", &next);
305 printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
309 printk_list[i].printk = list->printk;
310 printk_list[i].addr = list->addr;
317 qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
320 void print_printk(void)
324 for (i = 0; i < (int)printk_count; i++) {
325 printf("%016llx %s\n",
327 printk_list[i].printk);
331 static struct event *alloc_event(void)
335 event = malloc_or_die(sizeof(*event));
336 memset(event, 0, sizeof(*event));
353 static struct event *event_list;
355 static void add_event(struct event *event)
357 event->next = event_list;
361 static int event_item_type(enum event_type type)
364 case EVENT_ITEM ... EVENT_SQUOTE:
366 case EVENT_ERROR ... EVENT_DELIM:
372 static void free_arg(struct print_arg *arg)
380 free(arg->atom.atom);
383 case PRINT_FIELD ... PRINT_OP:
392 static enum event_type get_type(int ch)
395 return EVENT_NEWLINE;
398 if (isalnum(ch) || ch == '_')
406 if (ch == '(' || ch == ')' || ch == ',')
412 static int __read_char(void)
414 if (input_buf_ptr >= input_buf_siz)
417 return input_buf[input_buf_ptr++];
420 static int __peek_char(void)
422 if (input_buf_ptr >= input_buf_siz)
425 return input_buf[input_buf_ptr];
428 static enum event_type __read_token(char **tok)
431 int ch, last_ch, quote_ch, next_ch;
434 enum event_type type;
444 if (type == EVENT_NONE)
452 *tok = malloc_or_die(2);
460 next_ch = __peek_char();
461 if (next_ch == '>') {
462 buf[i++] = __read_char();
475 buf[i++] = __read_char();
487 default: /* what should we do instead? */
497 buf[i++] = __read_char();
502 /* don't keep quotes */
507 if (i == (BUFSIZ - 1)) {
510 *tok = realloc(*tok, tok_size + BUFSIZ);
525 } while (ch != quote_ch && last_ch != '\\');
526 /* remove the last quote */
530 case EVENT_ERROR ... EVENT_SPACE:
536 while (get_type(__peek_char()) == type) {
537 if (i == (BUFSIZ - 1)) {
540 *tok = realloc(*tok, tok_size + BUFSIZ);
559 *tok = realloc(*tok, tok_size + i);
571 static void free_token(char *tok)
577 static enum event_type read_token(char **tok)
579 enum event_type type;
582 type = __read_token(tok);
583 if (type != EVENT_SPACE)
594 static enum event_type read_token_item(char **tok)
596 enum event_type type;
599 type = __read_token(tok);
600 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
610 static int test_type(enum event_type type, enum event_type expect)
612 if (type != expect) {
613 die("Error: expected type %d but read %d",
620 static int test_type_token(enum event_type type, char *token,
621 enum event_type expect, char *expect_tok)
623 if (type != expect) {
624 die("Error: expected type %d but read %d",
629 if (strcmp(token, expect_tok) != 0) {
630 die("Error: expected '%s' but read '%s'",
637 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
639 enum event_type type;
642 type = read_token(tok);
644 type = read_token_item(tok);
645 return test_type(type, expect);
648 static int read_expect_type(enum event_type expect, char **tok)
650 return __read_expect_type(expect, tok, 1);
653 static int __read_expected(enum event_type expect, char *str, int newline_ok)
655 enum event_type type;
660 type = read_token(&token);
662 type = read_token_item(&token);
664 ret = test_type_token(type, token, expect, str);
671 static int read_expected(enum event_type expect, char *str)
673 return __read_expected(expect, str, 1);
676 static int read_expected_item(enum event_type expect, char *str)
678 return __read_expected(expect, str, 0);
681 static char *event_read_name(void)
685 if (read_expected(EVENT_ITEM, (char *)"name") < 0)
688 if (read_expected(EVENT_OP, (char *)":") < 0)
691 if (read_expect_type(EVENT_ITEM, &token) < 0)
701 static int event_read_id(void)
706 if (read_expected_item(EVENT_ITEM, (char *)"ID") < 0)
709 if (read_expected(EVENT_OP, (char *)":") < 0)
712 if (read_expect_type(EVENT_ITEM, &token) < 0)
715 id = strtoul(token, NULL, 0);
724 static int event_read_fields(struct event *event, struct format_field **fields)
726 struct format_field *field = NULL;
727 enum event_type type;
733 type = read_token(&token);
734 if (type == EVENT_NEWLINE) {
741 if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
745 type = read_token(&token);
747 * The ftrace fields may still use the "special" name.
750 if (event->flags & EVENT_FL_ISFTRACE &&
751 type == EVENT_ITEM && strcmp(token, "special") == 0) {
753 type = read_token(&token);
756 if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
759 if (read_expect_type(EVENT_ITEM, &token) < 0)
764 field = malloc_or_die(sizeof(*field));
765 memset(field, 0, sizeof(*field));
767 /* read the rest of the type */
769 type = read_token(&token);
770 if (type == EVENT_ITEM ||
771 (type == EVENT_OP && strcmp(token, "*") == 0) ||
773 * Some of the ftrace fields are broken and have
774 * an illegal "." in them.
776 (event->flags & EVENT_FL_ISFTRACE &&
777 type == EVENT_OP && strcmp(token, ".") == 0)) {
779 if (strcmp(token, "*") == 0)
780 field->flags |= FIELD_IS_POINTER;
783 field->type = realloc(field->type,
784 strlen(field->type) +
785 strlen(last_token) + 2);
786 strcat(field->type, " ");
787 strcat(field->type, last_token);
789 field->type = last_token;
798 die("no type found");
801 field->name = last_token;
803 if (test_type(type, EVENT_OP))
806 if (strcmp(token, "[") == 0) {
807 enum event_type last_type = type;
808 char *brackets = token;
811 field->flags |= FIELD_IS_ARRAY;
813 type = read_token(&token);
814 while (strcmp(token, "]") != 0) {
815 if (last_type == EVENT_ITEM &&
822 brackets = realloc(brackets,
824 strlen(token) + len);
826 strcat(brackets, " ");
827 strcat(brackets, token);
829 type = read_token(&token);
830 if (type == EVENT_NONE) {
831 die("failed to find token");
838 brackets = realloc(brackets, strlen(brackets) + 2);
839 strcat(brackets, "]");
841 /* add brackets to type */
843 type = read_token(&token);
845 * If the next token is not an OP, then it is of
846 * the format: type [] item;
848 if (type == EVENT_ITEM) {
849 field->type = realloc(field->type,
850 strlen(field->type) +
851 strlen(field->name) +
852 strlen(brackets) + 2);
853 strcat(field->type, " ");
854 strcat(field->type, field->name);
855 free_token(field->name);
856 strcat(field->type, brackets);
858 type = read_token(&token);
860 field->type = realloc(field->type,
861 strlen(field->type) +
862 strlen(brackets) + 1);
863 strcat(field->type, brackets);
868 if (test_type_token(type, token, EVENT_OP, (char *)";"))
872 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
875 if (read_expected(EVENT_OP, (char *)":") < 0)
878 if (read_expect_type(EVENT_ITEM, &token))
880 field->offset = strtoul(token, NULL, 0);
883 if (read_expected(EVENT_OP, (char *)";") < 0)
886 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
889 if (read_expected(EVENT_OP, (char *)":") < 0)
892 if (read_expect_type(EVENT_ITEM, &token))
894 field->size = strtoul(token, NULL, 0);
897 if (read_expected(EVENT_OP, (char *)";") < 0)
900 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
903 if (read_expected(EVENT_OP, (char *)":") < 0)
906 if (read_expect_type(EVENT_ITEM, &token))
908 if (strtoul(token, NULL, 0))
909 field->flags |= FIELD_IS_SIGNED;
912 if (read_expected(EVENT_OP, (char *)";") < 0)
915 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
920 fields = &field->next;
934 static int event_read_format(struct event *event)
939 if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
942 if (read_expected(EVENT_OP, (char *)":") < 0)
945 if (read_expect_type(EVENT_NEWLINE, &token))
949 ret = event_read_fields(event, &event->format.common_fields);
952 event->format.nr_common = ret;
954 ret = event_read_fields(event, &event->format.fields);
957 event->format.nr_fields = ret;
967 process_arg_token(struct event *event, struct print_arg *arg,
968 char **tok, enum event_type type);
970 static enum event_type
971 process_arg(struct event *event, struct print_arg *arg, char **tok)
973 enum event_type type;
976 type = read_token(&token);
979 return process_arg_token(event, arg, tok, type);
982 static enum event_type
983 process_cond(struct event *event, struct print_arg *top, char **tok)
985 struct print_arg *arg, *left, *right;
986 enum event_type type;
989 arg = malloc_or_die(sizeof(*arg));
990 memset(arg, 0, sizeof(*arg));
992 left = malloc_or_die(sizeof(*left));
994 right = malloc_or_die(sizeof(*right));
996 arg->type = PRINT_OP;
998 arg->op.right = right;
1001 type = process_arg(event, left, &token);
1002 if (test_type_token(type, token, EVENT_OP, (char *)":"))
1007 type = process_arg(event, right, &token);
1009 top->op.right = arg;
1022 static int get_op_prio(char *op)
1033 /* '>>' and '<<' are 8 */
1037 /* '==' and '!=' are 10 */
1047 die("unknown op '%c'", op[0]);
1051 if (strcmp(op, "++") == 0 ||
1052 strcmp(op, "--") == 0) {
1054 } else if (strcmp(op, ">>") == 0 ||
1055 strcmp(op, "<<") == 0) {
1057 } else if (strcmp(op, ">=") == 0 ||
1058 strcmp(op, "<=") == 0) {
1060 } else if (strcmp(op, "==") == 0 ||
1061 strcmp(op, "!=") == 0) {
1063 } else if (strcmp(op, "&&") == 0) {
1065 } else if (strcmp(op, "||") == 0) {
1068 die("unknown op '%s'", op);
1074 static void set_op_prio(struct print_arg *arg)
1077 /* single ops are the greatest */
1078 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1083 arg->op.prio = get_op_prio(arg->op.op);
1086 static enum event_type
1087 process_op(struct event *event, struct print_arg *arg, char **tok)
1089 struct print_arg *left, *right = NULL;
1090 enum event_type type;
1093 /* the op is passed in via tok */
1096 if (arg->type == PRINT_OP && !arg->op.left) {
1097 /* handle single op */
1099 die("bad op token %s", token);
1108 die("bad op token %s", token);
1112 /* make an empty left */
1113 left = malloc_or_die(sizeof(*left));
1114 left->type = PRINT_NULL;
1115 arg->op.left = left;
1117 right = malloc_or_die(sizeof(*right));
1118 arg->op.right = right;
1120 type = process_arg(event, right, tok);
1122 } else if (strcmp(token, "?") == 0) {
1124 left = malloc_or_die(sizeof(*left));
1125 /* copy the top arg to the left */
1128 arg->type = PRINT_OP;
1130 arg->op.left = left;
1133 type = process_cond(event, arg, tok);
1135 } else if (strcmp(token, ">>") == 0 ||
1136 strcmp(token, "<<") == 0 ||
1137 strcmp(token, "&") == 0 ||
1138 strcmp(token, "|") == 0 ||
1139 strcmp(token, "&&") == 0 ||
1140 strcmp(token, "||") == 0 ||
1141 strcmp(token, "-") == 0 ||
1142 strcmp(token, "+") == 0 ||
1143 strcmp(token, "*") == 0 ||
1144 strcmp(token, "^") == 0 ||
1145 strcmp(token, "/") == 0 ||
1146 strcmp(token, "==") == 0 ||
1147 strcmp(token, "!=") == 0) {
1149 left = malloc_or_die(sizeof(*left));
1151 /* copy the top arg to the left */
1154 arg->type = PRINT_OP;
1156 arg->op.left = left;
1160 right = malloc_or_die(sizeof(*right));
1162 type = process_arg(event, right, tok);
1164 arg->op.right = right;
1167 die("unknown op '%s'", token);
1168 /* the arg is now the left side */
1173 if (type == EVENT_OP) {
1176 /* higher prios need to be closer to the root */
1177 prio = get_op_prio(*tok);
1179 if (prio > arg->op.prio)
1180 return process_op(event, arg, tok);
1182 return process_op(event, right, tok);
1188 static enum event_type
1189 process_entry(struct event *event __unused, struct print_arg *arg,
1192 enum event_type type;
1196 if (read_expected(EVENT_OP, (char *)"->") < 0)
1199 if (read_expect_type(EVENT_ITEM, &token) < 0)
1203 arg->type = PRINT_FIELD;
1204 arg->field.name = field;
1206 type = read_token(&token);
1216 static char *arg_eval (struct print_arg *arg);
1218 static long long arg_num_eval(struct print_arg *arg)
1220 long long left, right;
1223 switch (arg->type) {
1225 val = strtoll(arg->atom.atom, NULL, 0);
1228 val = arg_num_eval(arg->typecast.item);
1231 switch (arg->op.op[0]) {
1233 left = arg_num_eval(arg->op.left);
1234 right = arg_num_eval(arg->op.right);
1236 val = left || right;
1241 left = arg_num_eval(arg->op.left);
1242 right = arg_num_eval(arg->op.right);
1244 val = left && right;
1249 left = arg_num_eval(arg->op.left);
1250 right = arg_num_eval(arg->op.right);
1251 switch (arg->op.op[1]) {
1256 val = left << right;
1259 val = left <= right;
1262 die("unknown op '%s'", arg->op.op);
1266 left = arg_num_eval(arg->op.left);
1267 right = arg_num_eval(arg->op.right);
1268 switch (arg->op.op[1]) {
1273 val = left >> right;
1276 val = left >= right;
1279 die("unknown op '%s'", arg->op.op);
1283 left = arg_num_eval(arg->op.left);
1284 right = arg_num_eval(arg->op.right);
1286 if (arg->op.op[1] != '=')
1287 die("unknown op '%s'", arg->op.op);
1289 val = left == right;
1292 left = arg_num_eval(arg->op.left);
1293 right = arg_num_eval(arg->op.right);
1295 switch (arg->op.op[1]) {
1297 val = left != right;
1300 die("unknown op '%s'", arg->op.op);
1304 die("unknown op '%s'", arg->op.op);
1309 case PRINT_FIELD ... PRINT_SYMBOL:
1312 die("invalid eval type %d", arg->type);
1318 static char *arg_eval (struct print_arg *arg)
1321 static char buf[20];
1323 switch (arg->type) {
1325 return arg->atom.atom;
1327 return arg_eval(arg->typecast.item);
1329 val = arg_num_eval(arg);
1330 sprintf(buf, "%lld", val);
1334 case PRINT_FIELD ... PRINT_SYMBOL:
1337 die("invalid eval type %d", arg->type);
1344 static enum event_type
1345 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1347 enum event_type type;
1348 struct print_arg *arg = NULL;
1349 struct print_flag_sym *field;
1355 type = read_token_item(&token);
1356 if (test_type_token(type, token, EVENT_OP, (char *)"{"))
1359 arg = malloc_or_die(sizeof(*arg));
1362 type = process_arg(event, arg, &token);
1363 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1366 field = malloc_or_die(sizeof(*field));
1367 memset(field, 0, sizeof(field));
1369 value = arg_eval(arg);
1370 field->value = strdup(value);
1373 type = process_arg(event, arg, &token);
1374 if (test_type_token(type, token, EVENT_OP, (char *)"}"))
1377 value = arg_eval(arg);
1378 field->str = strdup(value);
1383 list = &field->next;
1386 type = read_token_item(&token);
1387 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1399 static enum event_type
1400 process_flags(struct event *event, struct print_arg *arg, char **tok)
1402 struct print_arg *field;
1403 enum event_type type;
1406 memset(arg, 0, sizeof(*arg));
1407 arg->type = PRINT_FLAGS;
1409 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1412 field = malloc_or_die(sizeof(*field));
1414 type = process_arg(event, field, &token);
1415 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1418 arg->flags.field = field;
1420 type = read_token_item(&token);
1421 if (event_item_type(type)) {
1422 arg->flags.delim = token;
1423 type = read_token_item(&token);
1426 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1429 type = process_fields(event, &arg->flags.flags, &token);
1430 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1434 type = read_token_item(tok);
1442 static enum event_type
1443 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1445 struct print_arg *field;
1446 enum event_type type;
1449 memset(arg, 0, sizeof(*arg));
1450 arg->type = PRINT_SYMBOL;
1452 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1455 field = malloc_or_die(sizeof(*field));
1457 type = process_arg(event, field, &token);
1458 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1461 arg->symbol.field = field;
1463 type = process_fields(event, &arg->symbol.symbols, &token);
1464 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1468 type = read_token_item(tok);
1476 static enum event_type
1477 process_paren(struct event *event, struct print_arg *arg, char **tok)
1479 struct print_arg *item_arg;
1480 enum event_type type;
1484 type = process_arg(event, arg, &token);
1486 if (type == EVENT_ERROR)
1489 if (type == EVENT_OP) {
1490 /* handle the ptr casts */
1491 if (!strcmp(token, "*")) {
1493 * FIXME: should we zapp whitespaces before ')' ?
1494 * (may require a peek_token_item())
1496 if (__peek_char() == ')') {
1499 type = read_token_item(&token);
1503 type = process_op(event, arg, &token);
1505 if (type == EVENT_ERROR)
1510 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1516 type = read_token_item(&token);
1519 * If the next token is an item or another open paren, then
1520 * this was a typecast.
1522 if (event_item_type(type) ||
1523 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1525 /* make this a typecast and contine */
1527 /* prevous must be an atom */
1528 if (arg->type != PRINT_ATOM)
1529 die("previous needed to be PRINT_ATOM");
1531 item_arg = malloc_or_die(sizeof(*item_arg));
1533 arg->type = PRINT_TYPE;
1535 char *old = arg->atom.atom;
1537 arg->atom.atom = malloc_or_die(strlen(old + 3));
1538 sprintf(arg->atom.atom, "%s *", old);
1541 arg->typecast.type = arg->atom.atom;
1542 arg->typecast.item = item_arg;
1543 type = process_arg_token(event, item_arg, &token, type);
1552 static enum event_type
1553 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1555 enum event_type type;
1558 if (read_expected(EVENT_DELIM, (char *)"(") < 0)
1561 if (read_expect_type(EVENT_ITEM, &token) < 0)
1564 arg->type = PRINT_STRING;
1565 arg->string.string = token;
1566 arg->string.offset = -1;
1568 if (read_expected(EVENT_DELIM, (char *)")") < 0)
1571 type = read_token(&token);
1581 process_arg_token(struct event *event, struct print_arg *arg,
1582 char **tok, enum event_type type)
1591 if (strcmp(token, "REC") == 0) {
1593 type = process_entry(event, arg, &token);
1594 } else if (strcmp(token, "__print_flags") == 0) {
1596 type = process_flags(event, arg, &token);
1597 } else if (strcmp(token, "__print_symbolic") == 0) {
1599 type = process_symbols(event, arg, &token);
1600 } else if (strcmp(token, "__get_str") == 0) {
1602 type = process_str(event, arg, &token);
1605 /* test the next token */
1606 type = read_token_item(&token);
1608 /* atoms can be more than one token long */
1609 while (type == EVENT_ITEM) {
1610 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1612 strcat(atom, token);
1614 type = read_token_item(&token);
1617 /* todo, test for function */
1619 arg->type = PRINT_ATOM;
1620 arg->atom.atom = atom;
1625 arg->type = PRINT_ATOM;
1626 arg->atom.atom = token;
1627 type = read_token_item(&token);
1630 if (strcmp(token, "(") == 0) {
1632 type = process_paren(event, arg, &token);
1636 /* handle single ops */
1637 arg->type = PRINT_OP;
1639 arg->op.left = NULL;
1640 type = process_op(event, arg, &token);
1644 case EVENT_ERROR ... EVENT_NEWLINE:
1646 die("unexpected type %d", type);
1653 static int event_read_print_args(struct event *event, struct print_arg **list)
1655 enum event_type type;
1656 struct print_arg *arg;
1661 arg = malloc_or_die(sizeof(*arg));
1662 memset(arg, 0, sizeof(*arg));
1664 type = process_arg(event, arg, &token);
1666 if (type == EVENT_ERROR) {
1674 if (type == EVENT_OP) {
1675 type = process_op(event, arg, &token);
1680 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1687 } while (type != EVENT_NONE);
1689 if (type != EVENT_NONE)
1695 static int event_read_print(struct event *event)
1697 enum event_type type;
1701 if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
1704 if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
1707 if (read_expected(EVENT_OP, (char *)":") < 0)
1710 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1713 event->print_fmt.format = token;
1714 event->print_fmt.args = NULL;
1716 /* ok to have no arg */
1717 type = read_token_item(&token);
1719 if (type == EVENT_NONE)
1722 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1727 ret = event_read_print_args(event, &event->print_fmt.args);
1738 static struct format_field *
1739 find_common_field(struct event *event, const char *name)
1741 struct format_field *format;
1743 for (format = event->format.common_fields;
1744 format; format = format->next) {
1745 if (strcmp(format->name, name) == 0)
1752 static struct format_field *
1753 find_field(struct event *event, const char *name)
1755 struct format_field *format;
1757 for (format = event->format.fields;
1758 format; format = format->next) {
1759 if (strcmp(format->name, name) == 0)
1766 static struct format_field *
1767 find_any_field(struct event *event, const char *name)
1769 struct format_field *format;
1771 format = find_common_field(event, name);
1774 return find_field(event, name);
1777 static unsigned long long read_size(void *ptr, int size)
1781 return *(unsigned char *)ptr;
1783 return data2host2(ptr);
1785 return data2host4(ptr);
1787 return data2host8(ptr);
1795 raw_field_value(struct event *event, const char *name, void *data)
1797 struct format_field *field;
1799 field = find_any_field(event, name);
1803 return read_size(data + field->offset, field->size);
1806 void *raw_field_ptr(struct event *event, const char *name, void *data)
1808 struct format_field *field;
1810 field = find_any_field(event, name);
1814 return data + field->offset;
1817 static int get_common_info(const char *type, int *offset, int *size)
1819 struct event *event;
1820 struct format_field *field;
1823 * All events should have the same common elements.
1824 * Pick any event to find where the type is;
1827 die("no event_list!");
1830 field = find_common_field(event, type);
1832 die("field '%s' not found", type);
1834 *offset = field->offset;
1835 *size = field->size;
1840 int trace_parse_common_type(void *data)
1842 static int type_offset;
1843 static int type_size;
1847 ret = get_common_info("common_type",
1853 return read_size(data + type_offset, type_size);
1856 static int parse_common_pid(void *data)
1858 static int pid_offset;
1859 static int pid_size;
1863 ret = get_common_info("common_pid",
1870 return read_size(data + pid_offset, pid_size);
1873 struct event *trace_find_event(int id)
1875 struct event *event;
1877 for (event = event_list; event; event = event->next) {
1878 if (event->id == id)
1884 static unsigned long long eval_num_arg(void *data, int size,
1885 struct event *event, struct print_arg *arg)
1887 unsigned long long val = 0;
1888 unsigned long long left, right;
1890 switch (arg->type) {
1895 return strtoull(arg->atom.atom, NULL, 0);
1897 if (!arg->field.field) {
1898 arg->field.field = find_any_field(event, arg->field.name);
1899 if (!arg->field.field)
1900 die("field %s not found", arg->field.name);
1902 /* must be a number */
1903 val = read_size(data + arg->field.field->offset,
1904 arg->field.field->size);
1910 return eval_num_arg(data, size, event, arg->typecast.item);
1915 left = eval_num_arg(data, size, event, arg->op.left);
1916 right = eval_num_arg(data, size, event, arg->op.right);
1917 switch (arg->op.op[0]) {
1920 val = left || right;
1926 val = left && right;
1931 switch (arg->op.op[1]) {
1936 val = left << right;
1939 val = left <= right;
1942 die("unknown op '%s'", arg->op.op);
1946 switch (arg->op.op[1]) {
1951 val = left >> right;
1954 val = left >= right;
1957 die("unknown op '%s'", arg->op.op);
1961 if (arg->op.op[1] != '=')
1962 die("unknown op '%s'", arg->op.op);
1963 val = left == right;
1966 die("unknown op '%s'", arg->op.op);
1969 default: /* not sure what to do there */
1977 unsigned long long value;
1980 static const struct flag flags[] = {
1981 { "HI_SOFTIRQ", 0 },
1982 { "TIMER_SOFTIRQ", 1 },
1983 { "NET_TX_SOFTIRQ", 2 },
1984 { "NET_RX_SOFTIRQ", 3 },
1985 { "BLOCK_SOFTIRQ", 4 },
1986 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
1987 { "TASKLET_SOFTIRQ", 6 },
1988 { "SCHED_SOFTIRQ", 7 },
1989 { "HRTIMER_SOFTIRQ", 8 },
1990 { "RCU_SOFTIRQ", 9 },
1992 { "HRTIMER_NORESTART", 0 },
1993 { "HRTIMER_RESTART", 1 },
1996 static unsigned long long eval_flag(const char *flag)
2001 * Some flags in the format files do not get converted.
2002 * If the flag is not numeric, see if it is something that
2003 * we already know about.
2005 if (isdigit(flag[0]))
2006 return strtoull(flag, NULL, 0);
2008 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
2009 if (strcmp(flags[i].name, flag) == 0)
2010 return flags[i].value;
2015 static void print_str_arg(void *data, int size,
2016 struct event *event, struct print_arg *arg)
2018 struct print_flag_sym *flag;
2019 unsigned long long val, fval;
2023 switch (arg->type) {
2028 printf("%s", arg->atom.atom);
2031 if (!arg->field.field) {
2032 arg->field.field = find_any_field(event, arg->field.name);
2033 if (!arg->field.field)
2034 die("field %s not found", arg->field.name);
2036 str = malloc_or_die(arg->field.field->size + 1);
2037 memcpy(str, data + arg->field.field->offset,
2038 arg->field.field->size);
2039 str[arg->field.field->size] = 0;
2044 val = eval_num_arg(data, size, event, arg->flags.field);
2046 for (flag = arg->flags.flags; flag; flag = flag->next) {
2047 fval = eval_flag(flag->value);
2048 if (!val && !fval) {
2049 printf("%s", flag->str);
2052 if (fval && (val & fval) == fval) {
2053 if (print && arg->flags.delim)
2054 printf("%s", arg->flags.delim);
2055 printf("%s", flag->str);
2062 val = eval_num_arg(data, size, event, arg->symbol.field);
2063 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2064 fval = eval_flag(flag->value);
2066 printf("%s", flag->str);
2074 case PRINT_STRING: {
2077 if (arg->string.offset == -1) {
2078 struct format_field *f;
2080 f = find_any_field(event, arg->string.string);
2081 arg->string.offset = f->offset;
2083 str_offset = *(int *)(data + arg->string.offset);
2084 str_offset &= 0xffff;
2085 printf("%s", ((char *)data) + str_offset);
2090 * The only op for string should be ? :
2092 if (arg->op.op[0] != '?')
2094 val = eval_num_arg(data, size, event, arg->op.left);
2096 print_str_arg(data, size, event, arg->op.right->op.left);
2098 print_str_arg(data, size, event, arg->op.right->op.right);
2106 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2108 static struct format_field *field, *ip_field;
2109 struct print_arg *args, *arg, **next;
2110 unsigned long long ip, val;
2115 field = find_field(event, "buf");
2117 die("can't find buffer field for binary printk");
2118 ip_field = find_field(event, "ip");
2120 die("can't find ip field for binary printk");
2123 ip = read_size(data + ip_field->offset, ip_field->size);
2126 * The first arg is the IP pointer.
2128 args = malloc_or_die(sizeof(*args));
2133 arg->type = PRINT_ATOM;
2134 arg->atom.atom = malloc_or_die(32);
2135 sprintf(arg->atom.atom, "%lld", ip);
2137 /* skip the first "%pf : " */
2138 for (ptr = fmt + 6, bptr = data + field->offset;
2139 bptr < data + size && *ptr; ptr++) {
2163 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2175 val = read_size(bptr, ls);
2177 arg = malloc_or_die(sizeof(*arg));
2179 arg->type = PRINT_ATOM;
2180 arg->atom.atom = malloc_or_die(32);
2181 sprintf(arg->atom.atom, "%lld", val);
2186 arg = malloc_or_die(sizeof(*arg));
2188 arg->type = PRINT_STRING;
2189 arg->string.string = strdup(bptr);
2190 bptr += strlen(bptr) + 1;
2202 static void free_args(struct print_arg *args)
2204 struct print_arg *next;
2209 if (args->type == PRINT_ATOM)
2210 free(args->atom.atom);
2212 free(args->string.string);
2218 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2220 unsigned long long addr;
2221 static struct format_field *field;
2222 struct printk_map *printk;
2227 field = find_field(event, "fmt");
2229 die("can't find format field for binary printk");
2230 printf("field->offset = %d size=%d\n", field->offset, field->size);
2233 addr = read_size(data + field->offset, field->size);
2235 printk = find_printk(addr);
2237 format = malloc_or_die(45);
2238 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2244 /* Remove any quotes. */
2247 format = malloc_or_die(strlen(p) + 10);
2248 sprintf(format, "%s : %s", "%pf", p);
2249 /* remove ending quotes and new line since we will add one too */
2250 p = format + strlen(format) - 1;
2255 if (strcmp(p, "\\n") == 0)
2261 static void pretty_print(void *data, int size, struct event *event)
2263 struct print_fmt *print_fmt = &event->print_fmt;
2264 struct print_arg *arg = print_fmt->args;
2265 struct print_arg *args = NULL;
2266 const char *ptr = print_fmt->format;
2267 unsigned long long val;
2268 struct func_map *func;
2269 const char *saveptr;
2270 char *bprint_fmt = NULL;
2276 if (event->flags & EVENT_FL_ISFUNC)
2277 ptr = " %pF <-- %pF";
2279 if (event->flags & EVENT_FL_ISBPRINT) {
2280 bprint_fmt = get_bprint_format(data, size, event);
2281 args = make_bprint_args(bprint_fmt, data, size, event);
2286 for (; *ptr; ptr++) {
2313 if (*(ptr+1) == 'F' ||
2326 die("no argument match");
2328 len = ((unsigned long)ptr + 1) -
2329 (unsigned long)saveptr;
2331 /* should never happen */
2335 memcpy(format, saveptr, len);
2338 val = eval_num_arg(data, size, event, arg);
2342 func = find_func(val);
2344 printf("%s", func->func);
2345 if (show_func == 'F')
2353 printf(format, (int)val);
2356 printf(format, (long)val);
2359 printf(format, (long long)val);
2362 die("bad count (%d)", ls);
2367 die("no matching argument");
2369 print_str_arg(data, size, event, arg);
2373 printf(">%c<", *ptr);
2386 static inline int log10_cpu(int nb)
2395 /* taken from Linux, written by Frederic Weisbecker */
2396 static void print_graph_cpu(int cpu)
2399 int log10_this = log10_cpu(cpu);
2400 int log10_all = log10_cpu(cpus);
2404 * Start with a space character - to make it stand out
2405 * to the right a bit when trace output is pasted into
2411 * Tricky - we space the CPU field according to the max
2412 * number of online CPUs. On a 2-cpu system it would take
2413 * a maximum of 1 digit - on a 128 cpu system it would
2414 * take up to 3 digits:
2416 for (i = 0; i < log10_all - log10_this; i++)
2419 printf("%d) ", cpu);
2422 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2423 #define TRACE_GRAPH_INDENT 2
2425 static void print_graph_proc(int pid, const char *comm)
2427 /* sign + log10(MAX_INT) + '\0' */
2433 sprintf(pid_str, "%d", pid);
2435 /* 1 stands for the "-" character */
2436 len = strlen(comm) + strlen(pid_str) + 1;
2438 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2439 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2441 /* First spaces to align center */
2442 for (i = 0; i < spaces / 2; i++)
2445 printf("%s-%s", comm, pid_str);
2447 /* Last spaces to align center */
2448 for (i = 0; i < spaces - (spaces / 2); i++)
2452 static struct record *
2453 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2454 struct record *next)
2456 struct format_field *field;
2457 struct event *event;
2462 type = trace_parse_common_type(next->data);
2463 event = trace_find_event(type);
2467 if (!(event->flags & EVENT_FL_ISFUNCRET))
2470 pid = parse_common_pid(next->data);
2471 field = find_field(event, "func");
2473 die("function return does not have field func");
2475 val = read_size(next->data + field->offset, field->size);
2477 if (cur_pid != pid || cur_func != val)
2480 /* this is a leaf, now advance the iterator */
2481 return trace_read_data(cpu);
2484 /* Signal a overhead of time execution to the output */
2485 static void print_graph_overhead(unsigned long long duration)
2487 /* Non nested entry or return */
2488 if (duration == ~0ULL)
2489 return (void)printf(" ");
2491 /* Duration exceeded 100 msecs */
2492 if (duration > 100000ULL)
2493 return (void)printf("! ");
2495 /* Duration exceeded 10 msecs */
2496 if (duration > 10000ULL)
2497 return (void)printf("+ ");
2502 static void print_graph_duration(unsigned long long duration)
2504 unsigned long usecs = duration / 1000;
2505 unsigned long nsecs_rem = duration % 1000;
2506 /* log10(ULONG_MAX) + '\0' */
2512 sprintf(msecs_str, "%lu", usecs);
2515 len = printf("%lu", usecs);
2517 /* Print nsecs (we don't want to exceed 7 numbers) */
2519 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2520 len += printf(".%s", nsecs_str);
2525 /* Print remaining spaces to fit the row's width */
2526 for (i = len; i < 7; i++)
2533 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2535 unsigned long long rettime, calltime;
2536 unsigned long long duration, depth;
2537 unsigned long long val;
2538 struct format_field *field;
2539 struct func_map *func;
2540 struct event *ret_event;
2544 type = trace_parse_common_type(ret_rec->data);
2545 ret_event = trace_find_event(type);
2547 field = find_field(ret_event, "rettime");
2549 die("can't find rettime in return graph");
2550 rettime = read_size(ret_rec->data + field->offset, field->size);
2552 field = find_field(ret_event, "calltime");
2554 die("can't find rettime in return graph");
2555 calltime = read_size(ret_rec->data + field->offset, field->size);
2557 duration = rettime - calltime;
2560 print_graph_overhead(duration);
2563 print_graph_duration(duration);
2565 field = find_field(event, "depth");
2567 die("can't find depth in entry graph");
2568 depth = read_size(data + field->offset, field->size);
2571 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2574 field = find_field(event, "func");
2576 die("can't find func in entry graph");
2577 val = read_size(data + field->offset, field->size);
2578 func = find_func(val);
2581 printf("%s();", func->func);
2583 printf("%llx();", val);
2586 static void print_graph_nested(struct event *event, void *data)
2588 struct format_field *field;
2589 unsigned long long depth;
2590 unsigned long long val;
2591 struct func_map *func;
2595 print_graph_overhead(-1);
2600 field = find_field(event, "depth");
2602 die("can't find depth in entry graph");
2603 depth = read_size(data + field->offset, field->size);
2606 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2609 field = find_field(event, "func");
2611 die("can't find func in entry graph");
2612 val = read_size(data + field->offset, field->size);
2613 func = find_func(val);
2616 printf("%s() {", func->func);
2618 printf("%llx() {", val);
2622 pretty_print_func_ent(void *data, int size, struct event *event,
2623 int cpu, int pid, const char *comm,
2624 unsigned long secs, unsigned long usecs)
2626 struct format_field *field;
2631 printf("%5lu.%06lu | ", secs, usecs);
2633 print_graph_cpu(cpu);
2634 print_graph_proc(pid, comm);
2638 field = find_field(event, "func");
2640 die("function entry does not have func field");
2642 val = read_size(data + field->offset, field->size);
2645 * peek_data may unmap the data pointer. Copy it first.
2647 copy_data = malloc_or_die(size);
2648 memcpy(copy_data, data, size);
2651 rec = trace_peek_data(cpu);
2653 rec = get_return_for_leaf(cpu, pid, val, rec);
2655 print_graph_entry_leaf(event, data, rec);
2659 print_graph_nested(event, data);
2665 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2666 int cpu, int pid, const char *comm,
2667 unsigned long secs, unsigned long usecs)
2669 unsigned long long rettime, calltime;
2670 unsigned long long duration, depth;
2671 struct format_field *field;
2674 printf("%5lu.%06lu | ", secs, usecs);
2676 print_graph_cpu(cpu);
2677 print_graph_proc(pid, comm);
2681 field = find_field(event, "rettime");
2683 die("can't find rettime in return graph");
2684 rettime = read_size(data + field->offset, field->size);
2686 field = find_field(event, "calltime");
2688 die("can't find calltime in return graph");
2689 calltime = read_size(data + field->offset, field->size);
2691 duration = rettime - calltime;
2694 print_graph_overhead(duration);
2697 print_graph_duration(duration);
2699 field = find_field(event, "depth");
2701 die("can't find depth in entry graph");
2702 depth = read_size(data + field->offset, field->size);
2705 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2712 pretty_print_func_graph(void *data, int size, struct event *event,
2713 int cpu, int pid, const char *comm,
2714 unsigned long secs, unsigned long usecs)
2716 if (event->flags & EVENT_FL_ISFUNCENT)
2717 pretty_print_func_ent(data, size, event,
2718 cpu, pid, comm, secs, usecs);
2719 else if (event->flags & EVENT_FL_ISFUNCRET)
2720 pretty_print_func_ret(data, size, event,
2721 cpu, pid, comm, secs, usecs);
2725 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2728 struct event *event;
2730 unsigned long usecs;
2734 secs = nsecs / NSECS_PER_SEC;
2735 nsecs -= secs * NSECS_PER_SEC;
2736 usecs = nsecs / NSECS_PER_USEC;
2738 type = trace_parse_common_type(data);
2740 event = trace_find_event(type);
2742 printf("ug! no event found for type %d\n", type);
2746 pid = parse_common_pid(data);
2748 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2749 return pretty_print_func_graph(data, size, event, cpu,
2750 pid, comm, secs, usecs);
2752 printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
2754 secs, nsecs, event->name);
2756 pretty_print(data, size, event);
2760 static void print_fields(struct print_flag_sym *field)
2762 printf("{ %s, %s }", field->value, field->str);
2765 print_fields(field->next);
2769 static void print_args(struct print_arg *args)
2771 int print_paren = 1;
2773 switch (args->type) {
2778 printf("%s", args->atom.atom);
2781 printf("REC->%s", args->field.name);
2784 printf("__print_flags(");
2785 print_args(args->flags.field);
2786 printf(", %s, ", args->flags.delim);
2787 print_fields(args->flags.flags);
2791 printf("__print_symbolic(");
2792 print_args(args->symbol.field);
2794 print_fields(args->symbol.symbols);
2798 printf("__get_str(%s)", args->string.string);
2801 printf("(%s)", args->typecast.type);
2802 print_args(args->typecast.item);
2805 if (strcmp(args->op.op, ":") == 0)
2809 print_args(args->op.left);
2810 printf(" %s ", args->op.op);
2811 print_args(args->op.right);
2816 /* we should warn... */
2821 print_args(args->next);
2825 static void parse_header_field(char *type,
2826 int *offset, int *size)
2830 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2832 if (read_expected(EVENT_OP, (char *)":") < 0)
2835 if (read_expect_type(EVENT_ITEM, &token) < 0)
2839 if (read_expected(EVENT_ITEM, type) < 0)
2841 if (read_expected(EVENT_OP, (char *)";") < 0)
2843 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2845 if (read_expected(EVENT_OP, (char *)":") < 0)
2847 if (read_expect_type(EVENT_ITEM, &token) < 0)
2849 *offset = atoi(token);
2851 if (read_expected(EVENT_OP, (char *)";") < 0)
2853 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2855 if (read_expected(EVENT_OP, (char *)":") < 0)
2857 if (read_expect_type(EVENT_ITEM, &token) < 0)
2859 *size = atoi(token);
2861 if (read_expected(EVENT_OP, (char *)";") < 0)
2863 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
2865 if (read_expected(EVENT_OP, (char *)":") < 0)
2867 if (read_expect_type(EVENT_ITEM, &token) < 0)
2870 if (read_expected(EVENT_OP, (char *)";") < 0)
2872 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2877 int parse_header_page(char *buf, unsigned long size)
2879 init_input_buf(buf, size);
2881 parse_header_field((char *)"timestamp", &header_page_ts_offset,
2882 &header_page_ts_size);
2883 parse_header_field((char *)"commit", &header_page_size_offset,
2884 &header_page_size_size);
2885 parse_header_field((char *)"data", &header_page_data_offset,
2886 &header_page_data_size);
2891 int parse_ftrace_file(char *buf, unsigned long size)
2893 struct format_field *field;
2894 struct print_arg *arg, **list;
2895 struct event *event;
2898 init_input_buf(buf, size);
2900 event = alloc_event();
2904 event->flags |= EVENT_FL_ISFTRACE;
2906 event->name = event_read_name();
2908 die("failed to read ftrace event name");
2910 if (strcmp(event->name, "function") == 0)
2911 event->flags |= EVENT_FL_ISFUNC;
2913 else if (strcmp(event->name, "funcgraph_entry") == 0)
2914 event->flags |= EVENT_FL_ISFUNCENT;
2916 else if (strcmp(event->name, "funcgraph_exit") == 0)
2917 event->flags |= EVENT_FL_ISFUNCRET;
2919 else if (strcmp(event->name, "bprint") == 0)
2920 event->flags |= EVENT_FL_ISBPRINT;
2922 event->id = event_read_id();
2924 die("failed to read ftrace event id");
2928 ret = event_read_format(event);
2930 die("failed to read ftrace event format");
2932 ret = event_read_print(event);
2934 die("failed to read ftrace event print fmt");
2937 * The arguments for ftrace files are parsed by the fields.
2938 * Set up the fields as their arguments.
2940 list = &event->print_fmt.args;
2941 for (field = event->format.fields; field; field = field->next) {
2942 arg = malloc_or_die(sizeof(*arg));
2943 memset(arg, 0, sizeof(*arg));
2946 arg->type = PRINT_FIELD;
2947 arg->field.name = field->name;
2948 arg->field.field = field;
2953 int parse_event_file(char *buf, unsigned long size, char *sys)
2955 struct event *event;
2958 init_input_buf(buf, size);
2960 event = alloc_event();
2964 event->name = event_read_name();
2966 die("failed to read event name");
2968 event->id = event_read_id();
2970 die("failed to read event id");
2972 ret = event_read_format(event);
2974 die("failed to read event format");
2976 ret = event_read_print(event);
2978 die("failed to read event print fmt");
2980 event->system = strdup(sys);
2982 #define PRINT_ARGS 0
2983 if (PRINT_ARGS && event->print_fmt.args)
2984 print_args(event->print_fmt.args);
2990 void parse_set_info(int nr_cpus, int long_sz)
2993 long_size = long_sz;