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 /* the '\' '\' will cancel itself */
526 if (ch == '\\' && last_ch == '\\')
528 } while (ch != quote_ch || last_ch == '\\');
529 /* remove the last quote */
533 case EVENT_ERROR ... EVENT_SPACE:
539 while (get_type(__peek_char()) == type) {
540 if (i == (BUFSIZ - 1)) {
543 *tok = realloc(*tok, tok_size + BUFSIZ);
562 *tok = realloc(*tok, tok_size + i);
574 static void free_token(char *tok)
580 static enum event_type read_token(char **tok)
582 enum event_type type;
585 type = __read_token(tok);
586 if (type != EVENT_SPACE)
597 static enum event_type read_token_item(char **tok)
599 enum event_type type;
602 type = __read_token(tok);
603 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
613 static int test_type(enum event_type type, enum event_type expect)
615 if (type != expect) {
616 die("Error: expected type %d but read %d",
623 static int test_type_token(enum event_type type, char *token,
624 enum event_type expect, const char *expect_tok)
626 if (type != expect) {
627 die("Error: expected type %d but read %d",
632 if (strcmp(token, expect_tok) != 0) {
633 die("Error: expected '%s' but read '%s'",
640 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
642 enum event_type type;
645 type = read_token(tok);
647 type = read_token_item(tok);
648 return test_type(type, expect);
651 static int read_expect_type(enum event_type expect, char **tok)
653 return __read_expect_type(expect, tok, 1);
656 static int __read_expected(enum event_type expect, const char *str, int newline_ok)
658 enum event_type type;
663 type = read_token(&token);
665 type = read_token_item(&token);
667 ret = test_type_token(type, token, expect, str);
674 static int read_expected(enum event_type expect, const char *str)
676 return __read_expected(expect, str, 1);
679 static int read_expected_item(enum event_type expect, const char *str)
681 return __read_expected(expect, str, 0);
684 static char *event_read_name(void)
688 if (read_expected(EVENT_ITEM, (char *)"name") < 0)
691 if (read_expected(EVENT_OP, (char *)":") < 0)
694 if (read_expect_type(EVENT_ITEM, &token) < 0)
704 static int event_read_id(void)
709 if (read_expected_item(EVENT_ITEM, (char *)"ID") < 0)
712 if (read_expected(EVENT_OP, (char *)":") < 0)
715 if (read_expect_type(EVENT_ITEM, &token) < 0)
718 id = strtoul(token, NULL, 0);
727 static int field_is_string(struct format_field *field)
729 if ((field->flags & FIELD_IS_ARRAY) &&
730 (!strstr(field->type, "char") || !strstr(field->type, "u8") ||
731 !strstr(field->type, "s8")))
737 static int field_is_dynamic(struct format_field *field)
739 if (!strcmp(field->type, "__data_loc"))
745 static int event_read_fields(struct event *event, struct format_field **fields)
747 struct format_field *field = NULL;
748 enum event_type type;
754 type = read_token(&token);
755 if (type == EVENT_NEWLINE) {
762 if (test_type_token(type, token, EVENT_ITEM, (char *)"field"))
766 type = read_token(&token);
768 * The ftrace fields may still use the "special" name.
771 if (event->flags & EVENT_FL_ISFTRACE &&
772 type == EVENT_ITEM && strcmp(token, "special") == 0) {
774 type = read_token(&token);
777 if (test_type_token(type, token, EVENT_OP, (char *)":") < 0)
780 if (read_expect_type(EVENT_ITEM, &token) < 0)
785 field = malloc_or_die(sizeof(*field));
786 memset(field, 0, sizeof(*field));
788 /* read the rest of the type */
790 type = read_token(&token);
791 if (type == EVENT_ITEM ||
792 (type == EVENT_OP && strcmp(token, "*") == 0) ||
794 * Some of the ftrace fields are broken and have
795 * an illegal "." in them.
797 (event->flags & EVENT_FL_ISFTRACE &&
798 type == EVENT_OP && strcmp(token, ".") == 0)) {
800 if (strcmp(token, "*") == 0)
801 field->flags |= FIELD_IS_POINTER;
804 field->type = realloc(field->type,
805 strlen(field->type) +
806 strlen(last_token) + 2);
807 strcat(field->type, " ");
808 strcat(field->type, last_token);
810 field->type = last_token;
819 die("no type found");
822 field->name = last_token;
824 if (test_type(type, EVENT_OP))
827 if (strcmp(token, "[") == 0) {
828 enum event_type last_type = type;
829 char *brackets = token;
832 field->flags |= FIELD_IS_ARRAY;
834 type = read_token(&token);
835 while (strcmp(token, "]") != 0) {
836 if (last_type == EVENT_ITEM &&
843 brackets = realloc(brackets,
845 strlen(token) + len);
847 strcat(brackets, " ");
848 strcat(brackets, token);
850 type = read_token(&token);
851 if (type == EVENT_NONE) {
852 die("failed to find token");
859 brackets = realloc(brackets, strlen(brackets) + 2);
860 strcat(brackets, "]");
862 /* add brackets to type */
864 type = read_token(&token);
866 * If the next token is not an OP, then it is of
867 * the format: type [] item;
869 if (type == EVENT_ITEM) {
870 field->type = realloc(field->type,
871 strlen(field->type) +
872 strlen(field->name) +
873 strlen(brackets) + 2);
874 strcat(field->type, " ");
875 strcat(field->type, field->name);
876 free_token(field->name);
877 strcat(field->type, brackets);
879 type = read_token(&token);
881 field->type = realloc(field->type,
882 strlen(field->type) +
883 strlen(brackets) + 1);
884 strcat(field->type, brackets);
889 if (field_is_string(field)) {
890 field->flags |= FIELD_IS_STRING;
891 if (field_is_dynamic(field))
892 field->flags |= FIELD_IS_DYNAMIC;
895 if (test_type_token(type, token, EVENT_OP, (char *)";"))
899 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
902 if (read_expected(EVENT_OP, (char *)":") < 0)
905 if (read_expect_type(EVENT_ITEM, &token))
907 field->offset = strtoul(token, NULL, 0);
910 if (read_expected(EVENT_OP, (char *)";") < 0)
913 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
916 if (read_expected(EVENT_OP, (char *)":") < 0)
919 if (read_expect_type(EVENT_ITEM, &token))
921 field->size = strtoul(token, NULL, 0);
924 if (read_expected(EVENT_OP, (char *)";") < 0)
927 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
930 if (read_expected(EVENT_OP, (char *)":") < 0)
933 if (read_expect_type(EVENT_ITEM, &token))
935 if (strtoul(token, NULL, 0))
936 field->flags |= FIELD_IS_SIGNED;
939 if (read_expected(EVENT_OP, (char *)";") < 0)
942 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
947 fields = &field->next;
961 static int event_read_format(struct event *event)
966 if (read_expected_item(EVENT_ITEM, (char *)"format") < 0)
969 if (read_expected(EVENT_OP, (char *)":") < 0)
972 if (read_expect_type(EVENT_NEWLINE, &token))
976 ret = event_read_fields(event, &event->format.common_fields);
979 event->format.nr_common = ret;
981 ret = event_read_fields(event, &event->format.fields);
984 event->format.nr_fields = ret;
994 process_arg_token(struct event *event, struct print_arg *arg,
995 char **tok, enum event_type type);
997 static enum event_type
998 process_arg(struct event *event, struct print_arg *arg, char **tok)
1000 enum event_type type;
1003 type = read_token(&token);
1006 return process_arg_token(event, arg, tok, type);
1009 static enum event_type
1010 process_cond(struct event *event, struct print_arg *top, char **tok)
1012 struct print_arg *arg, *left, *right;
1013 enum event_type type;
1016 arg = malloc_or_die(sizeof(*arg));
1017 memset(arg, 0, sizeof(*arg));
1019 left = malloc_or_die(sizeof(*left));
1021 right = malloc_or_die(sizeof(*right));
1023 arg->type = PRINT_OP;
1024 arg->op.left = left;
1025 arg->op.right = right;
1028 type = process_arg(event, left, &token);
1029 if (test_type_token(type, token, EVENT_OP, (char *)":"))
1034 type = process_arg(event, right, &token);
1036 top->op.right = arg;
1049 static enum event_type
1050 process_array(struct event *event, struct print_arg *top, char **tok)
1052 struct print_arg *arg;
1053 enum event_type type;
1056 arg = malloc_or_die(sizeof(*arg));
1057 memset(arg, 0, sizeof(*arg));
1060 type = process_arg(event, arg, &token);
1061 if (test_type_token(type, token, EVENT_OP, (char *)"]"))
1064 top->op.right = arg;
1067 type = read_token_item(&token);
1078 static int get_op_prio(char *op)
1089 /* '>>' and '<<' are 8 */
1093 /* '==' and '!=' are 10 */
1103 die("unknown op '%c'", op[0]);
1107 if (strcmp(op, "++") == 0 ||
1108 strcmp(op, "--") == 0) {
1110 } else if (strcmp(op, ">>") == 0 ||
1111 strcmp(op, "<<") == 0) {
1113 } else if (strcmp(op, ">=") == 0 ||
1114 strcmp(op, "<=") == 0) {
1116 } else if (strcmp(op, "==") == 0 ||
1117 strcmp(op, "!=") == 0) {
1119 } else if (strcmp(op, "&&") == 0) {
1121 } else if (strcmp(op, "||") == 0) {
1124 die("unknown op '%s'", op);
1130 static void set_op_prio(struct print_arg *arg)
1133 /* single ops are the greatest */
1134 if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
1139 arg->op.prio = get_op_prio(arg->op.op);
1142 static enum event_type
1143 process_op(struct event *event, struct print_arg *arg, char **tok)
1145 struct print_arg *left, *right = NULL;
1146 enum event_type type;
1149 /* the op is passed in via tok */
1152 if (arg->type == PRINT_OP && !arg->op.left) {
1153 /* handle single op */
1155 die("bad op token %s", token);
1164 die("bad op token %s", token);
1168 /* make an empty left */
1169 left = malloc_or_die(sizeof(*left));
1170 left->type = PRINT_NULL;
1171 arg->op.left = left;
1173 right = malloc_or_die(sizeof(*right));
1174 arg->op.right = right;
1176 type = process_arg(event, right, tok);
1178 } else if (strcmp(token, "?") == 0) {
1180 left = malloc_or_die(sizeof(*left));
1181 /* copy the top arg to the left */
1184 arg->type = PRINT_OP;
1186 arg->op.left = left;
1189 type = process_cond(event, arg, tok);
1191 } else if (strcmp(token, ">>") == 0 ||
1192 strcmp(token, "<<") == 0 ||
1193 strcmp(token, "&") == 0 ||
1194 strcmp(token, "|") == 0 ||
1195 strcmp(token, "&&") == 0 ||
1196 strcmp(token, "||") == 0 ||
1197 strcmp(token, "-") == 0 ||
1198 strcmp(token, "+") == 0 ||
1199 strcmp(token, "*") == 0 ||
1200 strcmp(token, "^") == 0 ||
1201 strcmp(token, "/") == 0 ||
1202 strcmp(token, "<") == 0 ||
1203 strcmp(token, ">") == 0 ||
1204 strcmp(token, "==") == 0 ||
1205 strcmp(token, "!=") == 0) {
1207 left = malloc_or_die(sizeof(*left));
1209 /* copy the top arg to the left */
1212 arg->type = PRINT_OP;
1214 arg->op.left = left;
1218 right = malloc_or_die(sizeof(*right));
1220 type = read_token_item(&token);
1223 /* could just be a type pointer */
1224 if ((strcmp(arg->op.op, "*") == 0) &&
1225 type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
1226 if (left->type != PRINT_ATOM)
1227 die("bad pointer type");
1228 left->atom.atom = realloc(left->atom.atom,
1229 sizeof(left->atom.atom) + 3);
1230 strcat(left->atom.atom, " *");
1237 type = process_arg_token(event, right, tok, type);
1239 arg->op.right = right;
1241 } else if (strcmp(token, "[") == 0) {
1243 left = malloc_or_die(sizeof(*left));
1246 arg->type = PRINT_OP;
1248 arg->op.left = left;
1251 type = process_array(event, arg, tok);
1254 die("unknown op '%s'", token);
1255 /* the arg is now the left side */
1260 if (type == EVENT_OP) {
1263 /* higher prios need to be closer to the root */
1264 prio = get_op_prio(*tok);
1266 if (prio > arg->op.prio)
1267 return process_op(event, arg, tok);
1269 return process_op(event, right, tok);
1275 static enum event_type
1276 process_entry(struct event *event __unused, struct print_arg *arg,
1279 enum event_type type;
1283 if (read_expected(EVENT_OP, (char *)"->") < 0)
1286 if (read_expect_type(EVENT_ITEM, &token) < 0)
1290 arg->type = PRINT_FIELD;
1291 arg->field.name = field;
1293 type = read_token(&token);
1303 static char *arg_eval (struct print_arg *arg);
1305 static long long arg_num_eval(struct print_arg *arg)
1307 long long left, right;
1310 switch (arg->type) {
1312 val = strtoll(arg->atom.atom, NULL, 0);
1315 val = arg_num_eval(arg->typecast.item);
1318 switch (arg->op.op[0]) {
1320 left = arg_num_eval(arg->op.left);
1321 right = arg_num_eval(arg->op.right);
1323 val = left || right;
1328 left = arg_num_eval(arg->op.left);
1329 right = arg_num_eval(arg->op.right);
1331 val = left && right;
1336 left = arg_num_eval(arg->op.left);
1337 right = arg_num_eval(arg->op.right);
1338 switch (arg->op.op[1]) {
1343 val = left << right;
1346 val = left <= right;
1349 die("unknown op '%s'", arg->op.op);
1353 left = arg_num_eval(arg->op.left);
1354 right = arg_num_eval(arg->op.right);
1355 switch (arg->op.op[1]) {
1360 val = left >> right;
1363 val = left >= right;
1366 die("unknown op '%s'", arg->op.op);
1370 left = arg_num_eval(arg->op.left);
1371 right = arg_num_eval(arg->op.right);
1373 if (arg->op.op[1] != '=')
1374 die("unknown op '%s'", arg->op.op);
1376 val = left == right;
1379 left = arg_num_eval(arg->op.left);
1380 right = arg_num_eval(arg->op.right);
1382 switch (arg->op.op[1]) {
1384 val = left != right;
1387 die("unknown op '%s'", arg->op.op);
1391 die("unknown op '%s'", arg->op.op);
1396 case PRINT_FIELD ... PRINT_SYMBOL:
1399 die("invalid eval type %d", arg->type);
1405 static char *arg_eval (struct print_arg *arg)
1408 static char buf[20];
1410 switch (arg->type) {
1412 return arg->atom.atom;
1414 return arg_eval(arg->typecast.item);
1416 val = arg_num_eval(arg);
1417 sprintf(buf, "%lld", val);
1421 case PRINT_FIELD ... PRINT_SYMBOL:
1424 die("invalid eval type %d", arg->type);
1431 static enum event_type
1432 process_fields(struct event *event, struct print_flag_sym **list, char **tok)
1434 enum event_type type;
1435 struct print_arg *arg = NULL;
1436 struct print_flag_sym *field;
1442 type = read_token_item(&token);
1443 if (test_type_token(type, token, EVENT_OP, (char *)"{"))
1446 arg = malloc_or_die(sizeof(*arg));
1449 type = process_arg(event, arg, &token);
1450 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1453 field = malloc_or_die(sizeof(*field));
1454 memset(field, 0, sizeof(field));
1456 value = arg_eval(arg);
1457 field->value = strdup(value);
1460 type = process_arg(event, arg, &token);
1461 if (test_type_token(type, token, EVENT_OP, (char *)"}"))
1464 value = arg_eval(arg);
1465 field->str = strdup(value);
1470 list = &field->next;
1473 type = read_token_item(&token);
1474 } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
1486 static enum event_type
1487 process_flags(struct event *event, struct print_arg *arg, char **tok)
1489 struct print_arg *field;
1490 enum event_type type;
1493 memset(arg, 0, sizeof(*arg));
1494 arg->type = PRINT_FLAGS;
1496 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1499 field = malloc_or_die(sizeof(*field));
1501 type = process_arg(event, field, &token);
1502 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1505 arg->flags.field = field;
1507 type = read_token_item(&token);
1508 if (event_item_type(type)) {
1509 arg->flags.delim = token;
1510 type = read_token_item(&token);
1513 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1516 type = process_fields(event, &arg->flags.flags, &token);
1517 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1521 type = read_token_item(tok);
1529 static enum event_type
1530 process_symbols(struct event *event, struct print_arg *arg, char **tok)
1532 struct print_arg *field;
1533 enum event_type type;
1536 memset(arg, 0, sizeof(*arg));
1537 arg->type = PRINT_SYMBOL;
1539 if (read_expected_item(EVENT_DELIM, (char *)"(") < 0)
1542 field = malloc_or_die(sizeof(*field));
1544 type = process_arg(event, field, &token);
1545 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1548 arg->symbol.field = field;
1550 type = process_fields(event, &arg->symbol.symbols, &token);
1551 if (test_type_token(type, token, EVENT_DELIM, (char *)")"))
1555 type = read_token_item(tok);
1563 static enum event_type
1564 process_paren(struct event *event, struct print_arg *arg, char **tok)
1566 struct print_arg *item_arg;
1567 enum event_type type;
1570 type = process_arg(event, arg, &token);
1572 if (type == EVENT_ERROR)
1575 if (type == EVENT_OP)
1576 type = process_op(event, arg, &token);
1578 if (type == EVENT_ERROR)
1581 if (test_type_token(type, token, EVENT_DELIM, (char *)")")) {
1587 type = read_token_item(&token);
1590 * If the next token is an item or another open paren, then
1591 * this was a typecast.
1593 if (event_item_type(type) ||
1594 (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
1596 /* make this a typecast and contine */
1598 /* prevous must be an atom */
1599 if (arg->type != PRINT_ATOM)
1600 die("previous needed to be PRINT_ATOM");
1602 item_arg = malloc_or_die(sizeof(*item_arg));
1604 arg->type = PRINT_TYPE;
1605 arg->typecast.type = arg->atom.atom;
1606 arg->typecast.item = item_arg;
1607 type = process_arg_token(event, item_arg, &token, type);
1616 static enum event_type
1617 process_str(struct event *event __unused, struct print_arg *arg, char **tok)
1619 enum event_type type;
1622 if (read_expected(EVENT_DELIM, (char *)"(") < 0)
1625 if (read_expect_type(EVENT_ITEM, &token) < 0)
1628 arg->type = PRINT_STRING;
1629 arg->string.string = token;
1630 arg->string.offset = -1;
1632 if (read_expected(EVENT_DELIM, (char *)")") < 0)
1635 type = read_token(&token);
1645 process_arg_token(struct event *event, struct print_arg *arg,
1646 char **tok, enum event_type type)
1655 if (strcmp(token, "REC") == 0) {
1657 type = process_entry(event, arg, &token);
1658 } else if (strcmp(token, "__print_flags") == 0) {
1660 type = process_flags(event, arg, &token);
1661 } else if (strcmp(token, "__print_symbolic") == 0) {
1663 type = process_symbols(event, arg, &token);
1664 } else if (strcmp(token, "__get_str") == 0) {
1666 type = process_str(event, arg, &token);
1669 /* test the next token */
1670 type = read_token_item(&token);
1672 /* atoms can be more than one token long */
1673 while (type == EVENT_ITEM) {
1674 atom = realloc(atom, strlen(atom) + strlen(token) + 2);
1676 strcat(atom, token);
1678 type = read_token_item(&token);
1681 /* todo, test for function */
1683 arg->type = PRINT_ATOM;
1684 arg->atom.atom = atom;
1689 arg->type = PRINT_ATOM;
1690 arg->atom.atom = token;
1691 type = read_token_item(&token);
1694 if (strcmp(token, "(") == 0) {
1696 type = process_paren(event, arg, &token);
1700 /* handle single ops */
1701 arg->type = PRINT_OP;
1703 arg->op.left = NULL;
1704 type = process_op(event, arg, &token);
1708 case EVENT_ERROR ... EVENT_NEWLINE:
1710 die("unexpected type %d", type);
1717 static int event_read_print_args(struct event *event, struct print_arg **list)
1719 enum event_type type;
1720 struct print_arg *arg;
1725 arg = malloc_or_die(sizeof(*arg));
1726 memset(arg, 0, sizeof(*arg));
1728 type = process_arg(event, arg, &token);
1730 if (type == EVENT_ERROR) {
1738 if (type == EVENT_OP) {
1739 type = process_op(event, arg, &token);
1744 if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
1751 } while (type != EVENT_NONE);
1753 if (type != EVENT_NONE)
1759 static int event_read_print(struct event *event)
1761 enum event_type type;
1765 if (read_expected_item(EVENT_ITEM, (char *)"print") < 0)
1768 if (read_expected(EVENT_ITEM, (char *)"fmt") < 0)
1771 if (read_expected(EVENT_OP, (char *)":") < 0)
1774 if (read_expect_type(EVENT_DQUOTE, &token) < 0)
1778 event->print_fmt.format = token;
1779 event->print_fmt.args = NULL;
1781 /* ok to have no arg */
1782 type = read_token_item(&token);
1784 if (type == EVENT_NONE)
1787 /* Handle concatination of print lines */
1788 if (type == EVENT_DQUOTE) {
1791 cat = malloc_or_die(strlen(event->print_fmt.format) +
1793 strcpy(cat, event->print_fmt.format);
1796 free_token(event->print_fmt.format);
1797 event->print_fmt.format = NULL;
1802 if (test_type_token(type, token, EVENT_DELIM, (char *)","))
1807 ret = event_read_print_args(event, &event->print_fmt.args);
1818 static struct format_field *
1819 find_common_field(struct event *event, const char *name)
1821 struct format_field *format;
1823 for (format = event->format.common_fields;
1824 format; format = format->next) {
1825 if (strcmp(format->name, name) == 0)
1832 static struct format_field *
1833 find_field(struct event *event, const char *name)
1835 struct format_field *format;
1837 for (format = event->format.fields;
1838 format; format = format->next) {
1839 if (strcmp(format->name, name) == 0)
1846 static struct format_field *
1847 find_any_field(struct event *event, const char *name)
1849 struct format_field *format;
1851 format = find_common_field(event, name);
1854 return find_field(event, name);
1857 static unsigned long long read_size(void *ptr, int size)
1861 return *(unsigned char *)ptr;
1863 return data2host2(ptr);
1865 return data2host4(ptr);
1867 return data2host8(ptr);
1875 raw_field_value(struct event *event, const char *name, void *data)
1877 struct format_field *field;
1879 field = find_any_field(event, name);
1883 return read_size(data + field->offset, field->size);
1886 void *raw_field_ptr(struct event *event, const char *name, void *data)
1888 struct format_field *field;
1890 field = find_any_field(event, name);
1894 return data + field->offset;
1897 static int get_common_info(const char *type, int *offset, int *size)
1899 struct event *event;
1900 struct format_field *field;
1903 * All events should have the same common elements.
1904 * Pick any event to find where the type is;
1907 die("no event_list!");
1910 field = find_common_field(event, type);
1912 die("field '%s' not found", type);
1914 *offset = field->offset;
1915 *size = field->size;
1920 int trace_parse_common_type(void *data)
1922 static int type_offset;
1923 static int type_size;
1927 ret = get_common_info("common_type",
1933 return read_size(data + type_offset, type_size);
1936 static int parse_common_pid(void *data)
1938 static int pid_offset;
1939 static int pid_size;
1943 ret = get_common_info("common_pid",
1950 return read_size(data + pid_offset, pid_size);
1953 struct event *trace_find_event(int id)
1955 struct event *event;
1957 for (event = event_list; event; event = event->next) {
1958 if (event->id == id)
1964 static unsigned long long eval_num_arg(void *data, int size,
1965 struct event *event, struct print_arg *arg)
1967 unsigned long long val = 0;
1968 unsigned long long left, right;
1969 struct print_arg *larg;
1971 switch (arg->type) {
1976 return strtoull(arg->atom.atom, NULL, 0);
1978 if (!arg->field.field) {
1979 arg->field.field = find_any_field(event, arg->field.name);
1980 if (!arg->field.field)
1981 die("field %s not found", arg->field.name);
1983 /* must be a number */
1984 val = read_size(data + arg->field.field->offset,
1985 arg->field.field->size);
1991 return eval_num_arg(data, size, event, arg->typecast.item);
1996 if (strcmp(arg->op.op, "[") == 0) {
1998 * Arrays are special, since we don't want
1999 * to read the arg as is.
2001 if (arg->op.left->type != PRINT_FIELD)
2002 goto default_op; /* oops, all bets off */
2003 larg = arg->op.left;
2004 if (!larg->field.field) {
2006 find_any_field(event, larg->field.name);
2007 if (!larg->field.field)
2008 die("field %s not found", larg->field.name);
2010 right = eval_num_arg(data, size, event, arg->op.right);
2011 val = read_size(data + larg->field.field->offset +
2012 right * long_size, long_size);
2016 left = eval_num_arg(data, size, event, arg->op.left);
2017 right = eval_num_arg(data, size, event, arg->op.right);
2018 switch (arg->op.op[0]) {
2021 val = left || right;
2027 val = left && right;
2032 switch (arg->op.op[1]) {
2037 val = left << right;
2040 val = left <= right;
2043 die("unknown op '%s'", arg->op.op);
2047 switch (arg->op.op[1]) {
2052 val = left >> right;
2055 val = left >= right;
2058 die("unknown op '%s'", arg->op.op);
2062 if (arg->op.op[1] != '=')
2063 die("unknown op '%s'", arg->op.op);
2064 val = left == right;
2067 die("unknown op '%s'", arg->op.op);
2070 default: /* not sure what to do there */
2078 unsigned long long value;
2081 static const struct flag flags[] = {
2082 { "HI_SOFTIRQ", 0 },
2083 { "TIMER_SOFTIRQ", 1 },
2084 { "NET_TX_SOFTIRQ", 2 },
2085 { "NET_RX_SOFTIRQ", 3 },
2086 { "BLOCK_SOFTIRQ", 4 },
2087 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
2088 { "TASKLET_SOFTIRQ", 6 },
2089 { "SCHED_SOFTIRQ", 7 },
2090 { "HRTIMER_SOFTIRQ", 8 },
2091 { "RCU_SOFTIRQ", 9 },
2093 { "HRTIMER_NORESTART", 0 },
2094 { "HRTIMER_RESTART", 1 },
2097 static unsigned long long eval_flag(const char *flag)
2102 * Some flags in the format files do not get converted.
2103 * If the flag is not numeric, see if it is something that
2104 * we already know about.
2106 if (isdigit(flag[0]))
2107 return strtoull(flag, NULL, 0);
2109 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
2110 if (strcmp(flags[i].name, flag) == 0)
2111 return flags[i].value;
2116 static void print_str_arg(void *data, int size,
2117 struct event *event, struct print_arg *arg)
2119 struct print_flag_sym *flag;
2120 unsigned long long val, fval;
2124 switch (arg->type) {
2129 printf("%s", arg->atom.atom);
2132 if (!arg->field.field) {
2133 arg->field.field = find_any_field(event, arg->field.name);
2134 if (!arg->field.field)
2135 die("field %s not found", arg->field.name);
2137 str = malloc_or_die(arg->field.field->size + 1);
2138 memcpy(str, data + arg->field.field->offset,
2139 arg->field.field->size);
2140 str[arg->field.field->size] = 0;
2145 val = eval_num_arg(data, size, event, arg->flags.field);
2147 for (flag = arg->flags.flags; flag; flag = flag->next) {
2148 fval = eval_flag(flag->value);
2149 if (!val && !fval) {
2150 printf("%s", flag->str);
2153 if (fval && (val & fval) == fval) {
2154 if (print && arg->flags.delim)
2155 printf("%s", arg->flags.delim);
2156 printf("%s", flag->str);
2163 val = eval_num_arg(data, size, event, arg->symbol.field);
2164 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
2165 fval = eval_flag(flag->value);
2167 printf("%s", flag->str);
2175 case PRINT_STRING: {
2178 if (arg->string.offset == -1) {
2179 struct format_field *f;
2181 f = find_any_field(event, arg->string.string);
2182 arg->string.offset = f->offset;
2184 str_offset = *(int *)(data + arg->string.offset);
2185 str_offset &= 0xffff;
2186 printf("%s", ((char *)data) + str_offset);
2191 * The only op for string should be ? :
2193 if (arg->op.op[0] != '?')
2195 val = eval_num_arg(data, size, event, arg->op.left);
2197 print_str_arg(data, size, event, arg->op.right->op.left);
2199 print_str_arg(data, size, event, arg->op.right->op.right);
2207 static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event *event)
2209 static struct format_field *field, *ip_field;
2210 struct print_arg *args, *arg, **next;
2211 unsigned long long ip, val;
2216 field = find_field(event, "buf");
2218 die("can't find buffer field for binary printk");
2219 ip_field = find_field(event, "ip");
2221 die("can't find ip field for binary printk");
2224 ip = read_size(data + ip_field->offset, ip_field->size);
2227 * The first arg is the IP pointer.
2229 args = malloc_or_die(sizeof(*args));
2234 arg->type = PRINT_ATOM;
2235 arg->atom.atom = malloc_or_die(32);
2236 sprintf(arg->atom.atom, "%lld", ip);
2238 /* skip the first "%pf : " */
2239 for (ptr = fmt + 6, bptr = data + field->offset;
2240 bptr < data + size && *ptr; ptr++) {
2264 bptr = (void *)(((unsigned long)bptr + (long_size - 1)) &
2276 val = read_size(bptr, ls);
2278 arg = malloc_or_die(sizeof(*arg));
2280 arg->type = PRINT_ATOM;
2281 arg->atom.atom = malloc_or_die(32);
2282 sprintf(arg->atom.atom, "%lld", val);
2287 arg = malloc_or_die(sizeof(*arg));
2289 arg->type = PRINT_STRING;
2290 arg->string.string = strdup(bptr);
2291 bptr += strlen(bptr) + 1;
2303 static void free_args(struct print_arg *args)
2305 struct print_arg *next;
2310 if (args->type == PRINT_ATOM)
2311 free(args->atom.atom);
2313 free(args->string.string);
2319 static char *get_bprint_format(void *data, int size __unused, struct event *event)
2321 unsigned long long addr;
2322 static struct format_field *field;
2323 struct printk_map *printk;
2328 field = find_field(event, "fmt");
2330 die("can't find format field for binary printk");
2331 printf("field->offset = %d size=%d\n", field->offset, field->size);
2334 addr = read_size(data + field->offset, field->size);
2336 printk = find_printk(addr);
2338 format = malloc_or_die(45);
2339 sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
2345 /* Remove any quotes. */
2348 format = malloc_or_die(strlen(p) + 10);
2349 sprintf(format, "%s : %s", "%pf", p);
2350 /* remove ending quotes and new line since we will add one too */
2351 p = format + strlen(format) - 1;
2356 if (strcmp(p, "\\n") == 0)
2362 static void pretty_print(void *data, int size, struct event *event)
2364 struct print_fmt *print_fmt = &event->print_fmt;
2365 struct print_arg *arg = print_fmt->args;
2366 struct print_arg *args = NULL;
2367 const char *ptr = print_fmt->format;
2368 unsigned long long val;
2369 struct func_map *func;
2370 const char *saveptr;
2371 char *bprint_fmt = NULL;
2377 if (event->flags & EVENT_FL_ISFUNC)
2378 ptr = " %pF <-- %pF";
2380 if (event->flags & EVENT_FL_ISBPRINT) {
2381 bprint_fmt = get_bprint_format(data, size, event);
2382 args = make_bprint_args(bprint_fmt, data, size, event);
2387 for (; *ptr; ptr++) {
2409 } else if (*ptr == '%') {
2434 if (*(ptr+1) == 'F' ||
2447 die("no argument match");
2449 len = ((unsigned long)ptr + 1) -
2450 (unsigned long)saveptr;
2452 /* should never happen */
2456 memcpy(format, saveptr, len);
2459 val = eval_num_arg(data, size, event, arg);
2463 func = find_func(val);
2465 printf("%s", func->func);
2466 if (show_func == 'F')
2474 printf(format, (int)val);
2477 printf(format, (long)val);
2480 printf(format, (long long)val);
2483 die("bad count (%d)", ls);
2488 die("no matching argument");
2490 print_str_arg(data, size, event, arg);
2494 printf(">%c<", *ptr);
2507 static inline int log10_cpu(int nb)
2516 /* taken from Linux, written by Frederic Weisbecker */
2517 static void print_graph_cpu(int cpu)
2520 int log10_this = log10_cpu(cpu);
2521 int log10_all = log10_cpu(cpus);
2525 * Start with a space character - to make it stand out
2526 * to the right a bit when trace output is pasted into
2532 * Tricky - we space the CPU field according to the max
2533 * number of online CPUs. On a 2-cpu system it would take
2534 * a maximum of 1 digit - on a 128 cpu system it would
2535 * take up to 3 digits:
2537 for (i = 0; i < log10_all - log10_this; i++)
2540 printf("%d) ", cpu);
2543 #define TRACE_GRAPH_PROCINFO_LENGTH 14
2544 #define TRACE_GRAPH_INDENT 2
2546 static void print_graph_proc(int pid, const char *comm)
2548 /* sign + log10(MAX_INT) + '\0' */
2554 sprintf(pid_str, "%d", pid);
2556 /* 1 stands for the "-" character */
2557 len = strlen(comm) + strlen(pid_str) + 1;
2559 if (len < TRACE_GRAPH_PROCINFO_LENGTH)
2560 spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
2562 /* First spaces to align center */
2563 for (i = 0; i < spaces / 2; i++)
2566 printf("%s-%s", comm, pid_str);
2568 /* Last spaces to align center */
2569 for (i = 0; i < spaces - (spaces / 2); i++)
2573 static struct record *
2574 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
2575 struct record *next)
2577 struct format_field *field;
2578 struct event *event;
2583 type = trace_parse_common_type(next->data);
2584 event = trace_find_event(type);
2588 if (!(event->flags & EVENT_FL_ISFUNCRET))
2591 pid = parse_common_pid(next->data);
2592 field = find_field(event, "func");
2594 die("function return does not have field func");
2596 val = read_size(next->data + field->offset, field->size);
2598 if (cur_pid != pid || cur_func != val)
2601 /* this is a leaf, now advance the iterator */
2602 return trace_read_data(cpu);
2605 /* Signal a overhead of time execution to the output */
2606 static void print_graph_overhead(unsigned long long duration)
2608 /* Non nested entry or return */
2609 if (duration == ~0ULL)
2610 return (void)printf(" ");
2612 /* Duration exceeded 100 msecs */
2613 if (duration > 100000ULL)
2614 return (void)printf("! ");
2616 /* Duration exceeded 10 msecs */
2617 if (duration > 10000ULL)
2618 return (void)printf("+ ");
2623 static void print_graph_duration(unsigned long long duration)
2625 unsigned long usecs = duration / 1000;
2626 unsigned long nsecs_rem = duration % 1000;
2627 /* log10(ULONG_MAX) + '\0' */
2633 sprintf(msecs_str, "%lu", usecs);
2636 len = printf("%lu", usecs);
2638 /* Print nsecs (we don't want to exceed 7 numbers) */
2640 snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
2641 len += printf(".%s", nsecs_str);
2646 /* Print remaining spaces to fit the row's width */
2647 for (i = len; i < 7; i++)
2654 print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec)
2656 unsigned long long rettime, calltime;
2657 unsigned long long duration, depth;
2658 unsigned long long val;
2659 struct format_field *field;
2660 struct func_map *func;
2661 struct event *ret_event;
2665 type = trace_parse_common_type(ret_rec->data);
2666 ret_event = trace_find_event(type);
2668 field = find_field(ret_event, "rettime");
2670 die("can't find rettime in return graph");
2671 rettime = read_size(ret_rec->data + field->offset, field->size);
2673 field = find_field(ret_event, "calltime");
2675 die("can't find rettime in return graph");
2676 calltime = read_size(ret_rec->data + field->offset, field->size);
2678 duration = rettime - calltime;
2681 print_graph_overhead(duration);
2684 print_graph_duration(duration);
2686 field = find_field(event, "depth");
2688 die("can't find depth in entry graph");
2689 depth = read_size(data + field->offset, field->size);
2692 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2695 field = find_field(event, "func");
2697 die("can't find func in entry graph");
2698 val = read_size(data + field->offset, field->size);
2699 func = find_func(val);
2702 printf("%s();", func->func);
2704 printf("%llx();", val);
2707 static void print_graph_nested(struct event *event, void *data)
2709 struct format_field *field;
2710 unsigned long long depth;
2711 unsigned long long val;
2712 struct func_map *func;
2716 print_graph_overhead(-1);
2721 field = find_field(event, "depth");
2723 die("can't find depth in entry graph");
2724 depth = read_size(data + field->offset, field->size);
2727 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2730 field = find_field(event, "func");
2732 die("can't find func in entry graph");
2733 val = read_size(data + field->offset, field->size);
2734 func = find_func(val);
2737 printf("%s() {", func->func);
2739 printf("%llx() {", val);
2743 pretty_print_func_ent(void *data, int size, struct event *event,
2744 int cpu, int pid, const char *comm,
2745 unsigned long secs, unsigned long usecs)
2747 struct format_field *field;
2752 printf("%5lu.%06lu | ", secs, usecs);
2754 print_graph_cpu(cpu);
2755 print_graph_proc(pid, comm);
2759 field = find_field(event, "func");
2761 die("function entry does not have func field");
2763 val = read_size(data + field->offset, field->size);
2766 * peek_data may unmap the data pointer. Copy it first.
2768 copy_data = malloc_or_die(size);
2769 memcpy(copy_data, data, size);
2772 rec = trace_peek_data(cpu);
2774 rec = get_return_for_leaf(cpu, pid, val, rec);
2776 print_graph_entry_leaf(event, data, rec);
2780 print_graph_nested(event, data);
2786 pretty_print_func_ret(void *data, int size __unused, struct event *event,
2787 int cpu, int pid, const char *comm,
2788 unsigned long secs, unsigned long usecs)
2790 unsigned long long rettime, calltime;
2791 unsigned long long duration, depth;
2792 struct format_field *field;
2795 printf("%5lu.%06lu | ", secs, usecs);
2797 print_graph_cpu(cpu);
2798 print_graph_proc(pid, comm);
2802 field = find_field(event, "rettime");
2804 die("can't find rettime in return graph");
2805 rettime = read_size(data + field->offset, field->size);
2807 field = find_field(event, "calltime");
2809 die("can't find calltime in return graph");
2810 calltime = read_size(data + field->offset, field->size);
2812 duration = rettime - calltime;
2815 print_graph_overhead(duration);
2818 print_graph_duration(duration);
2820 field = find_field(event, "depth");
2822 die("can't find depth in entry graph");
2823 depth = read_size(data + field->offset, field->size);
2826 for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++)
2833 pretty_print_func_graph(void *data, int size, struct event *event,
2834 int cpu, int pid, const char *comm,
2835 unsigned long secs, unsigned long usecs)
2837 if (event->flags & EVENT_FL_ISFUNCENT)
2838 pretty_print_func_ent(data, size, event,
2839 cpu, pid, comm, secs, usecs);
2840 else if (event->flags & EVENT_FL_ISFUNCRET)
2841 pretty_print_func_ret(data, size, event,
2842 cpu, pid, comm, secs, usecs);
2846 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
2849 struct event *event;
2851 unsigned long usecs;
2855 secs = nsecs / NSECS_PER_SEC;
2856 nsecs -= secs * NSECS_PER_SEC;
2857 usecs = nsecs / NSECS_PER_USEC;
2859 type = trace_parse_common_type(data);
2861 event = trace_find_event(type);
2863 printf("ug! no event found for type %d\n", type);
2867 pid = parse_common_pid(data);
2869 if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET))
2870 return pretty_print_func_graph(data, size, event, cpu,
2871 pid, comm, secs, usecs);
2873 printf("%16s-%-5d [%03d] %5lu.%09Lu: %s: ",
2875 secs, nsecs, event->name);
2877 pretty_print(data, size, event);
2881 static void print_fields(struct print_flag_sym *field)
2883 printf("{ %s, %s }", field->value, field->str);
2886 print_fields(field->next);
2890 static void print_args(struct print_arg *args)
2892 int print_paren = 1;
2894 switch (args->type) {
2899 printf("%s", args->atom.atom);
2902 printf("REC->%s", args->field.name);
2905 printf("__print_flags(");
2906 print_args(args->flags.field);
2907 printf(", %s, ", args->flags.delim);
2908 print_fields(args->flags.flags);
2912 printf("__print_symbolic(");
2913 print_args(args->symbol.field);
2915 print_fields(args->symbol.symbols);
2919 printf("__get_str(%s)", args->string.string);
2922 printf("(%s)", args->typecast.type);
2923 print_args(args->typecast.item);
2926 if (strcmp(args->op.op, ":") == 0)
2930 print_args(args->op.left);
2931 printf(" %s ", args->op.op);
2932 print_args(args->op.right);
2937 /* we should warn... */
2942 print_args(args->next);
2946 static void parse_header_field(char *type,
2947 int *offset, int *size)
2951 if (read_expected(EVENT_ITEM, (char *)"field") < 0)
2953 if (read_expected(EVENT_OP, (char *)":") < 0)
2956 if (read_expect_type(EVENT_ITEM, &token) < 0)
2960 if (read_expected(EVENT_ITEM, type) < 0)
2962 if (read_expected(EVENT_OP, (char *)";") < 0)
2964 if (read_expected(EVENT_ITEM, (char *)"offset") < 0)
2966 if (read_expected(EVENT_OP, (char *)":") < 0)
2968 if (read_expect_type(EVENT_ITEM, &token) < 0)
2970 *offset = atoi(token);
2972 if (read_expected(EVENT_OP, (char *)";") < 0)
2974 if (read_expected(EVENT_ITEM, (char *)"size") < 0)
2976 if (read_expected(EVENT_OP, (char *)":") < 0)
2978 if (read_expect_type(EVENT_ITEM, &token) < 0)
2980 *size = atoi(token);
2982 if (read_expected(EVENT_OP, (char *)";") < 0)
2984 if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
2986 if (read_expected(EVENT_OP, (char *)":") < 0)
2988 if (read_expect_type(EVENT_ITEM, &token) < 0)
2991 if (read_expected(EVENT_OP, (char *)";") < 0)
2993 if (read_expect_type(EVENT_NEWLINE, &token) < 0)
2998 int parse_header_page(char *buf, unsigned long size)
3000 init_input_buf(buf, size);
3002 parse_header_field((char *)"timestamp", &header_page_ts_offset,
3003 &header_page_ts_size);
3004 parse_header_field((char *)"commit", &header_page_size_offset,
3005 &header_page_size_size);
3006 parse_header_field((char *)"data", &header_page_data_offset,
3007 &header_page_data_size);
3012 int parse_ftrace_file(char *buf, unsigned long size)
3014 struct format_field *field;
3015 struct print_arg *arg, **list;
3016 struct event *event;
3019 init_input_buf(buf, size);
3021 event = alloc_event();
3025 event->flags |= EVENT_FL_ISFTRACE;
3027 event->name = event_read_name();
3029 die("failed to read ftrace event name");
3031 if (strcmp(event->name, "function") == 0)
3032 event->flags |= EVENT_FL_ISFUNC;
3034 else if (strcmp(event->name, "funcgraph_entry") == 0)
3035 event->flags |= EVENT_FL_ISFUNCENT;
3037 else if (strcmp(event->name, "funcgraph_exit") == 0)
3038 event->flags |= EVENT_FL_ISFUNCRET;
3040 else if (strcmp(event->name, "bprint") == 0)
3041 event->flags |= EVENT_FL_ISBPRINT;
3043 event->id = event_read_id();
3045 die("failed to read ftrace event id");
3049 ret = event_read_format(event);
3051 die("failed to read ftrace event format");
3053 ret = event_read_print(event);
3055 die("failed to read ftrace event print fmt");
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 die("failed to read event format");
3097 ret = event_read_print(event);
3099 die("failed to read event print fmt");
3101 event->system = strdup(sys);
3103 #define PRINT_ARGS 0
3104 if (PRINT_ARGS && event->print_fmt.args)
3105 print_args(event->print_fmt.args);
3111 void parse_set_info(int nr_cpus, int long_sz)
3114 long_size = long_sz;