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.
32 #include "trace-parse-events.h"
34 int header_page_ts_offset;
35 int header_page_ts_size;
36 int header_page_size_offset;
37 int header_page_size_size;
38 int header_page_overwrite_offset;
39 int header_page_overwrite_size;
40 int header_page_data_offset;
41 int header_page_data_size;
45 static char *input_buf;
46 static unsigned long long input_buf_ptr;
47 static unsigned long long input_buf_siz;
51 static int is_flag_field;
52 static int is_symbolic_field;
54 static struct format_field *
55 find_any_field(struct event *event, const char *name);
57 static void init_input_buf(char *buf, unsigned long long size)
69 static struct cmdline *cmdlines;
70 static int cmdline_count;
72 static int cmdline_cmp(const void *a, const void *b)
74 const struct cmdline *ca = a;
75 const struct cmdline *cb = b;
77 if (ca->pid < cb->pid)
79 if (ca->pid > cb->pid)
85 void parse_cmdlines(char *file, int size __unused)
88 struct cmdline_list *next;
91 } *list = NULL, *item;
96 line = strtok_r(file, "\n", &next);
98 item = malloc_or_die(sizeof(*item));
99 sscanf(line, "%d %as", &item->pid,
100 (float *)(void *)&item->comm); /* workaround gcc warning */
103 line = strtok_r(NULL, "\n", &next);
107 cmdlines = malloc_or_die(sizeof(*cmdlines) * cmdline_count);
111 cmdlines[i].pid = list->pid;
112 cmdlines[i].comm = list->comm;
119 qsort(cmdlines, cmdline_count, sizeof(*cmdlines), cmdline_cmp);
122 static struct func_map {
123 unsigned long long addr;
127 static unsigned int func_count;
129 static int func_cmp(const void *a, const void *b)
131 const struct func_map *fa = a;
132 const struct func_map *fb = b;
134 if (fa->addr < fb->addr)
136 if (fa->addr > fb->addr)
142 void parse_proc_kallsyms(char *file, unsigned int size __unused)
145 struct func_list *next;
146 unsigned long long addr;
149 } *list = NULL, *item;
156 line = strtok_r(file, "\n", &next);
158 item = malloc_or_die(sizeof(*item));
160 sscanf(line, "%as %c %as\t[%as",
161 (float *)(void *)&addr_str, /* workaround gcc warning */
163 (float *)(void *)&item->func,
164 (float *)(void *)&item->mod);
165 item->addr = strtoull(addr_str, NULL, 16);
168 /* truncate the extra ']' */
170 item->mod[strlen(item->mod) - 1] = 0;
175 line = strtok_r(NULL, "\n", &next);
179 func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
183 func_list[i].func = list->func;
184 func_list[i].addr = list->addr;
185 func_list[i].mod = list->mod;
192 qsort(func_list, func_count, sizeof(*func_list), func_cmp);
195 * Add a special record at the end.
197 func_list[func_count].func = NULL;
198 func_list[func_count].addr = 0;
199 func_list[func_count].mod = NULL;
203 * We are searching for a record in between, not an exact
206 static int func_bcmp(const void *a, const void *b)
208 const struct func_map *fa = a;
209 const struct func_map *fb = b;
211 if ((fa->addr == fb->addr) ||
213 (fa->addr > fb->addr &&
214 fa->addr < (fb+1)->addr))
217 if (fa->addr < fb->addr)
223 static struct func_map *find_func(unsigned long long addr)
225 struct func_map *func;
230 func = bsearch(&key, func_list, func_count, sizeof(*func_list),
236 void print_funcs(void)
240 for (i = 0; i < (int)func_count; i++) {
244 if (func_list[i].mod)
245 printf(" [%s]\n", func_list[i].mod);
251 static struct printk_map {
252 unsigned long long addr;
255 static unsigned int printk_count;
257 static int printk_cmp(const void *a, const void *b)
259 const struct func_map *fa = a;
260 const struct func_map *fb = b;
262 if (fa->addr < fb->addr)
264 if (fa->addr > fb->addr)
270 static struct printk_map *find_printk(unsigned long long addr)
272 struct printk_map *printk;
273 struct printk_map key;
277 printk = bsearch(&key, printk_list, printk_count, sizeof(*printk_list),
283 void parse_ftrace_printk(char *file, unsigned int size __unused)
286 struct printk_list *next;
287 unsigned long long addr;
289 } *list = NULL, *item;
295 line = strtok_r(file, "\n", &next);
297 addr_str = strsep(&line, ":");
299 warning("error parsing print strings");
302 item = malloc_or_die(sizeof(*item));
303 item->addr = strtoull(addr_str, NULL, 16);
304 /* fmt still has a space, skip it */
305 item->printk = strdup(line+1);
308 line = strtok_r(NULL, "\n", &next);
312 printk_list = malloc_or_die(sizeof(*printk_list) * printk_count + 1);
316 printk_list[i].printk = list->printk;
317 printk_list[i].addr = list->addr;
324 qsort(printk_list, printk_count, sizeof(*printk_list), printk_cmp);
327 void print_printk(void)
331 for (i = 0; i < (int)printk_count; i++) {
332 printf("%016llx %s\n",
334 printk_list[i].printk);
338 static struct event *alloc_event(void)
342 event = malloc_or_die(sizeof(*event));
343 memset(event, 0, sizeof(*event));
360 static struct event *event_list;
362 static void add_event(struct event *event)
364 event->next = event_list;
368 static int event_item_type(enum event_type type)
371 case EVENT_ITEM ... EVENT_SQUOTE:
373 case EVENT_ERROR ... EVENT_DELIM:
379 static void free_arg(struct print_arg *arg)
387 free(arg->atom.atom);
390 case PRINT_FIELD ... PRINT_OP:
399 static enum event_type get_type(int ch)
402 return EVENT_NEWLINE;
405 if (isalnum(ch) || ch == '_')
413 if (ch == '(' || ch == ')' || ch == ',')
419 static int __read_char(void)
421 if (input_buf_ptr >= input_buf_siz)
424 return input_buf[input_buf_ptr++];
427 static int __peek_char(void)
429 if (input_buf_ptr >= input_buf_siz)
432 return input_buf[input_buf_ptr];
435 static enum event_type __read_token(char **tok)
438 int ch, last_ch, quote_ch, next_ch;
441 enum event_type type;
451 if (type == EVENT_NONE)
459 *tok = malloc_or_die(2);
467 next_ch = __peek_char();
468 if (next_ch == '>') {
469 buf[i++] = __read_char();
482 buf[i++] = __read_char();
494 default: /* what should we do instead? */
504 buf[i++] = __read_char();
509 /* don't keep quotes */
514 if (i == (BUFSIZ - 1)) {
517 *tok = realloc(*tok, tok_size + BUFSIZ);
532 /* the '\' '\' will cancel itself */
533 if (ch == '\\' && last_ch == '\\')
535 } while (ch != quote_ch || last_ch == '\\');
536 /* remove the last quote */
540 case EVENT_ERROR ... EVENT_SPACE:
546 while (get_type(__peek_char()) == type) {
547 if (i == (BUFSIZ - 1)) {
550 *tok = realloc(*tok, tok_size + BUFSIZ);
569 *tok = realloc(*tok, tok_size + i);
581 static void free_token(char *tok)
587 static enum event_type read_token(char **tok)
589 enum event_type type;
592 type = __read_token(tok);
593 if (type != EVENT_SPACE)
604 static enum event_type read_token_item(char **tok)
606 enum event_type type;
609 type = __read_token(tok);
610 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
620 static int test_type(enum event_type type, enum event_type expect)
622 if (type != expect) {
623 warning("Error: expected type %d but read %d",
630 static int __test_type_token(enum event_type type, char *token,
631 enum event_type expect, const char *expect_tok,
634 if (type != expect) {
636 warning("Error: expected type %d but read %d",
641 if (strcmp(token, expect_tok) != 0) {
643 warning("Error: expected '%s' but read '%s'",
650 static int test_type_token(enum event_type type, char *token,
651 enum event_type expect, const char *expect_tok)
653 return __test_type_token(type, token, expect, expect_tok, true);
656 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
658 enum event_type type;
661 type = read_token(tok);
663 type = read_token_item(tok);
664 return test_type(type, expect);
667 static int read_expect_type(enum event_type expect, char **tok)
669 return __read_expect_type(expect, tok, 1);
672 static int __read_expected(enum event_type expect, const char *str,
673 int newline_ok, bool warn)
675 enum event_type type;
680 type = read_token(&token);
682 type = read_token_item(&token);
684 ret = __test_type_token(type, token, expect, str, warn);
691 static int read_expected(enum event_type expect, const char *str)
693 return __read_expected(expect, str, 1, true);
696 static int read_expected_item(enum event_type expect, const char *str)
698 return __read_expected(expect, str, 0, true);
701 static char *event_read_name(void)
705 if (read_expected(EVENT_ITEM, "name") < 0)
708 if (read_expected(EVENT_OP, ":") < 0)
711 if (read_expect_type(EVENT_ITEM, &token) < 0)
721 static int event_read_id(void)
726 if (read_expected_item(EVENT_ITEM, "ID") < 0)
729 if (read_expected(EVENT_OP, ":") < 0)
732 if (read_expect_type(EVENT_ITEM, &token) < 0)
735 id = strtoul(token, NULL, 0);
744 static int field_is_string(struct format_field *field)
746 if ((field->flags & FIELD_IS_ARRAY) &&
747 (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
748 !strstr(field->type, "s8")))
754 static int field_is_dynamic(struct format_field *field)
756 if (!strncmp(field->type, "__data_loc", 10))
762 static int event_read_fields(struct event *event, struct format_field **fields)
764 struct format_field *field = NULL;
765 enum event_type type;
771 type = read_token(&token);
772 if (type == EVENT_NEWLINE) {
779 if (test_type_token(type, token, EVENT_ITEM, "field"))
783 type = read_token(&token);
785 * The ftrace fields may still use the "special" name.
788 if (event->flags & EVENT_FL_ISFTRACE &&
789 type == EVENT_ITEM && strcmp(token, "special") == 0) {
791 type = read_token(&token);
794 if (test_type_token(type, token, EVENT_OP, ":") < 0)
797 if (read_expect_type(EVENT_ITEM, &token) < 0)
802 field = malloc_or_die(sizeof(*field));
803 memset(field, 0, sizeof(*field));
805 /* read the rest of the type */
807 type = read_token(&token);
808 if (type == EVENT_ITEM ||
809 (type == EVENT_OP && strcmp(token, "*") == 0) ||
811 * Some of the ftrace fields are broken and have
812 * an illegal "." in them.
814 (event->flags & EVENT_FL_ISFTRACE &&
815 type == EVENT_OP && strcmp(token, ".") == 0)) {
817 if (strcmp(token, "*") == 0)
818 field->flags |= FIELD_IS_POINTER;
821 field->type = realloc(field->type,
822 strlen(field->type) +
823 strlen(last_token) + 2);
824 strcat(field->type, " ");
825 strcat(field->type, last_token);
827 field->type = last_token;
836 die("no type found");
839 field->name = last_token;
841 if (test_type(type, EVENT_OP))
844 if (strcmp(token, "[") == 0) {
845 enum event_type last_type = type;
846 char *brackets = token;
849 field->flags |= FIELD_IS_ARRAY;
851 type = read_token(&token);
852 while (strcmp(token, "]") != 0) {
853 if (last_type == EVENT_ITEM &&
860 brackets = realloc(brackets,
862 strlen(token) + len);
864 strcat(brackets, " ");
865 strcat(brackets, token);
867 type = read_token(&token);
868 if (type == EVENT_NONE) {
869 die("failed to find token");
876 brackets = realloc(brackets, strlen(brackets) + 2);
877 strcat(brackets, "]");
879 /* add brackets to type */
881 type = read_token(&token);
883 * If the next token is not an OP, then it is of
884 * the format: type [] item;
886 if (type == EVENT_ITEM) {
887 field->type = realloc(field->type,
888 strlen(field->type) +
889 strlen(field->name) +
890 strlen(brackets) + 2);
891 strcat(field->type, " ");
892 strcat(field->type, field->name);
893 free_token(field->name);
894 strcat(field->type, brackets);
896 type = read_token(&token);
898 field->type = realloc(field->type,
899 strlen(field->type) +
900 strlen(brackets) + 1);
901 strcat(field->type, brackets);
906 if (field_is_string(field)) {
907 field->flags |= FIELD_IS_STRING;
908 if (field_is_dynamic(field))
909 field->flags |= FIELD_IS_DYNAMIC;
912 if (test_type_token(type, token, EVENT_OP, ";"))
916 if (read_expected(EVENT_ITEM, "offset") < 0)
919 if (read_expected(EVENT_OP, ":") < 0)
922 if (read_expect_type(EVENT_ITEM, &token))
924 field->offset = strtoul(token, NULL, 0);
927 if (read_expected(EVENT_OP, ";") < 0)
930 if (read_expected(EVENT_ITEM, "size") < 0)
933 if (read_expected(EVENT_OP, ":") < 0)
936 if (read_expect_type(EVENT_ITEM, &token))
938 field->size = strtoul(token, NULL, 0);
941 if (read_expected(EVENT_OP, ";") < 0)
944 type = read_token(&token);
945 if (type != EVENT_NEWLINE) {
946 /* newer versions of the kernel have a "signed" type */
947 if (test_type_token(type, token, EVENT_ITEM, "signed"))
952 if (read_expected(EVENT_OP, ":") < 0)
955 if (read_expect_type(EVENT_ITEM, &token))
958 if (strtoul(token, NULL, 0))
959 field->flags |= FIELD_IS_SIGNED;
962 if (read_expected(EVENT_OP, ";") < 0)
965 if (read_expect_type(EVENT_NEWLINE, &token))
972 fields = &field->next;
986 static int event_read_format(struct event *event)
991 if (read_expected_item(EVENT_ITEM, "format") < 0)
994 if (read_expected(EVENT_OP, ":") < 0)
997 if (read_expect_type(EVENT_NEWLINE, &token))
1001 ret = event_read_fields(event, &event->format.common_fields);
1004 event->format.nr_common = ret;
1006 ret = event_read_fields(event, &event->format.fields);
1009 event->format.nr_fields = ret;
1019 process_arg_token(struct event *event, struct print_arg *arg,
1020 char **tok, enum event_type type);
1022 static enum event_type
1023 process_arg(struct event *event, struct print_arg *arg, char **tok)
1025 enum event_type type;
1028 type = read_token(&token);
1031 return process_arg_token(event, arg, tok, type);
1034 static enum event_type
1035 process_cond(struct event *event, struct print_arg *top, char **tok)
1037 struct print_arg *arg, *left, *right;
1038 enum event_type type;
1041 arg = malloc_or_die(sizeof(*arg));
1042 memset(arg, 0, sizeof(*arg));
1044 left = malloc_or_die(sizeof(*left));
1046 right = malloc_or_die(sizeof(*right));
1048 arg->type = PRINT_OP;
1049 arg->op.left = left;
1050 arg->op.right = right;
1053 type = process_arg(event, left, &token);
1054 if (test_type_token(type, token, EVENT_OP, ":"))
1059 type = process_arg(event, right, &token);
1061 top->op.right = arg;
1074 static enum event_type
1075 process_array(struct event *event, struct print_arg *top, char **tok)
1077 struct print_arg *arg;
1078 enum event_type type;
1081 arg = malloc_or_die(sizeof(*arg));
1082 memset(arg, 0, sizeof(*arg));
1085 type = process_arg(event, arg, &token);
1086 if (test_type_token(type, token, EVENT_OP, "]"))
1089 top->op.right = arg;
1092 type = read_token_item(&token);
1103 static int get_op_prio(char *op)
1114 /* '>>' and '<<' are 8 */
1118 /* '==' and '!=' are 10 */
1128 die("unknown op '%c'", op[0]);
1132 if (strcmp(op, "++") == 0 ||
1133 strcmp(op, "--") == 0) {
1135 } else if (strcmp(op, ">>") == 0 ||
1136 strcmp(op, "<<") == 0) {
1138 } else if (strcmp(op, ">=") == 0 ||
1139 strcmp(op, "<=") == 0) {
1141 } else if (strcmp(op, "==") == 0 ||
1142 strcmp(op, "!=") == 0) {
1144 } else if (strcmp(op, "&&") == 0) {
1146 } else if (strcmp(op, "||") == 0) {
1149 die("unknown op '%s'", op);
1155 static void set_op_prio(struct print_arg *arg)
1158 /* single ops are the greatest */
1159 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1164 arg->op.prio = get_op_prio(arg->op.op);
1167 static enum event_type
1168 process_op(struct event *event, struct print_arg *arg, char **tok)
1170 struct print_arg *left, *right = NULL;
1171 enum event_type type;
1174 /* the op is passed in via tok */
1177 if (arg->type == PRINT_OP && !arg->op.left) {
1178 /* handle single op */
1180 die("bad op token %s", token);
1189 die("bad op token %s", token);
1193 /* make an empty left */
1194 left = malloc_or_die(sizeof(*left));
1195 left->type = PRINT_NULL;
1196 arg->op.left = left;
1198 right = malloc_or_die(sizeof(*right));
1199 arg->op.right = right;
1201 type = process_arg(event, right, tok);
1203 } else if (strcmp(token, "?") == 0) {
1205 left = malloc_or_die(sizeof(*left));
1206 /* copy the top arg to the left */
1209 arg->type = PRINT_OP;
1211 arg->op.left = left;
1214 type = process_cond(event, arg, tok);
1216 } else if (strcmp(token, ">>") == 0 ||
1217 strcmp(token, "<<") == 0 ||
1218 strcmp(token, "&") == 0 ||
1219 strcmp(token, "|") == 0 ||
1220 strcmp(token, "&&") == 0 ||
1221 strcmp(token, "||") == 0 ||
1222 strcmp(token, "-") == 0 ||
1223 strcmp(token, "+") == 0 ||
1224 strcmp(token, "*") == 0 ||
1225 strcmp(token, "^") == 0 ||
1226 strcmp(token, "/") == 0 ||
1227 strcmp(token, "<") == 0 ||
1228 strcmp(token, ">") == 0 ||
1229 strcmp(token, "==") == 0 ||
1230 strcmp(token, "!=") == 0) {
1232 left = malloc_or_die(sizeof(*left));
1234 /* copy the top arg to the left */
1237 arg->type = PRINT_OP;
1239 arg->op.left = left;
1243 right = malloc_or_die(sizeof(*right));
1245 type = read_token_item(&token);
1248 /* could just be a type pointer */
1249 if ((strcmp(arg->op.op, "*") == 0) &&
1250 type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
1251 if (left->type != PRINT_ATOM)
1252 die("bad pointer type");
1253 left->atom.atom = realloc(left->atom.atom,
1254 sizeof(left->atom.atom) + 3);
1255 strcat(left->atom.atom, " *");
1262 type = process_arg_token(event, right, tok, type);
1264 arg->op.right = right;
1266 } else if (strcmp(token, "[") == 0) {
1268 left = malloc_or_die(sizeof(*left));
1271 arg->type = PRINT_OP;
1273 arg->op.left = left;
1276 type = process_array(event, arg, tok);
1279 warning("unknown op '%s'", token);
1280 event->flags |= EVENT_FL_FAILED;
1281 /* the arg is now the left side */
1285 if (type == EVENT_OP) {
1288 /* higher prios need to be closer to the root */
1289 prio = get_op_prio(*tok);
1291 if (prio > arg->op.prio)
1292 return process_op(event, arg, tok);
1294 return process_op(event, right, tok);
1300 static enum event_type
1301 process_entry(struct event *event __unused, struct print_arg *arg,
1304 enum event_type type;
1308 if (read_expected(EVENT_OP, "->") < 0)
1311 if (read_expect_type(EVENT_ITEM, &token) < 0)
1315 arg->type = PRINT_FIELD;
1316 arg->field.name = field;
1318 if (is_flag_field) {
1319 arg->field.field = find_any_field(event, arg->field.name);
1320 arg->field.field->flags |= FIELD_IS_FLAG;
1322 } else if (is_symbolic_field) {
1323 arg->field.field = find_any_field(event, arg->field.name);
1324 arg->field.field->flags |= FIELD_IS_SYMBOLIC;
1325 is_symbolic_field = 0;
1328 type = read_token(&token);
1338 static char *arg_eval (struct print_arg *arg);
1340 static long long arg_num_eval(struct print_arg *arg)
1342 long long left, right;
1345 switch (arg->type) {
1347 val = strtoll(arg->atom.atom, NULL, 0);
1350 val = arg_num_eval(arg->typecast.item);
1353 switch (arg->op.op[0]) {
1355 left = arg_num_eval(arg->op.left);
1356 right = arg_num_eval(arg->op.right);
1358 val = left || right;
1363 left = arg_num_eval(arg->op.left);
1364 right = arg_num_eval(arg->op.right);
1366 val = left && right;
1371 left = arg_num_eval(arg->op.left);
1372 right = arg_num_eval(arg->op.right);
1373 switch (arg->op.op[1]) {
1378 val = left << right;
1381 val = left <= right;
1384 die("unknown op '%s'", arg->op.op);
1388 left = arg_num_eval(arg->op.left);
1389 right = arg_num_eval(arg->op.right);
1390 switch (arg->op.op[1]) {
1395 val = left >> right;
1398 val = left >= right;
1401 die("unknown op '%s'", arg->op.op);
1405 left = arg_num_eval(arg->op.left);
1406 right = arg_num_eval(arg->op.right);
1408 if (arg->op.op[1] != '=')
1409 die("unknown op '%s'", arg->op.op);
1411 val = left == right;
1414 left = arg_num_eval(arg->op.left);
1415 right = arg_num_eval(arg->op.right);
1417 switch (arg->op.op[1]) {
1419 val = left != right;
1422 die("unknown op '%s'", arg->op.op);
1426 die("unknown op '%s'", arg->op.op);
1431 case PRINT_FIELD ... PRINT_SYMBOL:
1434 die("invalid eval type %d", arg->type);
1440 static char *arg_eval (struct print_arg *arg)
1443 static char buf[20];
1445 switch (arg->type) {
1447 return arg->atom.atom;
1449 return arg_eval(arg->typecast.item);
1451 val = arg_num_eval(arg);
1452 sprintf(buf, "%lld", val);
1456 case PRINT_FIELD ... PRINT_SYMBOL:
1459 die("invalid eval type %d", arg->type);
1466 static enum event_type
1467 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1469 enum event_type type;
1470 struct print_arg *arg = NULL;
1471 struct print_flag_sym *field;
1477 type = read_token_item(&token);
1478 if (test_type_token(type, token, EVENT_OP, "{"))
1481 arg = malloc_or_die(sizeof(*arg));
1484 type = process_arg(event, arg, &token);
1485 if (test_type_token(type, token, EVENT_DELIM, ","))
1488 field = malloc_or_die(sizeof(*field));
1489 memset(field, 0, sizeof(*field));
1491 value = arg_eval(arg);
1492 field->value = strdup(value);
1495 type = process_arg(event, arg, &token);
1496 if (test_type_token(type, token, EVENT_OP, "}"))
1499 value = arg_eval(arg);
1500 field->str = strdup(value);
1505 list = &field->next;
1508 type = read_token_item(&token);
1509 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1521 static enum event_type
1522 process_flags(struct event *event, struct print_arg *arg, char **tok)
1524 struct print_arg *field;
1525 enum event_type type;
1528 memset(arg, 0, sizeof(*arg));
1529 arg->type = PRINT_FLAGS;
1531 if (read_expected_item(EVENT_DELIM, "(") < 0)
1534 field = malloc_or_die(sizeof(*field));
1536 type = process_arg(event, field, &token);
1537 if (test_type_token(type, token, EVENT_DELIM, ","))
1540 arg->flags.field = field;
1542 type = read_token_item(&token);
1543 if (event_item_type(type)) {
1544 arg->flags.delim = token;
1545 type = read_token_item(&token);
1548 if (test_type_token(type, token, EVENT_DELIM, ","))
1551 type = process_fields(event, &arg->flags.flags, &token);
1552 if (test_type_token(type, token, EVENT_DELIM, ")"))
1556 type = read_token_item(tok);
1564 static enum event_type
1565 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1567 struct print_arg *field;
1568 enum event_type type;
1571 memset(arg, 0, sizeof(*arg));
1572 arg->type = PRINT_SYMBOL;
1574 if (read_expected_item(EVENT_DELIM, "(") < 0)
1577 field = malloc_or_die(sizeof(*field));
1579 type = process_arg(event, field, &token);
1580 if (test_type_token(type, token, EVENT_DELIM, ","))
1583 arg->symbol.field = field;
1585 type = process_fields(event, &arg->symbol.symbols, &token);
1586 if (test_type_token(type, token, EVENT_DELIM, ")"))
1590 type = read_token_item(tok);
1598 static enum event_type
1599 process_paren(struct event *event, struct print_arg *arg, char **tok)
1601 struct print_arg *item_arg;
1602 enum event_type type;
1605 type = process_arg(event, arg, &token);
1607 if (type == EVENT_ERROR)
1610 if (type == EVENT_OP)
1611 type = process_op(event, arg, &token);
1613 if (type == EVENT_ERROR)
1616 if (test_type_token(type, token, EVENT_DELIM, ")")) {
1622 type = read_token_item(&token);
1625 * If the next token is an item or another open paren, then
1626 * this was a typecast.
1628 if (event_item_type(type) ||
1629 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1631 /* make this a typecast and contine */
1633 /* prevous must be an atom */
1634 if (arg->type != PRINT_ATOM)
1635 die("previous needed to be PRINT_ATOM");
1637 item_arg = malloc_or_die(sizeof(*item_arg));
1639 arg->type = PRINT_TYPE;
1640 arg->typecast.type = arg->atom.atom;
1641 arg->typecast.item = item_arg;
1642 type = process_arg_token(event, item_arg, &token, type);
1651 static enum event_type
1652 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1654 enum event_type type;
1657 if (read_expected(EVENT_DELIM, "(") < 0)
1660 if (read_expect_type(EVENT_ITEM, &token) < 0)
1663 arg->type = PRINT_STRING;
1664 arg->string.string = token;
1665 arg->string.offset = -1;
1667 if (read_expected(EVENT_DELIM, ")") < 0)
1670 type = read_token(&token);
1680 process_arg_token(struct event *event, struct print_arg *arg,
1681 char **tok, enum event_type type)
1690 if (strcmp(token, "REC") == 0) {
1692 type = process_entry(event, arg, &token);
1693 } else if (strcmp(token, "__print_flags") == 0) {
1696 type = process_flags(event, arg, &token);
1697 } else if (strcmp(token, "__print_symbolic") == 0) {
1699 is_symbolic_field = 1;
1700 type = process_symbols(event, arg, &token);
1701 } else if (strcmp(token, "__get_str") == 0) {
1703 type = process_str(event, arg, &token);
1706 /* test the next token */
1707 type = read_token_item(&token);
1709 /* atoms can be more than one token long */
1710 while (type == EVENT_ITEM) {
1711 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1713 strcat(atom, token);
1715 type = read_token_item(&token);
1718 /* todo, test for function */
1720 arg->type = PRINT_ATOM;
1721 arg->atom.atom = atom;
1726 arg->type = PRINT_ATOM;
1727 arg->atom.atom = token;
1728 type = read_token_item(&token);
1731 if (strcmp(token, "(") == 0) {
1733 type = process_paren(event, arg, &token);
1737 /* handle single ops */
1738 arg->type = PRINT_OP;
1740 arg->op.left = NULL;
1741 type = process_op(event, arg, &token);
1745 case EVENT_ERROR ... EVENT_NEWLINE:
1747 die("unexpected type %d", type);
1754 static int event_read_print_args(struct event *event, struct print_arg **list)
1756 enum event_type type = EVENT_ERROR;
1757 struct print_arg *arg;
1762 if (type == EVENT_NEWLINE) {
1764 type = read_token_item(&token);
1768 arg = malloc_or_die(sizeof(*arg));
1769 memset(arg, 0, sizeof(*arg));
1771 type = process_arg(event, arg, &token);
1773 if (type == EVENT_ERROR) {
1781 if (type == EVENT_OP) {
1782 type = process_op(event, arg, &token);
1787 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1794 } while (type != EVENT_NONE);
1796 if (type != EVENT_NONE)
1802 static int event_read_print(struct event *event)
1804 enum event_type type;
1808 if (read_expected_item(EVENT_ITEM, "print") < 0)
1811 if (read_expected(EVENT_ITEM, "fmt") < 0)
1814 if (read_expected(EVENT_OP, ":") < 0)
1817 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1821 event->print_fmt.format = token;
1822 event->print_fmt.args = NULL;
1824 /* ok to have no arg */
1825 type = read_token_item(&token);
1827 if (type == EVENT_NONE)
1830 /* Handle concatination of print lines */
1831 if (type == EVENT_DQUOTE) {
1834 cat = malloc_or_die(strlen(event->print_fmt.format) +
1836 strcpy(cat, event->print_fmt.format);
1839 free_token(event->print_fmt.format);
1840 event->print_fmt.format = NULL;
1845 if (test_type_token(type, token, EVENT_DELIM, ","))
1850 ret = event_read_print_args(event, &event->print_fmt.args);
1861 static struct format_field *
1862 find_common_field(struct event *event, const char *name)
1864 struct format_field *format;
1866 for (format = event->format.common_fields;
1867 format; format = format->next) {
1868 if (strcmp(format->name, name) == 0)
1875 static struct format_field *
1876 find_field(struct event *event, const char *name)
1878 struct format_field *format;
1880 for (format = event->format.fields;
1881 format; format = format->next) {
1882 if (strcmp(format->name, name) == 0)
1889 static struct format_field *
1890 find_any_field(struct event *event, const char *name)
1892 struct format_field *format;
1894 format = find_common_field(event, name);
1897 return find_field(event, name);
1900 unsigned long long read_size(void *ptr, int size)
1904 return *(unsigned char *)ptr;
1906 return data2host2(ptr);
1908 return data2host4(ptr);
1910 return data2host8(ptr);
1918 raw_field_value(struct event *event, const char *name, void *data)
1920 struct format_field *field;
1922 field = find_any_field(event, name);
1926 return read_size(data + field->offset, field->size);
1929 void *raw_field_ptr(struct event *event, const char *name, void *data)
1931 struct format_field *field;
1933 field = find_any_field(event, name);
1937 if (field->flags & FIELD_IS_DYNAMIC) {
1940 offset = *(int *)(data + field->offset);
1943 return data + offset;
1946 return data + field->offset;
1949 static int get_common_info(const char *type, int *offset, int *size)
1951 struct event *event;
1952 struct format_field *field;
1955 * All events should have the same common elements.
1956 * Pick any event to find where the type is;
1959 die("no event_list!");
1962 field = find_common_field(event, type);
1964 die("field '%s' not found", type);
1966 *offset = field->offset;
1967 *size = field->size;
1972 static int __parse_common(void *data, int *size, int *offset,
1978 ret = get_common_info(name, offset, size);
1982 return read_size(data + *offset, *size);
1985 int trace_parse_common_type(void *data)
1987 static int type_offset;
1988 static int type_size;
1990 return __parse_common(data, &type_size, &type_offset,
1994 int trace_parse_common_pid(void *data)
1996 static int pid_offset;
1997 static int pid_size;
1999 return __parse_common(data, &pid_size, &pid_offset,
2003 int parse_common_pc(void *data)
2005 static int pc_offset;
2008 return __parse_common(data, &pc_size, &pc_offset,
2009 "common_preempt_count");
2012 int parse_common_flags(void *data)
2014 static int flags_offset;
2015 static int flags_size;
2017 return __parse_common(data, &flags_size, &flags_offset,
2021 int parse_common_lock_depth(void *data)
2023 static int ld_offset;
2027 ret = __parse_common(data, &ld_size, &ld_offset,
2028 "common_lock_depth");
2035 struct event *trace_find_event(int id)
2037 struct event *event;
2039 for (event = event_list; event; event = event->next) {
2040 if (event->id == id)
2046 struct event *trace_find_next_event(struct event *event)
2054 static unsigned long long eval_num_arg(void *data, int size,
2055 struct event *event, struct print_arg *arg)
2057 unsigned long long val = 0;
2058 unsigned long long left, right;
2059 struct print_arg *larg;
2061 switch (arg->type) {
2066 return strtoull(arg->atom.atom, NULL, 0);
2068 if (!arg->field.field) {
2069 arg->field.field = find_any_field(event, arg->field.name);
2070 if (!arg->field.field)
2071 die("field %s not found", arg->field.name);
2073 /* must be a number */
2074 val = read_size(data + arg->field.field->offset,
2075 arg->field.field->size);
2081 return eval_num_arg(data, size, event, arg->typecast.item);
2086 if (strcmp(arg->op.op, "[") == 0) {
2088 * Arrays are special, since we don't want
2089 * to read the arg as is.
2091 if (arg->op.left->type != PRINT_FIELD)
2092 goto default_op; /* oops, all bets off */
2093 larg = arg->op.left;
2094 if (!larg->field.field) {
2096 find_any_field(event, larg->field.name);
2097 if (!larg->field.field)
2098 die("field %s not found", larg->field.name);
2100 right = eval_num_arg(data, size, event, arg->op.right);
2101 val = read_size(data + larg->field.field->offset +
2102 right * long_size, long_size);
2106 left = eval_num_arg(data, size, event, arg->op.left);
2107 right = eval_num_arg(data, size, event, arg->op.right);
2108 switch (arg->op.op[0]) {
2111 val = left || right;
2117 val = left && right;
2122 switch (arg->op.op[1]) {
2127 val = left << right;
2130 val = left <= right;
2133 die("unknown op '%s'", arg->op.op);
2137 switch (arg->op.op[1]) {
2142 val = left >> right;
2145 val = left >= right;
2148 die("unknown op '%s'", arg->op.op);
2152 if (arg->op.op[1] != '=')
2153 die("unknown op '%s'", arg->op.op);
2154 val = left == right;
2163 die("unknown op '%s'", arg->op.op);
2166 default: /* not sure what to do there */
2174 unsigned long long value;
2177 static const struct flag flags[] = {
2178 { "HI_SOFTIRQ", 0 },
2179 { "TIMER_SOFTIRQ", 1 },
2180 { "NET_TX_SOFTIRQ", 2 },
2181 { "NET_RX_SOFTIRQ", 3 },
2182 { "BLOCK_SOFTIRQ", 4 },
2183 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
2184 { "TASKLET_SOFTIRQ", 6 },
2185 { "SCHED_SOFTIRQ", 7 },
2186 { "HRTIMER_SOFTIRQ", 8 },
2187 { "RCU_SOFTIRQ", 9 },
2189 { "HRTIMER_NORESTART", 0 },
2190 { "HRTIMER_RESTART", 1 },
2193 unsigned long long eval_flag(const char *flag)
2198 * Some flags in the format files do not get converted.
2199 * If the flag is not numeric, see if it is something that
2200 * we already know about.
2202 if (isdigit(flag[0]))
2203 return strtoull(flag, NULL, 0);
2205 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
2206 if (strcmp(flags[i].name, flag) == 0)
2207 return flags[i].value;
2212 static void print_str_arg(void *data, int size,
2213 struct event *event, struct print_arg *arg)
2215 struct print_flag_sym *flag;
2216 unsigned long long val, fval;
2220 switch (arg->type) {
2225 printf("%s", arg->atom.atom);
2228 if (!arg->field.field) {
2229 arg->field.field = find_any_field(event, arg->field.name);
2230 if (!arg->field.field)
2231 die("field %s not found", arg->field.name);
2233 str = malloc_or_die(arg->field.field->size + 1);
2234 memcpy(str, data + arg->field.field->offset,
2235 arg->field.field->size);
2236 str[arg->field.field->size] = 0;
2241 val = eval_num_arg(data, size, event, arg->flags.field);
2243 for (flag = arg->flags.flags; flag; flag = flag->next) {
2244 fval = eval_flag(flag->value);
2245 if (!val && !fval) {
2246 printf("%s", flag->str);
2249 if (fval && (val & fval) == fval) {
2250 if (print && arg->flags.delim)
2251 printf("%s", arg->flags.delim);
2252 printf("%s", flag->str);
2259 val = eval_num_arg(data, size, event, arg->symbol.field);
2260 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2261 fval = eval_flag(flag->value);
2263 printf("%s", flag->str);
2271 case PRINT_STRING: {
2274 if (arg->string.offset == -1) {
2275 struct format_field *f;
2277 f = find_any_field(event, arg->string.string);
2278 arg->string.offset = f->offset;
2280 str_offset = *(int *)(data + arg->string.offset);
2281 str_offset &= 0xffff;
2282 printf("%s", ((char *)data) + str_offset);
2287 * The only op for string should be ? :
2289 if (arg->op.op[0] != '?')
2291 val = eval_num_arg(data, size, event, arg->op.left);
2293 print_str_arg(data, size, event, arg->op.right->op.left);
2295 print_str_arg(data, size, event, arg->op.right->op.right);
2303 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2305 static struct format_field *field, *ip_field;
2306 struct print_arg *args, *arg, **next;
2307 unsigned long long ip, val;
2312 field = find_field(event, "buf");
2314 die("can't find buffer field for binary printk");
2315 ip_field = find_field(event, "ip");
2317 die("can't find ip field for binary printk");
2320 ip = read_size(data + ip_field->offset, ip_field->size);
2323 * The first arg is the IP pointer.
2325 args = malloc_or_die(sizeof(*args));
2330 arg->type = PRINT_ATOM;
2331 arg->atom.atom = malloc_or_die(32);
2332 sprintf(arg->atom.atom, "%lld", ip);
2334 /* skip the first "%pf : " */
2335 for (ptr = fmt + 6, bptr = data + field->offset;
2336 bptr < data + size && *ptr; ptr++) {
2360 /* the pointers are always 4 bytes aligned */
2361 bptr = (void *)(((unsigned long)bptr + 3) &
2373 val = read_size(bptr, ls);
2375 arg = malloc_or_die(sizeof(*arg));
2377 arg->type = PRINT_ATOM;
2378 arg->atom.atom = malloc_or_die(32);
2379 sprintf(arg->atom.atom, "%lld", val);
2384 arg = malloc_or_die(sizeof(*arg));
2386 arg->type = PRINT_STRING;
2387 arg->string.string = strdup(bptr);
2388 bptr += strlen(bptr) + 1;
2400 static void free_args(struct print_arg *args)
2402 struct print_arg *next;
2407 if (args->type == PRINT_ATOM)
2408 free(args->atom.atom);
2410 free(args->string.string);
2416 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2418 unsigned long long addr;
2419 static struct format_field *field;
2420 struct printk_map *printk;
2425 field = find_field(event, "fmt");
2427 die("can't find format field for binary printk");
2428 printf("field->offset = %d size=%d\n", field->offset, field->size);
2431 addr = read_size(data + field->offset, field->size);
2433 printk = find_printk(addr);
2435 format = malloc_or_die(45);
2436 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2442 /* Remove any quotes. */
2445 format = malloc_or_die(strlen(p) + 10);
2446 sprintf(format, "%s : %s", "%pf", p);
2447 /* remove ending quotes and new line since we will add one too */
2448 p = format + strlen(format) - 1;
2453 if (strcmp(p, "\\n") == 0)
2459 static void pretty_print(void *data, int size, struct event *event)
2461 struct print_fmt *print_fmt = &event->print_fmt;
2462 struct print_arg *arg = print_fmt->args;
2463 struct print_arg *args = NULL;
2464 const char *ptr = print_fmt->format;
2465 unsigned long long val;
2466 struct func_map *func;
2467 const char *saveptr;
2468 char *bprint_fmt = NULL;
2474 if (event->flags & EVENT_FL_ISFUNC)
2475 ptr = " %pF <-- %pF";
2477 if (event->flags & EVENT_FL_ISBPRINT) {
2478 bprint_fmt = get_bprint_format(data, size, event);
2479 args = make_bprint_args(bprint_fmt, data, size, event);
2484 for (; *ptr; ptr++) {
2506 } else if (*ptr == '%') {
2531 if (*(ptr+1) == 'F' ||
2544 die("no argument match");
2546 len = ((unsigned long)ptr + 1) -
2547 (unsigned long)saveptr;
2549 /* should never happen */
2553 memcpy(format, saveptr, len);
2556 val = eval_num_arg(data, size, event, arg);
2560 func = find_func(val);
2562 printf("%s", func->func);
2563 if (show_func == 'F')
2571 printf(format, (int)val);
2574 printf(format, (long)val);
2577 printf(format, (long long)val);
2580 die("bad count (%d)", ls);
2585 die("no matching argument");
2587 print_str_arg(data, size, event, arg);
2591 printf(">%c<", *ptr);
2604 static inline int log10_cpu(int nb)
2613 static void print_lat_fmt(void *data, int size __unused)
2615 unsigned int lat_flags;
2621 lat_flags = parse_common_flags(data);
2622 pc = parse_common_pc(data);
2623 lock_depth = parse_common_lock_depth(data);
2625 hardirq = lat_flags & TRACE_FLAG_HARDIRQ;
2626 softirq = lat_flags & TRACE_FLAG_SOFTIRQ;
2629 (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
2630 (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
2632 (lat_flags & TRACE_FLAG_NEED_RESCHED) ?
2634 (hardirq && softirq) ? 'H' :
2635 hardirq ? 'h' : softirq ? 's' : '.');
2645 printf("%d ", lock_depth);
2648 #define TRACE_GRAPH_INDENT 2
2650 static struct record *
2651 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2652 struct record *next)
2654 struct format_field *field;
2655 struct event *event;
2660 type = trace_parse_common_type(next->data);
2661 event = trace_find_event(type);
2665 if (!(event->flags & EVENT_FL_ISFUNCRET))
2668 pid = trace_parse_common_pid(next->data);
2669 field = find_field(event, "func");
2671 die("function return does not have field func");
2673 val = read_size(next->data + field->offset, field->size);
2675 if (cur_pid != pid || cur_func != val)
2678 /* this is a leaf, now advance the iterator */
2679 return trace_read_data(cpu);
2682 /* Signal a overhead of time execution to the output */
2683 static void print_graph_overhead(unsigned long long duration)
2685 /* Non nested entry or return */
2686 if (duration == ~0ULL)
2687 return (void)printf(" ");
2689 /* Duration exceeded 100 msecs */
2690 if (duration > 100000ULL)
2691 return (void)printf("! ");
2693 /* Duration exceeded 10 msecs */
2694 if (duration > 10000ULL)
2695 return (void)printf("+ ");
2700 static void print_graph_duration(unsigned long long duration)
2702 unsigned long usecs = duration / 1000;
2703 unsigned long nsecs_rem = duration % 1000;
2704 /* log10(ULONG_MAX) + '\0' */
2710 sprintf(msecs_str, "%lu", usecs);
2713 len = printf("%lu", usecs);
2715 /* Print nsecs (we don't want to exceed 7 numbers) */
2717 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2718 len += printf(".%s", nsecs_str);
2723 /* Print remaining spaces to fit the row's width */
2724 for (i = len; i < 7; i++)
2731 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2733 unsigned long long rettime, calltime;
2734 unsigned long long duration, depth;
2735 unsigned long long val;
2736 struct format_field *field;
2737 struct func_map *func;
2738 struct event *ret_event;
2742 type = trace_parse_common_type(ret_rec->data);
2743 ret_event = trace_find_event(type);
2745 field = find_field(ret_event, "rettime");
2747 die("can't find rettime in return graph");
2748 rettime = read_size(ret_rec->data + field->offset, field->size);
2750 field = find_field(ret_event, "calltime");
2752 die("can't find rettime in return graph");
2753 calltime = read_size(ret_rec->data + field->offset, field->size);
2755 duration = rettime - calltime;
2758 print_graph_overhead(duration);
2761 print_graph_duration(duration);
2763 field = find_field(event, "depth");
2765 die("can't find depth in entry graph");
2766 depth = read_size(data + field->offset, field->size);
2769 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2772 field = find_field(event, "func");
2774 die("can't find func in entry graph");
2775 val = read_size(data + field->offset, field->size);
2776 func = find_func(val);
2779 printf("%s();", func->func);
2781 printf("%llx();", val);
2784 static void print_graph_nested(struct event *event, void *data)
2786 struct format_field *field;
2787 unsigned long long depth;
2788 unsigned long long val;
2789 struct func_map *func;
2793 print_graph_overhead(-1);
2798 field = find_field(event, "depth");
2800 die("can't find depth in entry graph");
2801 depth = read_size(data + field->offset, field->size);
2804 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2807 field = find_field(event, "func");
2809 die("can't find func in entry graph");
2810 val = read_size(data + field->offset, field->size);
2811 func = find_func(val);
2814 printf("%s() {", func->func);
2816 printf("%llx() {", val);
2820 pretty_print_func_ent(void *data, int size, struct event *event,
2823 struct format_field *field;
2828 if (latency_format) {
2829 print_lat_fmt(data, size);
2833 field = find_field(event, "func");
2835 die("function entry does not have func field");
2837 val = read_size(data + field->offset, field->size);
2840 * peek_data may unmap the data pointer. Copy it first.
2842 copy_data = malloc_or_die(size);
2843 memcpy(copy_data, data, size);
2846 rec = trace_peek_data(cpu);
2848 rec = get_return_for_leaf(cpu, pid, val, rec);
2850 print_graph_entry_leaf(event, data, rec);
2854 print_graph_nested(event, data);
2860 pretty_print_func_ret(void *data, int size __unused, struct event *event)
2862 unsigned long long rettime, calltime;
2863 unsigned long long duration, depth;
2864 struct format_field *field;
2867 if (latency_format) {
2868 print_lat_fmt(data, size);
2872 field = find_field(event, "rettime");
2874 die("can't find rettime in return graph");
2875 rettime = read_size(data + field->offset, field->size);
2877 field = find_field(event, "calltime");
2879 die("can't find calltime in return graph");
2880 calltime = read_size(data + field->offset, field->size);
2882 duration = rettime - calltime;
2885 print_graph_overhead(duration);
2888 print_graph_duration(duration);
2890 field = find_field(event, "depth");
2892 die("can't find depth in entry graph");
2893 depth = read_size(data + field->offset, field->size);
2896 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2903 pretty_print_func_graph(void *data, int size, struct event *event,
2906 if (event->flags & EVENT_FL_ISFUNCENT)
2907 pretty_print_func_ent(data, size, event, cpu, pid);
2908 else if (event->flags & EVENT_FL_ISFUNCRET)
2909 pretty_print_func_ret(data, size, event);
2913 void print_trace_event(int cpu, void *data, int size)
2915 struct event *event;
2919 type = trace_parse_common_type(data);
2921 event = trace_find_event(type);
2923 warning("ug! no event found for type %d", type);
2927 pid = trace_parse_common_pid(data);
2929 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2930 return pretty_print_func_graph(data, size, event, cpu, pid);
2933 print_lat_fmt(data, size);
2935 if (event->flags & EVENT_FL_FAILED) {
2936 printf("EVENT '%s' FAILED TO PARSE\n",
2941 pretty_print(data, size, event);
2944 static void print_fields(struct print_flag_sym *field)
2946 printf("{ %s, %s }", field->value, field->str);
2949 print_fields(field->next);
2953 static void print_args(struct print_arg *args)
2955 int print_paren = 1;
2957 switch (args->type) {
2962 printf("%s", args->atom.atom);
2965 printf("REC->%s", args->field.name);
2968 printf("__print_flags(");
2969 print_args(args->flags.field);
2970 printf(", %s, ", args->flags.delim);
2971 print_fields(args->flags.flags);
2975 printf("__print_symbolic(");
2976 print_args(args->symbol.field);
2978 print_fields(args->symbol.symbols);
2982 printf("__get_str(%s)", args->string.string);
2985 printf("(%s)", args->typecast.type);
2986 print_args(args->typecast.item);
2989 if (strcmp(args->op.op, ":") == 0)
2993 print_args(args->op.left);
2994 printf(" %s ", args->op.op);
2995 print_args(args->op.right);
3000 /* we should warn... */
3005 print_args(args->next);
3009 int parse_ftrace_file(char *buf, unsigned long size)
3011 struct format_field *field;
3012 struct print_arg *arg, **list;
3013 struct event *event;
3016 init_input_buf(buf, size);
3018 event = alloc_event();
3022 event->flags |= EVENT_FL_ISFTRACE;
3024 event->name = event_read_name();
3026 die("failed to read ftrace event name");
3028 if (strcmp(event->name, "function") == 0)
3029 event->flags |= EVENT_FL_ISFUNC;
3031 else if (strcmp(event->name, "funcgraph_entry") == 0)
3032 event->flags |= EVENT_FL_ISFUNCENT;
3034 else if (strcmp(event->name, "funcgraph_exit") == 0)
3035 event->flags |= EVENT_FL_ISFUNCRET;
3037 else if (strcmp(event->name, "bprint") == 0)
3038 event->flags |= EVENT_FL_ISBPRINT;
3040 event->id = event_read_id();
3042 die("failed to read ftrace event id");
3046 ret = event_read_format(event);
3048 die("failed to read ftrace event format");
3050 ret = event_read_print(event);
3052 die("failed to read ftrace event print fmt");
3054 /* New ftrace handles args */
3058 * The arguments for ftrace files are parsed by the fields.
3059 * Set up the fields as their arguments.
3061 list = &event->print_fmt.args;
3062 for (field = event->format.fields; field; field = field->next) {
3063 arg = malloc_or_die(sizeof(*arg));
3064 memset(arg, 0, sizeof(*arg));
3067 arg->type = PRINT_FIELD;
3068 arg->field.name = field->name;
3069 arg->field.field = field;
3074 int parse_event_file(char *buf, unsigned long size, char *sys)
3076 struct event *event;
3079 init_input_buf(buf, size);
3081 event = alloc_event();
3085 event->name = event_read_name();
3087 die("failed to read event name");
3089 event->id = event_read_id();
3091 die("failed to read event id");
3093 ret = event_read_format(event);
3095 warning("failed to read event format for %s", event->name);
3099 ret = event_read_print(event);
3101 warning("failed to read event print fmt for %s", event->name);
3105 event->system = strdup(sys);
3107 #define PRINT_ARGS 0
3108 if (PRINT_ARGS && event->print_fmt.args)
3109 print_args(event->print_fmt.args);
3115 event->flags |= EVENT_FL_FAILED;
3116 /* still add it even if it failed */
3121 void parse_set_info(int nr_cpus, int long_sz)
3124 long_size = long_sz;