Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com> |
| 3 | * |
| 4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5 | * |
| 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!) |
| 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | * |
| 19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 20 | */ |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 21 | #include <dirent.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <getopt.h> |
| 26 | #include <stdarg.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/wait.h> |
| 30 | #include <sys/mman.h> |
| 31 | #include <pthread.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <unistd.h> |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 34 | #include <errno.h> |
| 35 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 36 | #include "../perf.h" |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 37 | #include "util.h" |
| 38 | #include "trace-event.h" |
| 39 | |
| 40 | static int input_fd; |
| 41 | |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 42 | int file_bigendian; |
| 43 | int host_bigendian; |
| 44 | static int long_size; |
| 45 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 46 | static ssize_t calc_data_size; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 47 | static bool repipe; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 48 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 49 | static int __do_read(int fd, void *buf, int size) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 50 | { |
| 51 | int rsize = size; |
| 52 | |
| 53 | while (size) { |
| 54 | int ret = read(fd, buf, size); |
| 55 | |
| 56 | if (ret <= 0) |
| 57 | return -1; |
| 58 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 59 | if (repipe) { |
| 60 | int retw = write(STDOUT_FILENO, buf, ret); |
| 61 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 62 | if (retw <= 0 || retw != ret) { |
| 63 | pr_debug("repiping input file"); |
| 64 | return -1; |
| 65 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 68 | size -= ret; |
| 69 | buf += ret; |
| 70 | } |
| 71 | |
| 72 | return rsize; |
| 73 | } |
| 74 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 75 | static int do_read(void *data, int size) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 76 | { |
| 77 | int r; |
| 78 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 79 | r = __do_read(input_fd, data, size); |
| 80 | if (r <= 0) { |
| 81 | pr_debug("reading input file (size expected=%d received=%d)", |
| 82 | size, r); |
| 83 | return -1; |
| 84 | } |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 85 | |
| 86 | if (calc_data_size) |
| 87 | calc_data_size += r; |
| 88 | |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 89 | return r; |
| 90 | } |
| 91 | |
Tom Zanussi | cbb5cf7 | 2010-05-04 23:02:10 -0500 | [diff] [blame] | 92 | /* If it fails, the next read will report it */ |
| 93 | static void skip(int size) |
| 94 | { |
| 95 | char buf[BUFSIZ]; |
| 96 | int r; |
| 97 | |
| 98 | while (size) { |
| 99 | r = size > BUFSIZ ? BUFSIZ : size; |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 100 | do_read(buf, r); |
Tom Zanussi | cbb5cf7 | 2010-05-04 23:02:10 -0500 | [diff] [blame] | 101 | size -= r; |
| 102 | }; |
| 103 | } |
| 104 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 105 | static unsigned int read4(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 106 | { |
| 107 | unsigned int data; |
| 108 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 109 | if (do_read(&data, 4) < 0) |
| 110 | return 0; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 111 | return __data2host4(pevent, data); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 114 | static unsigned long long read8(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 115 | { |
| 116 | unsigned long long data; |
| 117 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 118 | if (do_read(&data, 8) < 0) |
| 119 | return 0; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 120 | return __data2host8(pevent, data); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static char *read_string(void) |
| 124 | { |
| 125 | char buf[BUFSIZ]; |
| 126 | char *str = NULL; |
| 127 | int size = 0; |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 128 | off_t r; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 129 | char c; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 130 | |
| 131 | for (;;) { |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 132 | r = read(input_fd, &c, 1); |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 133 | if (r < 0) { |
| 134 | pr_debug("reading input file"); |
| 135 | goto out; |
| 136 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 137 | |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 138 | if (!r) { |
| 139 | pr_debug("no data"); |
| 140 | goto out; |
| 141 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 142 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 143 | if (repipe) { |
| 144 | int retw = write(STDOUT_FILENO, &c, 1); |
| 145 | |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 146 | if (retw <= 0 || retw != r) { |
| 147 | pr_debug("repiping input file string"); |
| 148 | goto out; |
| 149 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 152 | buf[size++] = c; |
| 153 | |
| 154 | if (!c) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 155 | break; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 158 | if (calc_data_size) |
| 159 | calc_data_size += size; |
Ingo Molnar | 6f4596d | 2009-09-03 16:22:45 +0200 | [diff] [blame] | 160 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 161 | str = malloc(size); |
| 162 | if (str) |
| 163 | memcpy(str, buf, size); |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 164 | out: |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 165 | return str; |
| 166 | } |
| 167 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 168 | static int read_proc_kallsyms(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 169 | { |
| 170 | unsigned int size; |
| 171 | char *buf; |
| 172 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 173 | size = read4(pevent); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 174 | if (!size) |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 175 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 176 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 177 | buf = malloc(size + 1); |
| 178 | if (buf == NULL) |
| 179 | return -1; |
| 180 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 181 | if (do_read(buf, size) < 0) { |
| 182 | free(buf); |
| 183 | return -1; |
| 184 | } |
OGAWA Hirofumi | 7691b1e | 2009-12-06 20:10:49 +0900 | [diff] [blame] | 185 | buf[size] = '\0'; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 186 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 187 | parse_proc_kallsyms(pevent, buf, size); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 188 | |
| 189 | free(buf); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 190 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 193 | static int read_ftrace_printk(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 194 | { |
| 195 | unsigned int size; |
| 196 | char *buf; |
| 197 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 198 | /* it can have 0 size */ |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 199 | size = read4(pevent); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 200 | if (!size) |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 201 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 202 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 203 | buf = malloc(size); |
| 204 | if (buf == NULL) |
| 205 | return -1; |
| 206 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 207 | if (do_read(buf, size) < 0) { |
| 208 | free(buf); |
| 209 | return -1; |
| 210 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 211 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 212 | parse_ftrace_printk(pevent, buf, size); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 213 | |
| 214 | free(buf); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 215 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 218 | static int read_header_files(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 219 | { |
| 220 | unsigned long long size; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 221 | char *header_event; |
| 222 | char buf[BUFSIZ]; |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 223 | int ret = 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 224 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 225 | if (do_read(buf, 12) < 0) |
| 226 | return -1; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 227 | |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 228 | if (memcmp(buf, "header_page", 12) != 0) { |
| 229 | pr_debug("did not read header page"); |
| 230 | return -1; |
| 231 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 232 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 233 | size = read8(pevent); |
Frederic Weisbecker | d00a47c | 2010-05-01 03:08:46 +0200 | [diff] [blame] | 234 | skip(size); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * The size field in the page is of type long, |
| 238 | * use that instead, since it represents the kernel. |
| 239 | */ |
| 240 | long_size = header_page_size_size; |
| 241 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 242 | if (do_read(buf, 13) < 0) |
| 243 | return -1; |
| 244 | |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 245 | if (memcmp(buf, "header_event", 13) != 0) { |
| 246 | pr_debug("did not read header event"); |
| 247 | return -1; |
| 248 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 249 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 250 | size = read8(pevent); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 251 | header_event = malloc(size); |
| 252 | if (header_event == NULL) |
| 253 | return -1; |
| 254 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 255 | if (do_read(header_event, size) < 0) |
| 256 | ret = -1; |
| 257 | |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 258 | free(header_event); |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 259 | return ret; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 260 | } |
| 261 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 262 | static int read_ftrace_file(struct pevent *pevent, unsigned long long size) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 263 | { |
| 264 | char *buf; |
| 265 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 266 | buf = malloc(size); |
| 267 | if (buf == NULL) |
| 268 | return -1; |
| 269 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 270 | if (do_read(buf, size) < 0) { |
| 271 | free(buf); |
| 272 | return -1; |
| 273 | } |
| 274 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 275 | parse_ftrace_file(pevent, buf, size); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 276 | free(buf); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 277 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 280 | static int read_event_file(struct pevent *pevent, char *sys, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 281 | unsigned long long size) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 282 | { |
| 283 | char *buf; |
| 284 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 285 | buf = malloc(size); |
| 286 | if (buf == NULL) |
| 287 | return -1; |
| 288 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 289 | if (do_read(buf, size) < 0) { |
| 290 | free(buf); |
| 291 | return -1; |
| 292 | } |
| 293 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 294 | parse_event_file(pevent, buf, size, sys); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 295 | free(buf); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 296 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 299 | static int read_ftrace_files(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 300 | { |
| 301 | unsigned long long size; |
| 302 | int count; |
| 303 | int i; |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 304 | int ret; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 305 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 306 | count = read4(pevent); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 307 | |
| 308 | for (i = 0; i < count; i++) { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 309 | size = read8(pevent); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 310 | ret = read_ftrace_file(pevent, size); |
| 311 | if (ret) |
| 312 | return ret; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 313 | } |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 314 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 317 | static int read_event_files(struct pevent *pevent) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 318 | { |
| 319 | unsigned long long size; |
| 320 | char *sys; |
| 321 | int systems; |
| 322 | int count; |
| 323 | int i,x; |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 324 | int ret; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 325 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 326 | systems = read4(pevent); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 327 | |
| 328 | for (i = 0; i < systems; i++) { |
| 329 | sys = read_string(); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 330 | if (sys == NULL) |
| 331 | return -1; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 332 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 333 | count = read4(pevent); |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 334 | |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 335 | for (x=0; x < count; x++) { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 336 | size = read8(pevent); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 337 | ret = read_event_file(pevent, sys, size); |
| 338 | if (ret) |
| 339 | return ret; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 340 | } |
| 341 | } |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 342 | return 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 345 | ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 346 | { |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 347 | char buf[BUFSIZ]; |
| 348 | char test[] = { 23, 8, 68 }; |
| 349 | char *version; |
Ingo Molnar | d9340c1 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 350 | int show_version = 0; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 351 | int show_funcs = 0; |
| 352 | int show_printk = 0; |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 353 | ssize_t size = -1; |
| 354 | struct pevent *pevent; |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 355 | int err; |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 356 | |
| 357 | *ppevent = NULL; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 358 | |
| 359 | calc_data_size = 1; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 360 | repipe = __repipe; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 361 | |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 362 | input_fd = fd; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 363 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 364 | if (do_read(buf, 3) < 0) |
| 365 | return -1; |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 366 | if (memcmp(buf, test, 3) != 0) { |
| 367 | pr_debug("no trace data in the file"); |
| 368 | return -1; |
| 369 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 370 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 371 | if (do_read(buf, 7) < 0) |
| 372 | return -1; |
Namhyung Kim | 452958f | 2013-03-21 16:18:51 +0900 | [diff] [blame^] | 373 | if (memcmp(buf, "tracing", 7) != 0) { |
| 374 | pr_debug("not a trace file (missing 'tracing' tag)"); |
| 375 | return -1; |
| 376 | } |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 377 | |
| 378 | version = read_string(); |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 379 | if (version == NULL) |
| 380 | return -1; |
Ingo Molnar | d9340c1 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 381 | if (show_version) |
| 382 | printf("version = %s\n", version); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 383 | free(version); |
| 384 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 385 | if (do_read(buf, 1) < 0) |
| 386 | return -1; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 387 | file_bigendian = buf[0]; |
| 388 | host_bigendian = bigendian(); |
| 389 | |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 390 | pevent = read_trace_init(file_bigendian, host_bigendian); |
| 391 | if (pevent == NULL) { |
| 392 | pr_debug("read_trace_init failed"); |
| 393 | goto out; |
| 394 | } |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 395 | |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 396 | if (do_read(buf, 1) < 0) |
| 397 | goto out; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 398 | long_size = buf[0]; |
| 399 | |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 400 | page_size = read4(pevent); |
Namhyung Kim | 4a31e56 | 2013-03-21 16:18:50 +0900 | [diff] [blame] | 401 | if (!page_size) |
| 402 | goto out; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 403 | |
Namhyung Kim | a4c9836 | 2013-03-21 16:18:49 +0900 | [diff] [blame] | 404 | err = read_header_files(pevent); |
| 405 | if (err) |
| 406 | goto out; |
| 407 | err = read_ftrace_files(pevent); |
| 408 | if (err) |
| 409 | goto out; |
| 410 | err = read_event_files(pevent); |
| 411 | if (err) |
| 412 | goto out; |
| 413 | err = read_proc_kallsyms(pevent); |
| 414 | if (err) |
| 415 | goto out; |
| 416 | err = read_ftrace_printk(pevent); |
| 417 | if (err) |
| 418 | goto out; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 419 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 420 | size = calc_data_size - 1; |
| 421 | calc_data_size = 0; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 422 | repipe = false; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 423 | |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 424 | if (show_funcs) { |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 425 | pevent_print_funcs(pevent); |
| 426 | } else if (show_printk) { |
| 427 | pevent_print_printk(pevent); |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 430 | *ppevent = pevent; |
| 431 | pevent = NULL; |
| 432 | |
| 433 | out: |
| 434 | if (pevent) |
| 435 | pevent_free(pevent); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 436 | return size; |
Steven Rostedt | 538bafb | 2009-08-17 16:18:06 +0200 | [diff] [blame] | 437 | } |